• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 658
  • Last Modified:

Examples/Snippets of Webbrowser/ActiveX in a dialog box using C Win32 API


I'm looking for working examples or working snippets of how to embed a webbrowser control (and any other ActiveX) into a dialog using C ,Win32 API SDK, non-MFC, non-ATL/WTL.

Thanks in advance!

1 Solution
Roshan DavisCommented:
I got this information from EE
One friend quoted like this


Import the informations about ActiveX into your Project

#import "axBrowser.ocx" named_guids raw_interfaces_only \no_namespace rename_namespace ("Arch")

after that if you rebuild the project, you can see in intermediate directory (Debug, for example) two
with extension .tlh and .tli
after that you can use the COM objects.
You NEED to read carefully the reference about #import directive. Content of generated files is COM
class wrappers, GUID reference and so on , imported from specified DLL(for example) and depends on #import
. You can use that like usual C++ classes. Don't forget to COM Init/DeInit.

hr  = CoInitialize(0);
hr = CoCreateInstance(CLSID_AxBrowser,
                   IID_IAxBrowser,(void **)

Good Luck
RolandAZAuthor Commented:
Thanks, roshmon, for input!
I'll try to follow your tip, and see if i can get it working.

RolandAZAuthor Commented:
roshmon and All, hello!

Using the import directive, as you suggested,

#import "axBrowser.ocx" named_guids raw_interfaces_only \
       no_namespace rename_namespace ("Arch") ,

the compiler reported "fatal error C1083: Cannot open type library file: 'axBrowser.ocx': No such file or directory ."

I want to use the IE browser control. I don't know what type library/ocx should I use in the import declaration.

With the result above, I decided to try RICHTX32.OCX, in lieu of the browser control, to see what happens. No error this time , but the Debug directory had a RICHTX32.tlh file but no .tli file.

Continuing, how do I use the info found in .tlh file, RICHTX32.tlh, like C++ classes and create a working control in a dialog box?

Please elaborate more on the details of using your technique to insert an activex control and the IE browser control into a dialog box.
Your help is greatly appreciated!
Thanks again in advance, Roshmon, and to all who replies to the question.


Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Hi RolandAZ,

From my understanding of your question, you don't want to use MFC.  Well, your in a world of pain!

BUT!  Look what I found ;-)


Good Luck.
RolandAZAuthor Commented:
hi, Peter,
Yes, no MFC on this one, and yes, it is a pain.

Thanks for the link! Though I still need to make a child dialog(not on the main window) that contains the webbrowser, I think you deserve points for the info.
100 points? I'll post it on "points for peterdownes."

And I'll still leave this question open ...

Any other help on inserting that webbrowser into a dialog is greatly appreciated.



This topic is very simple using Atl.

Just design your Dialog with Dialog Editor into Visual C++ and insert the WebBrowser ActiveX control.
Modify properties (Dialog Editor saves the control properties in your .rc file).

And in your code do not call DialogBox or relates functions. Use this code instead:

#pragma once

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
#define _WIN32_WINNT 0x0500

// Windows Header Files:
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>

// C RunTime Header Files
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stddef.h>
#include <limits.h>

// ATL Windows support Header files
#include <atlbase.h>
extern CComModule _Module;
#include <atlwin.h>
#include <atlctl.h>

// OLE-ActiveX support Header files
#include <objbase.h>
#include <ocidl.h>

/*                                                                         */
/*                                                                         */
/* CMyDialogBox class                                                    */
/*                                                                         */
/*                                                                         */
class CMyDialogBox : public CAxDialogImpl< CMyDialogBox >

int        IDD;
HWND       m_hWndParent;
DLGPROC    m_DlgProc;

      CMyDialogBox( int Idd = NULL, HWND hWndParent = NULL, DLGPROC pDlgProc = NULL )
           IDD = Idd;
           m_hWndParent = hWndParent;
           m_DlgProc = pDlgProc;

      BOOL ProcessWindowMessage( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID = 0 )
           if( uMsg == WM_INITDIALOG ) CenterWindow( m_hWndParent );
           if( m_DlgProc ) return (BOOL)CallWindowProc( (WNDPROC)m_DlgProc, hWnd, uMsg, wParam, lParam );
           else return 0;


And, when you want display the dialog, use:

CMyDialog*   dlg = new CMyDialog( IDD_DIALOG, hWndParent, (DLGPROC)MyDlgProc );

     LRESULT lResult = dlg.DoModal();
     return lRet;

In your Dialog Procedure, you can use AtlAxGetControl() function to get a IUnknown pointer to WebBrowser or whatever controls you insert in your dialog, and modify behaviour in your WM_INITDIALOG procedure.

See Atlhost.h in ATL library for reference. Is an incredible source or knowledge about these topis.

Hope this will help you.


RolandAZAuthor Commented:
Thanks for input, Jorge.
I will try your suggestion and see if I can get it working on my non-MFC, non-ATL non-WTL app.

Will get back on this ...

PAQed - no points refunded (of 500)

Community Support Moderator

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now