ATL actual combat series "with ATL COM WIZARD (VC ++ plug-in) Add-in"

zhaozj2021-02-08  261

To achieve add-in object, there are three ways, one is to implement the ATL object add -in object in the ATL COM Wizard, the other is to achieve the use of devstudio add-in wizard, the third is handwritten all the code If handwritten, be sure to remember to implement the IDSADDIN interface, so that the new command and tools can be added to the VC's IDE environment.

I mainly explain ATL COM Wizard, so I use the first way. Here I implements the IapplicationEvents and IDSADDIN interfaces, and the IapplicationEvents interface should be operated for the Application object, such as newDocument (), WorkspaceOpen (). To implement the IDSADDIN interface, you should go to the IDE environment to be added to the VC to add new commands and tools.

Sample program implementation:

1) Add a toolbar (4 buttons) in the IDE environment of the VC, and can manipulate the IDE environment of the VC, (toolbar as follows) The first button pop-up dialog allows you to modify user information, the second button minimizes All open windows, the third maximizes all windows, the fourth button pops up a MessagBox.

2) For each new document, copyright information and related content comments are automatically added in the file header according to the document type.

Source code http://263.9cbs.net/filebbs/files/2001_8/t_436_1.zip

Watching Effect: Download source code, generate Sample_02.dll after compile, then in the VC environment, select the menu Tools / Customize, then select the last add-INS AND MACRO Files tab, select the Browse button, select Sample_02 that just compiled. DLL file, then select the Copyright Class in the Add-Ins and Macro list box, then the Close Customize dialog, this is a toolbar with four buttons (see image above). You can click on these buttons to see the effect, or you can see if the file header plus copyright information in a VC environment (newly built) new type file (.cpp, .h .htm and .txt file). .

Let's take a step by step to implement this example:

1) Create a DLL project file called Sample_02 with ATL COM WIZARD

2) Right-click in Class Wizard, select New ATL Object ...

3) Categroy in the ATL COM Wizard dialog box Select Object to select Add-In Object in Object, select the Next button (as shown).

4) Select the NAMES tab of the Properties dialog, enter Copyright in the Short Name edit box of the C group (Figure)

5) Select the DevStudio Add-IN tab, select Application Events in Add-in Features, select the OK button to determine

The above steps generate basic add-in frame code

6) Create an IDE toolbar

a) Create two Bitmap files as toolbar image resources

IDB_TOOLBAR_LARGE_COPYRIGHT 32 x 32 Size

IDB_TOOLBAR_MEDIUM_COPYRIGHT 16 x 16

b) Add the code for the Creating the Toolbar button in the onConnection () function of the ccopyright class. For details, please refer to the source code. This code mainly uses two methods for Application Object () and addcommandbarButton () () (), addcommand () method call After that, there will be a corresponding command command in the Categroy list box in the commands tab in the menu Tools / Customize. (),

If I add such a command addcommand (ccombstr ("showinfodl / n display / n modified user copyright information / n display")), ccombstr (_T ("showinfodlg")), 0, dwaddinid, & bret); in Categroy SHOWINFODLG will be found in All Commands. The addcommandbarbutton () method is to add a toolbar button to the IDE integration environment. You can disconnect it to the toolbar manually in the program. Open Menu Tools / Customize Use the mouse to pull the command you need to go to the toolbar (as shown)

The code in the ccopyright class newDocument () method is mainly increasing the necessary copyright information to the document, which is mainly to explain how to operate the document in the VC environment. Everyone gets the specific Windows to modify the shape and attribute of the window. How to modify It is necessary to see their respective imagination.

Increase the method of the command:

1) If you want to add a command, you must increase the corresponding method in ICOPYRIGHT. If I add this command in the sample program, I must also increase the MINIWINDOW in ICopyRight (Right-click ICOPYRIGHT in ClassWizard, select Add method in the pop-up menu to increase the method)

The sample program program adds four commands: showinfodlg, miniWindow, maxwindow, and test, this must be implemented in the iCopyRight interface.

7) After realizing the toolbar, it is to achieve a specific method, please refer to the four methods in ccopyright.

STDMETHODIMP CCOPYRIGHT :: ShowinFodlg ()

StdMethodimp ccopyright :: MaxWindow ()

Stdmethodimp ccopyright :: miniwindow ()

STDMETHODIMP CCOPYRIGHT :: Test ()

The description of the value is a dialog box in the showinfodl () method. It is easy to implement in the ATL like this dialog. Right-click in Class Wizard, select Miscellaneous in category in ATL Object Wizard, select Miscellaneous in the Object, Select Dialog, next button, in the ATL Object Wizard Properties dialog box in the Short Name Editing box Enter UserInfodlg to complete the implementation of the dialog. In addition, the user information entered in the dialog is described in the registry. The interface pops up in the SHOWInFodlg () method is shown below:

At this point, the sample code is basically completed, and because many people are familiar with ATL development, this principle and some details will not be explained. Because of the completion of the rush, the wrong place, please forgive me.

Additional: How to call the sample program, compile operation, select the common / msdev98 / bin / msdev.exe under the installation path of the pop-up, then use the debugger, then select the menu under the debug-launched VC environment. Tools / Customize In the case of the specific operation, see the front viewing effect. Next time, you are ready to introduce Simple Object in ATL COM Wizard to make a simple distributed C / S app, and how to return data from the server.

转载请注明原文地址:https://www.9cbs.com/read-1864.html

New Post(0)