Startup of VC ActiveX Control writing-creation and debugging

Source: Internet
Author: User

Recently, I have been trying to develop ActiveX controls. I should do a good job in the first step. I checked a bunch of ActiveX Control Principles and found it is quite similar to the DLL dynamic library.

Next, go to the topic. First, create a project. There are two ways to compile ActiveX Controls: one is MFC ActiveX and the other is ATL ActiveX. What is the difference between the two? The control made by MFC comes with a series of runtime libraries of MFC. Although it is based on the COM interface, it is much larger than that of ATL. The control made by ATL is a product completely based on the COM technology, and the OCX control generated is smaller and more flexible (the more flexible price is that you need to be familiar with multiple API functions, messages are well understood, because all messages without MFC encapsulation must be completed by yourself ).

The following uses an ActiveX control of MFC as an example to create a new project: file-> New-> Project

 

 

 

 

 

 

 

 

 

 

In the next steps, use the default settings to enter the control settings:

#002 #


 

 

 

 

 

 

 

 

 

 

 

 

Select "activation when visible" and "activation without blinking", cancel the "about" dialog box, and click-> finish.

So far, an MFC-based ActiveX project has been established. Let's add a method for this project and switch to the Class View first:

#003 #

 

 

 

 

 

 

 

 

 

Right-click _ dmfc_activex and select "return type" and "parameter type". In this example, the return type is long and the parameter type is long. Add a function named addfun.

#004 #

After addition, a piece of code is automatically added in ctrl:

Long cmfc_activexctrl: addfun (long Add1, long Add2)
{
Afx_manage_state (afxgetstaticmodulestate ());

// Todo: add the scheduling handler code here

Return Add1 + Add2; // The returned data Add1 + Add2
}

The next step is to create a debugging environment, because ActiveX controls cannot be run directly, and they need to be run by a third party. There is a tool in vc6.0 that can be used to test ActiveX, but this tool is not available in vc2008. Therefore, you need to create an HTML webpage to call this control, this is also the ideal environment for testing ActiveX controls, because it is a test in a real environment.

Add a new item> HTML page to an existing project. Enter the following code:

<HTML>
<Head>
<Meta name = "generator" content = "Microsoft Visual Studio 8.0">
<Title> dialogcontrol </title> // Title
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Script language = "JavaScript">
Function addfun () // call the Control Method
{
VaR object = mfc_activex.addfun (11,12 );
Alert (object );
}
</SCRIPT>
</Head>
<Body>
<Center>
<Object ID = "mfc_activex" classid = "CLSID: C9D6CF40-B5EC-436E-B3DA-D61B73DD28C2" Height = 600 width = 400 cadebase = "Debug \ textmfc_activex.ocx">

// This is the key. mfc_activex is the project name. Note that you must add CLSID when entering classid. Otherwise, a Red Cross will pop up on the webpage, followed by the guid of the mfc_activex project. the class information of the Dil suffix file. The cadebase value is the location of the OCX control in the project file.
<Param name = "_ version" value = "65536">
<Param name = "_ extentx" value = "3329">
<Param name = "_ extenty" value = "2164">
<Param name = "_ stockprops" value = "64">
</Object>
<Fieldset>
<Legend> test page </legend>
<Table border = "0" cellspacing = "0" cellpadding = "0" width = "100%">
<Tr>
<TD width = "20%"> <input type = "button" onclick = "addfun ()" value = "addfun"/> // Add a button named addfun
</TD>
</Tr>
</Center>
</Body>
</Html>

The last step is to set project-> property-> Debug:

Enter c: \ Program Files \ Internet Explorer \ iw.e. EXE in "command ".

In "Command Parameters", enter $ (inputdir) + the HTML file name you created, for example, watermark (inputdir)atltext.htm, where inputdir is added as a macro insert.

After all these are done, you can use normal debugging. Press F5 to automatically load the ActiveX control on the webpage.

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.