Distinct offers Network Monitor, the ONLY natural language Protocol Analyzer, ONC RPC for C++, .NET and Java, and IntelliTerm, the fastest Terminal Emulator for TN3270, TN5250 and VT420 on the market.

Knowledge Base

   Products   Downloads   Sales   Support   About us
  Knowledge Base  Ask Cody  Manuals  Source Code Library  Resources



        
 
How can I create an instance of an Active X control dynamically?
 
Product: Distinct VITTopic: GeneralLast updated: 3/17/2008
 
Q.: How can I create an instance of an Active X control dynamically?
A.: The following article is an excerpt from MSDN and can be found under the subject-ActiveX Control Containers: Using Controls in a Non-Dialog Container

In some applications, such as an SDI or MDI application, you will want to embed a control in a window of the application. The Create member function of the wrapper class, inserted by Gallery, can create an instance of the control dynamically, without the need for a dialog box.

The Create member function has the following parameters:

lpszWindowName

A pointer to the text to be displayed in the control's Text or Caption property (if any).

dwStyle

Windows styles. For a complete list, seeCWnd::CreateControl.

rect

Specifies the control's size and position.

pParentWnd

Specifies the control's parent window, usually a CDialog. It must not be NULL.

nID

Specifies the control ID and can be used by the container to refer to the control.

One example of using this function to dynamically create an ActiveX control
would be in a form view of an SDI application. You could then create an instance of the control in the WM_CREATE handler of the application.For this example, CMyView is the main view class, CCirc2 is the wrapper class, and CIRC2.H is the header (.H) file of the wrapper class.

Implementing this feature is a four-step process.

To dynamically create an ActiveX control in a non-dialog window
Insert CIRC2.H in CMYVIEW.H, just before the CMyView class definition:
#include "circ2.h"

Add a member variable (of type CCirc2) to the protected section of the CMyView class definition located in CMYVIEW.H:
class CMyView : public CView
{
...
protected:

CCirc2 m_myCtl;
...
};

Add a WM_CREATE message handler to class CMyView.


In the handler function, CMyView::OnCreate, make a call to the control's Create function using the this pointer as the parent window:
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (MyView::OnCreate(lpCreateStruct) == -1)
return -1;

// ****** Add your code below this line ********** //

m_myCtl.Create(NULL, WS_VISIBLE,
CRect(50,50,100,100), this, 0);
m_myCtl.SetCaption(_T("Control created"));

// ****** Add your code above this line ********** //

return 0;
}

Rebuild the project. A Circ2 control will be created dynamically whenever the application's view is created.

Do you find this information useful ?       Yes   No   Not Sure




Search by Keyword


If you did not find what you are looking for:


Products

 Packet Analyzer
The Distinct Network Monitor is a protocol analyzer for Windows that includes both packet sniffing and network traffic statistical analysis tools.

 Intelliterm
The Most Complete Terminal Emulator for TN3270, TN5250 and DEC VT220 to VT420

 RPC for C and C++
The Fastest Way to Port Your Existing Unix-RPC Applications to Windows

  7/24/2008   Legal notices | PRIVACY Policy | Networking News |         Page Last Modified: 3/31/2008