Jian MFC expansion DLL in Visual C ++

zhaozj2021-02-11  282

In Visual C , the MFC expansion DLL has written a sample of the class and encapsulates it in the DLL to show you the process. Experienced Windows programming people have discarded Windows SDK, while the turn can provide high-level abrasive development environments for low-level mechanisms that are built in Windows. One of this transfer is a beneficiary of Visual C , which rely on the MFC library to provide views of the opposite objects of the Windows API. The MFC is a powerful tool that is experienced with rich programming, but it is far from the perfect. In fact, all the people I have recognized as the MFC program have issued him or her own extension combination, and they are classified as the basic class as the basic class. This is the power of C . If a class cannot meet your needs (and if it is just as the beginning of the design), you can send new classes from it to the new class and modify the part of you don't like. It is assumed that you have written an MFC expansion collection and willing to interact with the company's developers. What should you enclose these extensions? You can distribute source code files or components that are compatible with the Visual C component library (Component Gallery). Or you can seal your expansion in DLL in DLL like MFC. As the DLL of the like can deviate the function, the MFC expansion DLL can be derived. Any moving chain is connected to the MFC DLL to connect to the MFC expansion DLL. As a developer, you only need to include the necessary header files and add DLL Guidelines in the link-to-order chain list. Is it difficult to write MFC expansion DLL? With Visual C and MFC, this is actually light loose. This article explains how to create a MFC expansion DLL to make MFC's CTooltiPCtrl classes. Once you know that it is simple, you will not help but write a few MFC expansion. Writing the MFC Extension DLL From the perspective of the agency, the CTool-TipCtrl class of the MFC simplifies the process that will be associated with the Tooltip to associate the control or window of the dialog box or window. (Reference Information is a small help text window that is playing in the mouse light stagnation of the toolbar button or its UI to the UI to the like.) But there is a question still to be solved. By CTooltipCtrl :: AddTool, you cannot self-movement into a subclass of the window that is attached to the message, so the mouse event must be handed over to the report information control. This is often intended to create a stand in the window.

If you send the correct mark to the message control of the CTooltipCtrl object, it should be able to create a subclass with self-created subclasses - this is oily functionality that is neglected by the MFC. Fortunately, it is not difficult to correct. Just send a class from the CTooltipCtrl class, with a similar function to ctooltipCtrl :: addtool, the function's TTM_ADDTOOL message uses the ToolInfo structure, and its UFLAGS domain contains TTF_SUBCLASS flags. Better square is to use two functions to replace it: they add to the sub-window and rectangular window area to add report information. The ADDTOOL function supports both, but the two methods of establishing a message in the formation of the information are different. Figures 1 and 2 show the source code of the classic class named CTooltipCtrl named CTooltip-Ctrlex. The derived class adds two functions to its contributing, one CTooltipCtrl :: AddWindow associates the message to the child window, and the second addRectangle enables the report information to the rectangular area of ​​the window. These two functions use TTF_SUBCLASS flags to make the creation of information. Assuming m_tooltipCtrl is CToolTipCtrlEx object, to the controller ID of IDC_BUTTON Buttons added prompt information on very easy a: m_tooltipCtrl.AddWindow (GetDlgItem (IDC_BUTTON), "Enter tooltip text here!"); How the CToolTipCtrlEx class package to DLL it? Under the detail steps in Visual C 4.x: 1. Launch Visual C and create new projects through the NEW from the FILE menu, double-click Project Workspace. Enter "Mfcext" in the NAME box of New Project Workspace. Select the MFC AppWizard (DLL) in the TYPE box. Click the CREATE button. 2. In the STEP 1 dialog box in AppWizard, select "MFC Extension DLL (Using Shared MFC DLL" through "What type of dll would you like to create?". Click the Finish button, then click the initial code of the OK production DLL. Note "Using Shared MFC DLL" displayed in the arc after the "MFC Extension DLL". When you write the MFC to expand the DLL, you cannot select a static link to the MFC. The DLL must be linked to the MFC library. 3. Place ClassWizard and click the Add Class button. Choose New to open the Create New Class dialog box.

In the box marked with the "base class", select CTooltipCtrl, enter "CTooltipCtrlex" in the box labeled "Name". Use the Change button to change the document name to Tooltip.h and Tooltip.cpp. (Change the name of the document is not necessarily, I do this is to avoid long file names.) Do not select the "Add to Component Gallery" box to save the tank space. Click the Create command to confirm the class, and then click OK to withdraw the ClassWizard. 4. As shown in Figure 2, add the member function addWindow and AddRectangle to the CTooltipCtrlex class. By these two functions to be accessed outside CTooltipCtrlex, they are confirmed to be public. Techniques: Jane to add members in Visual C is to click the class name in the ClassView window and select Add Function from the shortcut menu. 5. In the ClassView window, double-click the header of CTooltipCtrlex to open class. Add AFX_EXT_CLASS (see Figure 1) after the Class keyword of the class. 6. Building a project. You will generate two important documents: DLL- (Mfcext.dll) and the DLL's Guarantees (Mfcext.LIB). The introduction library basin is a list of a function name - or, in this example, a series of devices. Link to the Guaranteed Programming Enable the program that is exported from the MFC expansion DLL, as the library containing the same package is the static chain. Continued with the Mfcext.lib link also enables Windows to know the programming program to be Mfcext.dll to run. The application of MFC expansion DLL creates the use of Mfcext.dll is light and easy. Just ensure that the tooltip.h header files are included in each class that uses CTooltipCtrlex, and the Mfcext.lib adds to the list of items. Then CTooltipCtrlex can be used in the MFC class. When answering the appWizard's inquiry, you must select "As A Shared DLL", which you should have a dynamic link to the MFC. You can click the Mfcext.lib to add Mfcext.lib to the list of items from the Visual C 's build menu, click the Link tab and enter the path to Mfcext.lib in the box labeled "Object / Library Modules" (see Figure 3) ). Tooltest is a suitable program for sample examples, which shows a button in the dialog box. It is moving chain to Mfcext.dll and uses CTooltipCtrlex.

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

New Post(0)