Using VBX Controls with MFC 2.0Last reviewed: July 18, 1997Article ID: Q116494 |
1.00
WINDOWS
kbprg
The information in this article applies to:
SUMMARYThis document lists several common questions that developers using Microsoft Visual C++ version 1.0 might have when using VBX controls.
1. Q. Where can I find more information on using VBX controls with Visual C++? A. There are many locations in the documentation and sample code where VBX issues are discussed. They include: Class Library User's Guide, Chapter 17 "Programming with VBX Controls" MFC technote #27 "Emulation Support for Visual Basic Custom Controls" Class Library Reference (Ref. Vol. 1), CVBControl description (P.827) MFC Sample Programs: VBCIRCLE - Illustrates how to dynamically create a VBX control and how to use a VBX control in a dialog. VBCHART - using App Studio and ClassWizard with a VBX control. Also, calling CVBControl member functions. Sample programs: SUBVBX - This sample shows how to subclass a VBX control. Specifically, it subclasses the grid control to allow arrow navigation in the grid. This sample (SUBVBX.ZIP) is located in the library of section 8 in the MSLANG forum. You can retrieve the accompanying article by going to the Microsoft Developer's Knowledgebase (GO MDKB) and searching for the following identification number: Q103856 AFXVBX - Illustrates how to use VBX controls in a DLL. It shows how to dynamically create them using CVBControl::Create(), and also how to use them as part of a dialog template resource. At the time of this writing, this sample is undergoing internal review. However, if you have a pressing need for this information, leave a message to the sysop of section 6 in the MSLANG forum. MFCVBX - This sample demonstrates how to write a VBX control using MFC 2.0. This sample is implemented as a _USRDLL. The _USRDLL model allows this sample to be used by both MFC and VB applications. Using the _AFXDLL model would restrict this sample to be used only by MFC applications. It also creates an object of a class derived from CWinApp. This allows necessary MFC initializations to take place. Another good place to find information on using VBX controls with Visual C++ is the Microsoft Developer's Knowledge Base on the MSDN CD-ROM or on the Internet (http://www.microsoft.com). Search on the following words: MFC VBX This query will list all articles that contain information on using VBX controls with the Microsoft Foundation Class library. 2. Q. I've added a VBX control to my dialog box, but when I go to ClassWizard, no messages are listed when I click on the object ID. A. Go to the Microsoft Knowledgebase and query on the following words: VBX Class Wizard That query will bring up the following article which discusses the cause and workaround for this problem: PRB: Class Wizard Does Not Display Messages for VBX Control ID: Q102668 3. Q. I'd like to install an image into the picture property of a VBX control at run-time. How do I do that? A. Read the section in MFC technote #27 titled "How to Manage VBX Picture Properties in MFC". Also, go to the Microsoft Developer's Knowledgebase (GO MDKB) and search on the following words: VBX MFC Picture That query will bring up the following article: How to Manage VBX Picture Properties with MFC 2.0 ID: Q104642 This articles corrects some erroneous information in the MFC technote and provides additional information as well as some sample code. 4. Q. Can I use VBX controls in my WIN32 or WIN32s application? If not, why not? A. 16 bit VBX controls cannot be used by WIN32 or WIN32s applications. VBX controls are 16-bit DLLs and cannot be mapped into the address space of a WIN32 application. WIN32s supports calling 16-bit DLLs through special thunks. Since VBX controls aren't written to use these thunks, they can't be used with WIN32s applications. Microsoft is currently developing a 32-bit custom control model that will be compatible with WIN32 and WIN32s. The following statement represents the most current information available: "Microsoft Visual C++ and Microsoft Visual Basic are committed to supporting the existing custom control extensibility mechanism (VBX) that has been widely adopted by corporations and ISVs. Microsoft will extend this architecture by adding support for OLE 2.0 for both 16- and 32-bit Windows platforms. A new control architecture that merges the benefits of OLE 2.0 with the existing VBX architecture will be supported in future versions of all 16- and 32-bit Microsoft tools and applications. We are working on a new control development kit (CDK) for both the 16- and 32-bit Windows platforms. We will be providing information on how to create new controls as well as on how an existing 16-bit VBX custom control may be enhanced to take advantage of this new architecture. We do not have any more detailed product information or a schedule to announce at this time." 5. Q. I'm using GRAPH.VBX, and it only seems to work in while I'm in AppStudio. If I change a property while my program is running, the graph does not update properly. Why is this? A. This behavior is by design. You need to set the DrawMode property to 2 in order to redraw the graph at run-time. The reason for this is that often you are setting many properties sequentially that will effect the appearance of the graph. You normally would like the graph to only redraw when all properties have been updated. 6. Q. Can I use VBX controls in a Windows-based application written entirely in C? A. No. The VBX support in Visual C++ is provided as part of the Microsoft Foundation Class (MFC) library. This library is written in C++ and requires any application using it to be written in C++. It is worth noting, however, that an MFC application can include a mixture of C++ and C code. 7. Q. How can I develop my own VBX controls? A. You will need to purchase the Control Development Kit (CDK). This kit comes bundled with Visual Basic 3.0 Professional Edition and is also part of the Visual Control Pack. The CDK is not sold as a stand-alone product. The CDK contains a library (VBAPI.LIB) and header file (VBAPI.H) needed for VBX control development and also includes documentation and several example VBX controls (with source code). 8. Q. What 3rd-party controls do you recommend? A. Microsoft does not explicitly recommend or endorse any third-party VBX controls. However, Visual C++ does contain a pamphlet titled "Direct access for Microsoft Visual C++" that lists several VBX vendors. You might also want to look at advertisements in a recent copy of "Visual Basic Programmer's Journal" or "Windows Tech Journal" to get additional leads. Finally, you could call a company that specializes in distributing third party libraries and add-on products. Three of them are listed below: Programmer's Paradise (800)445-7899 Programmer's Shop (800)421-8006 Provantage (800) 336-1166 9. Q. How do I add VBX support to an MFC application? A. If you are using AppWizard to initially create the application, make sure to press the "Options..." button and check the "Custom VBX Controls" check box in the Options dialog. If you have already run AppWizard and decide to add VBX support at a later date, you will need to add the following line: EnableVBX(); to your application's InitInstance() function. 10. Q. I'm using the grid control. I have noticed that when a cell (or group of cells) is selected and I use the scroll bar to scroll the grid's contents, the display it not updated correctly. Why does this happen? A. There is a problem with MFC's emulation of Visual Basic that prevents the grid from painting itself correctly under some circumstances. Please refer to article q108901 for the fix. 11. Q. My MFC application has been working correctly, but as soon as I add a VBX control to a dialog box, it fails to come up. Why? A. Your application does not have VBX support enabled. See question 9 for information on enabling support for VBX controls in an MFC application. |
Additional reference words: kbinf 1.00 2.00 faq
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |