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.

  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:
  <OBJECT ID="DialogControl"  CLASSID="CLSID:insert here the GUID from ODL file"
   HEIGHT=300 WIDTH=300>

Last updated: 17 November 1998


  • Thank for your article.

    Posted by fery Setianto on 07/03/2013 10:04pm

    Thank for your article.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

  • Thanks to the Internet of Things (IoT), physical assets are turning into participants in real-time global digital markets. The countless types of assets around us will become as easily indexed, searched and traded as any online commodity. While some industries will be tougher to transform than others – those with physical limitations, such as manufacturing, will be harder to digitize – untold economic opportunities exist for growth and advancement. Our research shows this will create a new "Economy …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date