Click here to Skip to main content
15,867,141 members
Articles / Programming Languages / C++
Article

AutoText Add-in for Visual Studio 6.0

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
3 Mar 2001 115.5K   1.5K   39   19
Adds the auto text feature from MS Word (tm) to the Developer Studio (tm)

Sample Image - DeveloperStudioAutoText.gif

Introduction

I have been using this tool for about a year now for my personal use and it works quite fine. After reading some articles here on CodeProject I felt like I needed to give back something useful to the community. So here it is...

This add-in adds an AutoText feature to Visual Studio similar to the one found in MS Word (tm). It replaces misspellings or can replace abbreviated words while typing with their full text. This can be used to abbreviate hard to type names; for example, UNUSED_ALWAYS (which I abbreviated to ua ). Or to correct common spelling errors; for example, typing TURE and having it replaced with TRUE.

Current version: Version 1,0,0.1 (February 21, 2001)
I'll post updates here when available.


Installation

Either download the DeveloperStudioAutoText_src.zip file and build it for yourself or just download the ready to use build DeveloperStudioAutoText_addin.zip then copy the file DeveloperStudioAutoText.dll to c:\Program Files\microsoft visual studio\common\msdev98\addins or where ever you have installed your copy of visual studio respectively.
  1. Copy DeveloperStudioAutoText.dll to any place you want. A good place would be under the Microsoft Visual Studio folder at Common\MDev98\AddIns.
  2. Open Visual Studio and select: Tools | Customize...
  3. Go to the Add-ins and Macro files tab and click on the Browse button.
  4. Go to the folder to which you copied DeveloperStudioAutoText.dll and select it. Make sure the "files of type" listbox is set to "Add-ins (.dll)".
  5. When closing the dialog, a toolbar will appear with the AutoText-Configuration button (Large 'T' with small "Auto" below it" and a button labeled "H/C+" which toggles between C(++) and the .H-file.
    Like with any other toolbar button you can move this button to any other toolbar.
  6. Press the left button (with the 'T' on it) to setup the AutoText replacement table. Here you can enable/disable the plug-in trough switching on/off the Enable AutoText checkbox.
  7. Type in the Replace edit box the text to be replaced and in the With edit box the text to replace it with. Then press <return> or click on Add New to add it.
  8. With the Delete button you can remove unwanted entries and when the replace text already exists, the Add New button changes to Replace to let you modify existing entries.
  9. When you press the OK button all settings are written to the file %windir%\DSAutoText.CFG which is in fact a standard .INI-file. You may edit it by hand (it's syntax is quite straightforward: In the section [Substitutions] there is a mapping between the original text on the left and the text to replace it with on the right side of the equal sign.
    You should not modify WordListState. This one contains the list view settings (column width and ordering)
  10. While typing the add-in watches for space and opening brackets. When you enter any of these it will search its replacement list and when it finds a suitable one, replaces your typed word with it.
  11. When the replaced text is not what you wanted, just delete it using edit/undo or pressing the backspace key and retype the original text, the next time you enter one of the stopping chars (space or bracket) it will ask if it should replace it and you can cancel replacing by pressing ESC or selecting DON'T REPLACE.
    Replace with question menu


How it works

On loading it tries to identify the main window and the MDIClientArea window (method CDSAddIn::OnConnection). The interesting part follows:
//First find the main window
hWnd = ::GetActiveWindow();
while( hWnd  &&  hWnd != hDesktopWnd )
{
    m_hDevStudioWnd = hWnd;
    hWnd = ::GetParent(hWnd);
}

GetWindowText( m_hDevStudioWnd, szWindowTitle, 512 );

if( strstr( szWindowTitle, "Microsoft Visual C++" ) )
{
   m_wndDevStudioMainWindow.SubclassWindow( m_hDevStudioWnd );

   // The MDIArea always has ID 0xe900
   m_hDevStudioMDIArea = GetDlgItem( m_hDevStudioWnd, 0xe900 );

   m_wndMDIAreaManager.SubclassWindow( m_hDevStudioMDIArea );
}
The line m_wndDevStudioMainWindow.SubclassWindow( m_hDevStudioWnd ); subclasses the DevStudio main window (class C_DevStudioMainWindowFilter. This is necessary because it would otherwise translate some of the cursor movements to WM_COMMAND messages. But as we need the cursor messages we intercept them.

There is another class C_DevStudioMainWindowFilter that is mainly used to easily get the active MDI (a.k.a. text editor) window and to handle the menu and normal keys.

The decision process, if anything needs to be replaced can be found in C_ActiveMDIWindowFilter::OnSpecialKeyPressed(). Of interest, may be the handling of m_bEnableAutoCorrect, which determines if the entered text is automatically replaced or if the user is asked if it should be replaced (after the user pressed delete it will be set to FALSE and back to TRUE when a stop char is pressed).

The actual replacing occurs in CheckAutoText(). If bAutoReplace is TRUE the text will immediately be replaced if possible. Otherwise only the replacement text (if available) will be returned. If there is nothing typed by the user that can be replaced then the return value will be empty and the text will not be changed.

Known Problems

MsDev6 on some systems has a problem to paste text to the editor (Edit/Paste) when copied from the same text window when using macros/add-ins.
As far as I know it's possible to fix this by disabling the new heap manager by adding the following registry key (at least it works on my colleges systems):
Add this key with regedit:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\MSDEV.EXE
then add a string value beneath it named DisableHeapLookaside and set it to "1".

This add-in was built with Visual C++ 6.0 with service pack 4. I have tested it also with service pack 3 and it worked fine there too, so I guess it won't make problems with different service packs.

See Q231652 and Q195009 in the knowledge base for more information.

Version History

Version 1,0,0.1
First public release.

Credits

The initial idea of subclassing the main window (but not the technique) was also taken from an addin found on code guru. But after over one year I forgot who it was. Sorry about that.

Some of the copyright notices was taken from Yuri Tkachov's enhanced windowlist submission. I hope he does not mind.

Further I have to thank my company (MicroMotion GmbH) for letting me use their equipment (and some time on working hours) to write this addin. (btw. this addin does not fulfill internal coding standards - it's a hobby project)

About Christoph Weber

Christoph Weber is a member of the core development team at MicroMotion GmbH.
He's programming Assembler/C/C++ (and some more) for 18 years now and Visual C++/MFC and ATL for 6 years.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionWhat about VC5 ? Pin
28-Jan-02 13:48
suss28-Jan-02 13:48 
AnswerRe: What about VC5 ? Pin
Christoph Weber29-Jan-02 10:32
Christoph Weber29-Jan-02 10:32 
GeneralRe: What about VC5 ? Pin
29-Jan-02 14:04
suss29-Jan-02 14:04 
GeneralCrash... Pin
| mProject |20-Dec-01 21:51
| mProject |20-Dec-01 21:51 
GeneralRe: Crash... Pin
Christoph Weber22-Dec-01 3:31
Christoph Weber22-Dec-01 3:31 
GeneralRe: Crash... Pin
5-Feb-02 19:38
suss5-Feb-02 19:38 
GeneralProblems with paste Pin
6-Mar-01 18:20
suss6-Mar-01 18:20 
GeneralRe: Problems with paste Pin
Simon Hughes6-Mar-01 22:58
Simon Hughes6-Mar-01 22:58 
GeneralRe: Problems with paste Pin
Christoph Weber7-Mar-01 1:20
Christoph Weber7-Mar-01 1:20 
GeneralRe: Problems with paste Pin
Joshua Jensen7-Mar-01 9:37
Joshua Jensen7-Mar-01 9:37 
GeneralRe: Problems with paste Pin
14-Mar-01 12:07
suss14-Mar-01 12:07 
GeneralFunctioning with other add-ins Pin
Ray Hayes6-Mar-01 0:00
Ray Hayes6-Mar-01 0:00 
GeneralRe: Functioning with other add-ins Pin
Simon Capewell6-Mar-01 3:27
Simon Capewell6-Mar-01 3:27 
GeneralRe: Functioning with other add-ins Pin
Christoph Weber6-Mar-01 10:03
Christoph Weber6-Mar-01 10:03 
GeneralRe: Functioning with other add-ins Pin
Simon Capewell6-Mar-01 23:18
Simon Capewell6-Mar-01 23:18 
GeneralRe: Functioning with other add-ins Pin
Christoph Weber7-Mar-01 3:42
Christoph Weber7-Mar-01 3:42 
GeneralRe: Functioning with other add-ins Pin
Joshua Jensen7-Mar-01 9:40
Joshua Jensen7-Mar-01 9:40 
GeneralRe: Functioning with other add-ins Pin
Christoph Weber7-Mar-01 23:40
Christoph Weber7-Mar-01 23:40 
GeneralRe: Functioning with other add-ins Pin
Oz Solomon8-Mar-01 5:21
Oz Solomon8-Mar-01 5:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.