Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

AutoText Add-in for Visual Studio 6.0

0.00/5 (No votes)
3 Mar 2001 1  
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 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