Dialog frame as an ActiveX control | CodeGuru

Dialog frame as an ActiveX control

. I wanted to create a control which would behave as a dialog or formview (you can place controls here). There is a simple way to do it – to take advantage of ActiveX. Create a new MFC ActiveX ControlWizard workspace (no need to special options). Insert a new dialog resource named IDC_MYDIALOG (check following: […]

Written By
CodeGuru Staff
CodeGuru Staff
Dec 4, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

.

I wanted to create a control which would behave as a dialog or
formview (you can place controls here). There is a simple way to do it – to take advantage
of ActiveX.

  1. Create a new MFC ActiveX ControlWizard workspace (no need to special options).
  2. Insert a new dialog resource named IDC_MYDIALOG (check following: style – child, border
    – dialog frame, visible, control, static edge)
  3. Insert a new MFC class named CMyDialog
    (base class CDialog)
  4. Add CMyDialog m_MyDialog member to your CDialogCtrl header source
    (don’t forget to add #include "MyDialog.h")
  5. Using classwizard add a member function OnCreate (WM_CREATE)
int CDialogCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if (COleControl::OnCreate(lpCreateStruct) == -1)
        return -1;
    m_MyDialog.Create(IDD_MYDIALOG, this);
    return 0;
}

Modify the member function OnDraw (the dialog’s size depends on the WIDTH and HEIGHT
specified in the HTML file):

void CDialogCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
   // TODO: Replace the following code with your own drawing code.
   // pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
   // pdc->Ellipse(rcBounds);
   m_MyDialog.MoveWindow(rcBounds, TRUE);
}

To show the control in your browser use this simple HTML:

  <html>
  <head>
  <title>DialogControl</title>
  </head>
  <body>
  <center>
  <OBJECT ID=“DialogControl”  CLASSID=“CLSID:insert here the GUID from ODL fileHEIGHT=300 WIDTH=300>
  </OBJECT>
  </center>
  </body>
  </html>

Last updated: 17 November 1998

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.