1. New Project
2. Click Next until the interface appears, note the Red Callout option, and click Done.
3. Enter the project's property interface and set the project properties
4. Add a dialog resource and other controls, add a dialog box class,
5. Setting dialog Box Properties
6. Set the "Add Class" for dialog
Enter "class name"; (other blanks are filled in automatically)
The "MyDlg.h" and "MyDlg.cpp" two files are automatically generated at this time.
7. To add the Wm_create event to "Cdemoactivexctrl", select "< add >oncreate" to initialize the dialog box object.
There are two more pieces of code in "DemoActiveXCtrl.cpp" at this point.
8. Modify the Code
(1) in "DemoActiveXCtrl.h" Add header file #include "MyDlog.h" and member Mydlg M_mydlg;
(2) Modify DemoActiveXCtrl.cpp "
int cdemoactivexctrl::oncreate (lpcreatestruct lpcreatestruct) { if (Colecontrol::oncreate ( lpcreatestruct) = =-1 )return -1; // TODO: Add your dedicated create code m_mydlg.create (idd_dialog1, this)here; // Initialize dialog box return 0 ;}
void Cdemoactivexctrl::ondraw (CDCconstconst crect& rcinvalid) { if (! PDC) return;
M_mydlg.movewindow (RcBounds,true); }
At this point, the interface with the edit box can already be displayed after the control has been loaded, click "Build" in the menu bar, "Rebuild solution", and if there is no error, the control will be registered in this machine. Write a simple HTM file below to test the control on this computer.
<HTML><HEAD><TITLE>Test ActiveX</TITLE></HEAD><OBJECTID= "Textactivex"WIDTH=528HEIGHT=545ClassID= "Clsid:ecf33ace-175e-4d25-919a-0fabf03b55d5"> <PARAMNAME= "_version"VALUE= "65536"> <PARAMNAME= "_extentx"VALUE= "12806"> <PARAMNAME= "_extenty"VALUE= "1747"> <PARAMNAME= "_stockprops"VALUE= "0"></OBJECT></HTML>
where "ecf33ace-175e-4d25-919a-0fabf03b55d5" is obtained through "demoactivexctrl.idl"
Use IE browser to open the saved HTML file, you can display the control, if not configured under IE Security options ~ ~ ~
VS2012 developing an MFC-based ActiveX control