Visual C ++ 6 Add-in Programming Example

xiaoxiao2021-03-20  220

Author:

Hao.yu

Download this article sample code

I have used some time to learn how to write add-in for Visual C 6.0. This is an interesting question, but in general, the documentation and sample programs related to this area are still relatively lacking (Chinese more rare). So I decided to write some of my own learning process and shared with everyone.

1. Frequently Asked Questions about Visual C Add-IN

(1) What is Visual C add-in? What is it used?

In general, Visual C add -in is a component object that implements certain COM interfaces, which can embed the developer Studio integration development environment and provide some commands to implement automated tasks, or simplify the program writing process, etc.

From a programmer's point of view, a Visual C Add-in is basically a COM object that implements the IDSADDIN interface. With this interface, Add-in can take a developer Studio environment and perform specific tasks.

(2) How to write add-in?

The easiest way is to start Visual C AppWizard and select DevStudio Add-in Wizard from the project type, as shown below.

(3) Where to find programming information and documentation about add-in?

The most complete document in MSDN, location is MSDN Library / Visual Studio Documentation / Use Visual C / Visual C User ''s Guide / Automating Tasks In Visual C / Add-Ins for Visual C Developer Studio. Different versions of MSDN may have some small differences on the specific path.

(4) How to use Add-in?

If you have a useful add-in, or write one yourself, install it according to the following steps:

Select Tools | Customize from the main menu of Visual C , then turn it to the Add-INS AND MACRO Files page:

If your add-in does not appear in the list, press the Browse button to find the add-in file (note that the default file type (* .dsm) is changed to (* .dll)):

Say, add-in will appear in the Add-Ins and Macros list. Verify that the check box on the left of Add-in is selected, and then press Close.

Back to the integrated environment, usually add-in will add a new toolbar in the environment, listing this add-in available commands. Now you can work with these command buttons.

(5) What is the advantages and disadvantages of add-in?

Add-in is integrated with the development environment, which means that we can use Add-in to complete the work without leaving IDE, without having to use external tools, which is a great advantage of add-in. Therefore, Add-in is usually used to simplify some repetitive work and improve programmers' work efficiency. For example, an ADD-I called AutobuildNumber can automatically add version number to 1 when compiling the project; another famous Add-in (some people in the reader are already using it) A page similar to Ultra-Edit is available to allow programmers to switch in open files. Add-in also has its shortcomings, which is manifested in several ways. First, if your purpose is to simplify the work of repetitiveness, it is not necessarily to write add-in: You can first consider writing a macro script. Scripts and add-in have the ability to access the full developer studio Object Model, and its writing and maintenance is simpler, so it is also a good choice. However, the script cannot achieve a relatively advanced feature, such as calling Win32 API, etc. At this time, you should consider add-in.

Another disadvantage of add-in is that it is limited to the interface provided by the development environment. Microsoft provides a set of interfaces for add-in, you need to use these interface properties and methods to complete the actual tasks, if some features are not available, then you are also difficult to implement them in Add-in. To learn what add-in can do and what can't do, the best way is to familiarize yourself with the developer studio object model, please refer to MSDN for this purpose. In addition, add-in cannot be (or difficult) to implement advanced UI features, such as the user interface that add-in can implement only the modal dialog; if you want to build a window and contact IDE, almost It is impossible. ADD-I like WndTabs achieves some special skills to break through this restriction, but it uses less use of some Hacker means, which is not supported by the official, that is to say, as long as Microsoft makes it a little to Visual C . Change, it may be completely invalid; it is also very difficult to figure out these skills, so it is generally recommended.

Second, the example of this article

Now transfer to a topic, introduce a specific example I am based on Add-in documentation. This example achieves four useful methods, I will introduce one by one.

(1) Show Object Model

This method is the product of the learning document, because when I read MSDN, I always want to know what the object model provided by the Add-IN specification should look like. So this method, when you select this command, it will call up a dialog where all objects in the model are listed in the hierarchy, and their respective properties.

From the figure, you can see that the top layer of the model is an Application object, its name is Microsoft Developer Studio, version is 6.0, and other properties can also be visually visible from the figure. For these specific objects and the relationship between them, please refer to MSDN.

I found this method very useful when I actually write Add-in, because it can tell me in an intuitive: what objects currently have, and those attributes of the objects are available. This saves a lot of time to repeatedly switch between Visual C and MSDN.

(2) Switch Between .h and .cpp

Friends who have used Borland C Builder should be familiar with this method. For example, today's Test.cpp, you can use this command to see the corresponding test.h, and vice versa. Visual C does not implement a similar function, so I wrote a method to simulate C Builder. (3) Open RC AS TEXT

Sometimes we need to open the project's resource files to be edited on some text, in some cases, this is more convenient and fast than using Resource Editor, or avoids the limitations of the integrated environment. However, there is no simple method in Visual C to do this, so I have to close all resource windows every time, browse to the RC file with the open command, select the open mode for text, after several steps can be done, why not What is automated? The Open rc as text command is to implement this feature.

(4) Include Browser

This command can quickly open the header file listed in the Visual C Include environment variable to avoid the trouble of manually find. It has a very intimate feature that when the files listed too much, enter several characters of the file you want to see, the list automatically filter out the qualified file, no need to flip before and after the long list. For example, I want to see the header file definition related to the Windows socket, just select this command and enter "Winsock", so the list will be listed in the list, select the file and press "Open" to open it, as shown below Indicated.

There is no special place for program code, so I don't intend to explain them, if you don't understand, refer to the source code. Even so, the code still provides some interesting things, such as simplifying the template functions of the query interface properties and methods, the use of CCOMDISPATCHDRIVER objects, embedding the toolbar, custom painting, registry query function in the dialog box, custom painting Wait, many of them are reusable or can be used. Please check the relevant code for details.

Third, regarding the instructions and conclusions of the program

Because this program is currently only a draft, if you are interested in add-in programming, then it provides a good starting point; even if you don't want to write it, the few features listed above may also be able to program your daily programming. The task is helpful. Add-in programming is an interesting area where you can share your own integrated development environment with your own integrated development environment, and in Visual Studio.NET 2002 and Visual Studio.Net 2003, this model is constantly changing and enhanced. . The examples of this article are completed in Visual C 6.0, but there is still a reference value in subsequent versions. If you want to learn more about add-in, please refer to MSDN Online, CodeGuru, and CodeProject and other famous Visual C programming sites, I believe you must improve your ability to write Add-in.

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

New Post(0)