Click here to Skip to main content
Click here to Skip to main content

Use an ActiveX control in your Win32 Project without MFC with CreateWindowEx or in a dialog box

, 15 Apr 2007
Rate this:
Please Sign up or sign in to vote.
An article on how to use an ActiveX control in your Win32 Project without MFC with CreateWindowEx or in a dialog box
Screenshot - d.jpg

Introduction

You would really like to use the multitude of ActiveX controls available in Windows and on the Internet, however you did have to use MFC or OWL or a non native platform. The solution is here! A HWND that acts as an ActiveX container!

Using the code

In short, AX is a HWND that acts as an ActiveX container. You register its class with AXRegister():

int __stdcall WinMain(HINSTANCE h,HINSTANCE,LPSTR,int)
{
    OleInitialize(0);
    if (!AXRegister())
        return 0;
    ...
}

Using the control is easy. You either use CreateWindowEx(), or specify the AX control within the RC editor:

DIALOG_1 DIALOGEX 0, 0, 500, 400
...
{
    CONTROL "{8856F961-340A-11D0-A96B-00C04FD705A2}", 801, "AX", 
                WS_CHILD | WS_VISIBLE, 0, 0, 500, 400
}

As the Window Title, you use the CLSID of the ActiveX object you wish to create. Here I used the CLSID of Internet Explorer. You can find all the CLSIDs you want by using MS's OLEView.

When you call CreateWindowEx() or DialogBox() to create the window, the ActiveX object will be created, but it won't as yet be activated in place. Use AX_INPLACE (wParam = 1 to Activate , wParam = 2 to deactivate):

