BookNote: Uses Automation to Make Persistent Bookmarks and Add Notes About Code

Click to open or copy the BookNote project files.

BookNote lets you record notes (like permanent bookmarks), associating them with code. The sample also shows using the registry to persist a number of items in an MRU list. BookNote was created with the ATL COM AppWizard. Support MFC was checked in the wizard, and then an Add-in object was added to the project with the ATL Object Wizard. Most of the code added is in MarkIt.cpp.

If you modify the sample, precede each function that could be called from an external interface with the following code:

AFX_MANAGE_STATE(AfxGetStaticModuleState());

This allows you to access your resources and is necessary because of the MFC support.

The CMRUStrings class is used to do the persistence for a drop-down combo box. You can use this class and other classes from the add-ins in other projects. See Reusing Code Topics and Adding Classes to the Gallery for information on how to reuse code.

To build the sample

  1. Click the link at the beginning of this topic to download the sample files.

  2. In Visual C++, open the project file BookNote.dsp.

  3. Choose an appropriate configuration (Win32 Release is best if you plan to use this add-in).

  4. Click Rebuild All from the Build menu.

To run the add-in

  1. From the Tools menu, click Customize.

  2. Select the BookNote.dll file or browse for it. See Tips for Using Add-ins.

  3. Visual C++ will load the add-in. When you close the Customize dialog box, BookNote’s toolbar will appear.

  4. Run the BookNote add-in by clicking the toolbar button. Once the add-in has been loaded, it will open a dialog box. It will record the current selection (file, line, end of selection if applicable). You can type a note into the main edit box. When you click OK, the current selection will be copied into a file, which you can specify in this dialog box via a combo box that holds up to 10 file names. You can also immediately dump the current note to the output window. You can then use this with the F4 key. F4 will navigate to the line of code.

There is a check box for indenting notes that is on by default. If you copy text out of the output window and want to navigate to it, turn indenting off.

There is a button that dumps the file to the output window. The button does not close the dialog box. This is useful for putting any file into the output window; clicking Cancel stops recording a note.

Sample output

C:\VC98\VC98\CRT\SRC\DBGHEAP.C(328) : (09:16:04 PM  02/09/1998) 
328: set _crtDbgFlag and _crtBreakAlloc to find memory leaks

Before dumping files into the output window, you may want to clear the output window first. Use the context menu (right-click and choose Clear).

This sample demonstrates the following keywords:

CTimeSpan; CTime::GetCurrentTime; CTime::Format; CRegKey::QueryValue; CRegKey::Create; CRegKey::SetValue, ITextSelection, IApplication, CRegKey; ITextSelection::get_TopLine; CComPtr, CComQIPtr, ITextDocument::get_FullName; CComBSTR, IApplication::PrintToOutputWindow; addin; customize.