Use Dialog and FormView in ActiveX

Source: Internet
Author: User

Recently, I made ActiveX plug-ins to get started with a series of articles titled "Development of ActiveX controls based on MFC" by a cool man on the Internet. However, his article mainly introduces development in the framework provided by ActiveX itself. If I want my ActiveX plug-in to be displayed in the form of Dialog or FormView, what should I do? This article will summarize this and summarize how to debug ActiveX under vs2008 and on the webpage as a supplement to the above series of articles.

1. Use Dialog in ActiveX

1. Create an ActiveX project named MyActiveX.

2. Create a Dialog box resource Dialog) and associate it with a CMyDialog class ). Check the resource configuration in the dialog box. Recommended Configuration: style: child, border: dialog frame, visible: ture, control: ture

3. perform the following operations on ActiveX Control CMyActiveXCtrl:

1) in the definition of CMyActiveXCtrl class, add a member variable: CMyDialog m_myDlg;

2) add an OnCreate message response for the CMyActiveXCtrl class:

 
 
  1. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); 

3) In the OnCreate message response function, add the following code:

 
 
  1. M_myDlg.Create (IDD_MYDLG, this); // IDD_MYDLG is the resource ID of the dialog box.

4) Add the following code to the OnDraw function of the CMyActiveXCtrl class:

 
 
  1. m_myDlg.MoveWindow(rcBounds, TRUE); 

4. Now, the basic work is complete. You can test it in Active X control test container.

IIUse FormView in ActiveX

Using FormView in ActiveX is similar to using Dialog, but there are many differences between FormView and Dialog, so pay special attention to it.

1. Create an ActiveX project. Assume the project name is MyActiveX.

2. Create a FormView resource and associate it with a class CMyForm derived from CFormView ). Check the resource configuration in the dialog box. Recommended Configuration: style: child, border: none, visible: ture, control: ture

3. add a friend declaration in the definition of the CMyForm class: friend class CmyActiveXCtrl;) because the Create function of the FromView class is of the protected type, if you want to manually call the Create function of the FromView derived class, you can either add a friend declaration or, in the definition of the derived class CMyForm, reload the Create method and set it to public.

4. perform the following operations on ActiveX Control CMyActiveXCtrl:

1) in the definition of CMyActiveXCtrl class, add a member variable: CMyForm * p_myFrom; // Note: pointers must be used here, And FormView resources must be dynamically created. If objects are directly used here, instead of using pointers, a Debug Assertion Fail error occurs when the ActiveX control is released.

2) Add OnCreate message response for CMyActiveXCtrl class

 
 
  1. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); 

3) In the OnCreate message response function, add the following code:

 
 
  1. p_myForm = new CMyForm(); 
  2. p_myForm->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL);  

4) Add the following code to the OnDraw function of the CMyActiveXCtrl class:

 
 
  1. p_myForm->MoveWindow(rcBounds,TRUE);  

5. Now, the basic work is complete. You can test it in Active X control test container.

Iii. debug ActiveX controls in win7 + vs2008

In vs2008, there is no built-in Active X control test container and you need to compile it yourself. Some problems may occur during this process. I have collected the solution on the Internet, for your reference.

When Editing ActiveX controls, you can use Active X control test container to test activex controls. This is easy to find in Visual Studio 6, which is available under the tool menu. However, in Visual Studio 2008, The tstcon32.exe file disappears. So it's gone, no. Microsoft put it in the example program and compiled it by itself. Detailed Directory: for example, if I install it in disk C, the VC example is in the source code of "C: \ Program Files \ Microsoft Visual Studio 9.0 \ Samples \ 2052 \ Program: "C ++ \ MFC \ ole \ TstCon", you can compile it yourself.

Note that the default solution platform for Win32 is used. Therefore, when compiling TCProps and TstCon, select the compiling platform as Win32 instead of the default Itanium platform.

650) this. width = 650; "alt =" "src =" data: image/png; base64, kernel + kernel +/kernel + QpCSG2OXK5 + kernel/kernel + kernel/cEdFMGOdteByVT1Dizy8/kernel + kernel/X3t + kernel + Gpg/kernel/D7NlbWU /jRXlkEu + release/H4lgn309/release + Y3 + release/f2THO1 + 9 + dqXL1 + 9 vRhWOJPd + GEscuS + release/release + Q3MAa0lJ6 + export + dTasTFB + tQgh/9 ElODuR + Yqd99gy/un + logs/logs + fAzLgtZQ + logs/j7aZMBrmTP/4B6oiOX /avmiePX + keys/keys + hE5bt8JY3X1y/keys/Iif4LNfGQuGbWiu8 + 78k6Dly/wPqcS08S5 + WvgAAAABJRU5ErkJggg = "/>

OK to compile. Note that you must first compile TCProps and then compile TstCon.

If you run the test in win7, an error occurs. The "parallel running error" dialog box is displayed. solution ]:

1) Add # define _ WIN32_WINNT 0x0600 to StdAfx. H files of TstCon and TCProps respectively.

2) The original TstCon project does not have to be added between the corresponding statements. The original TCProps project Changes # define _ WIN32_WINNT 0x0400 to # define _ WIN32_WINNT 0x0600.

3) perform the following operations on each project: Right-click the project and choose Properties> Configuration Properties> Linker> Manifest File. Select Enable User Account Control (UAC ): change "No" to "Yes". Click "application" and click "OK. You need to configure each Release and Debug configuration once.

In addition, the following error may occur during MyActiveX project compilation in vs2008:

Project: error PRJ0050: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions.

Solution ]:

1) choose No in project configuration> Linker> General> Per-User Redirection.
2) Right-click the vs2008vs exe icon with the Administrator permission and choose "Run as administrator)
3) if the problem persists, check whether all the library files on which your ActiveX project depends are located. in the directory where the ocx file is located, if the dependent library file is missing, this error is also reported.

4. Test ActiveX on the webpage

First, install ActiveX Control Pad, which is a tool provided by Microsoft to dynamically generate html page code for testing ActiveX, you can easily generate the required html code or webpage.

Then, perform the following steps:

1. Set your myActiveX project to release to generate a required version.) Otherwise, ActiveX Control Pad cannot obtain valid plug-in information. Note: After changing to the release version, pay attention to the engineering configuration, such as the dependent libraries, must be consistent with the debug version .)

2. Open ActiveX Control Pad and select File> New HTML to create an HTML page.

3. select Edit-> Insert ActiveX Control... from the ActiveX Control Pad menu, and a message box will pop up. Select ActiveX Control from the list of message boxes and click OK to insert ActiveX Control to the HTML page. You can adjust relevant parameters in the pop-up box, such as the control size)

4. Open the generated HTML in the local IE browser to see ActiveX Control displayed on the HTML page. Note: Some browsers may disable ActiveX Control Loading and check related security configurations)

 

This article from the "three shadows" blog, please be sure to keep this source http://ticktick.blog.51cto.com/823160/610784

Related Article

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.