VS2012 developing an MFC-based ActiveX control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.