case WM_INITDIALOG:
{
    HWND hX = GetDlgItem(hh,801);
    SendMessage(hX,AX_INPLACE,1,0)
...

And how do you access the interfaces that this ActiveX object supports? Use AX_QUERYINTERFACE, with WPARAM as a pointer to the reference ID, and LPARAM as a double pointer to the output interface. I try this with IWebBrowser2:

// Navigate
IWebBrowser2* wb = 0;
SendMessage(hX,AX_QUERYINTERFACE,(WPARAM)&IID_IWebBrowser2,(LPARAM)&wb);
if (wb)
{
    wb->Navigate(L"http://www.codeproject.com",0,0,0,0);
    wb->Release();
}

Points of Interest

AX.CPP and AX.H contain more code, not yet implemented (or yet buggy!) . My plan is to allow Advise Sink connections, OLE menus etc. in the future. AX implements as few as possible of the IOleClientSite methods, for simplicity. When you further explore OLE and ActiveX, you put your own implementations there!

With the above IWebBrowser2, for example, you might need to get notified when the user clicks on a URL. This can be done using IDispatch, but it isn't simple and I won't demonstrate it here, because it depends on the ActiveX control you want to host.

Good luck!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Michael Chourdakis
Engineer
Greece Greece
I'm working in C++, PHP , Flash and DSP Programming, currently experimenting with Windows 7 technologies and professional audio applications.
 
I 've a PhD in Digital Signal Processing.
 
My home page: http://www.michaelchourdakis.com

Comments and Discussions

 
QuestionIWebbrowser2 events in VC wihtout using MFC PinmemberMember 73749128-Jul-14 22:57 
AnswerRe: IWebbrowser2 events in VC wihtout using MFC PinpremiumMichael Chourdakis8-Jul-14 23:06 
GeneralRe: IWebbrowser2 events in VC wihtout using MFC PinmemberMember 73749128-Jul-14 23:44 
Generalthinks a lot Pinmemberkk501114-Aug-13 22:33 
Questiontab and delete keys are not working Pinmembervenkatesh528678-May-13 20:40 
QuestionFor "ENTER" click the events are not taking place on webpage. PinmemberNIKHIL788 Agrawal1-Dec-12 3:34 
AnswerRe: For "ENTER" click the events are not taking place on webpage. PinmemberMichael Chourdakis1-Dec-12 3:40 
GeneralRe: For "ENTER" click the events are not taking place on webpage. PinmemberNIKHIL788 Agrawal1-Dec-12 3:46 
GeneralRe: For "ENTER" click the events are not taking place on webpage. PinmemberMichael Chourdakis1-Dec-12 3:49 
GeneralRe: For "ENTER" click the events are not taking place on webpage. PinmemberNIKHIL788 Agrawal1-Dec-12 4:45 
QuestionCan not open tax.zip Pinmember40810576413-Nov-12 22:02 
AnswerRe: Can not open tax.zip PinmemberMichael Chourdakis14-Nov-12 5:38 
GeneralRe: Thanks Pinmember40810576414-Nov-12 15:43 
QuestionCanot compile PinmemberATILLA672-Oct-12 5:15 
AnswerRe: Canot compile Pinmembershint10-Apr-13 18:25 
GeneralThanks for this very useful article. PinmemberMember 83703258-Nov-11 12:50 
GeneralMy vote of 5 PinmemberMember 432084425-Oct-11 10:52 
GeneralIShockwaveFlash Pinmemberzzz7net9-Apr-11 13:25 
GeneralMy vote of 4 Pinmemberzzz7net3-Apr-11 14:34 
GeneralContext menu Pinmemberbasiek29-Mar-11 4:07 
GeneralRe: Context menu Pinmemberbasiek5-Apr-11 3:00 
GeneralKeyboard shortucts PinmemberMartin Kucera23-Jan-11 22:39 
GeneralRe: Keyboard shortucts PinmemberNIKHIL788 Agrawal2-Dec-12 1:59 
GeneralAdobe Acrobat Browser Control Pinmemberdrunkbear16-Jul-10 19:16 
GeneralRe: Adobe Acrobat Browser Control PinmemberDaktor15-Sep-10 8:09 
QuestionSizing error when I display google homepage. Pinmembersalvatore.sergi4-Mar-10 21:32 
AnswerRe: Sizing error when I display google homepage. PinmemberMartin Kucera23-Jan-11 22:36 
QuestionUsing flash activeX control using this code Pinmembersnehayp14-Jan-10 21:35 
AnswerRe: Using flash activeX control using this code PinmemberMichael Chourdakis14-Jan-10 21:43 
GeneralRe: Using flash activeX control using this code Pinmembersnehayp14-Jan-10 22:52 
GeneralRe: Using flash activeX control using this code PinmemberMichael Chourdakis15-Jan-10 1:23 
GeneralRe: Using flash activeX control using this code Pinmembersnehayp18-Jan-10 23:05 
GeneralRe: Using flash activeX control using this code PinmemberMichael Chourdakis19-Jan-10 2:41 
GeneralRe: Using flash activeX control using this code Pinmembersnehayp19-Jan-10 18:46 
GeneralRe: Using flash activeX control using this code PinmemberMichael Chourdakis20-Jan-10 1:38 
Questionhow to make it in WinForm Pinmembertanya_kuraeva5-Oct-09 6:03 
AnswerRe: how to make it in WinForm PinmemberMichael Chourdakis14-Jan-10 22:07 
GeneralMy vote of 2 Pinmembernityasantosh23-Sep-09 1:31 
GeneralDevCpp compilation and usage PinmemberDanilo Bonsignore5-Sep-09 14:06 
GeneralRe: DevCpp compilation and usage PinmemberMichael Chourdakis6-Sep-09 3:14 
GeneralRe: DevCpp compilation and usage Pinmembersyntotic6-Sep-09 14:45 
GeneralRe: DevCpp compilation and usage PinmemberMichael Chourdakis19-Jan-10 3:20 
GeneralRe: DevCpp compilation and usage PinmemberPamungkas Penta20-Oct-11 17:06 
GeneralRe: DevCpp compilation and usage PinmemberMichael Chourdakis21-Oct-11 1:51 
AnswerCompilation problem in VS2008 PinmemberInfinitum3D1-Sep-09 3:17 
GeneralRe: Compilation problem in VS2008 Pinmemberdrakooooo14-May-10 2:45 
QuestionFlash using this code? PinmemberGregor Casar9-May-09 5:09 
AnswerRe: Flash using this code? PinmemberMichael Chourdakis9-May-09 6:55 
GeneralRe: Flash using this code? PinmemberGregor Casar9-May-09 8:25 
QuestionHow to add mozilla fire fox activeX in this example PinmemberMember 46202168-Dec-08 20:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 15 Apr 2007
Article Copyright 2007 by Michael Chourdakis
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid