Click here to Skip to main content
Licence 
First Posted 15 Apr 2007
Views 70,169
Downloads 1,027
Bookmarked 38 times

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

By Michael Chourdakis | 15 Apr 2007
An article on how to use an ActiveX control in your Win32 Project without MFC with CreateWindowEx or in a dialog box
1 vote, 5.9%
1
2 votes, 11.8%
2

3
3 votes, 17.6%
4
11 votes, 64.7%
5
4.18/5 - 17 votes
1 removed
μ 3.91, σa 2.32 [?]
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

Member
I'm working in C++, PHP , Flash and DSP Programming, currently experimenting with Windows 7 technologies and professional audio applications.
 
http://www.turboirc.com
 
You can find me on efnet in #musicdsp, #win32 and #winprog.
Nick: WindowsNT.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThanks for this very useful article. PinmemberMember 837032513:50 8 Nov '11  
GeneralMy vote of 5 PinmemberMember 432084411:52 25 Oct '11  
GeneralIShockwaveFlash Pinmemberzzz7net14:25 9 Apr '11  
GeneralMy vote of 4 Pinmemberzzz7net15:34 3 Apr '11  
GeneralContext menu Pinmemberbasiek5:07 29 Mar '11  
GeneralRe: Context menu Pinmemberbasiek4:00 5 Apr '11  
GeneralKeyboard shortucts PinmemberMartin Kucera223:39 3 Jan '11  
GeneralAdobe Acrobat Browser Control Pinmemberdrunkbear20:16 16 Jul '10  
GeneralRe: Adobe Acrobat Browser Control PinmemberDaktor9:09 15 Sep '10  
QuestionSizing error when I display google homepage. Pinmembersalvatore.sergi22:32 4 Mar '10  
AnswerRe: Sizing error when I display google homepage. PinmemberMartin Kucera223:36 3 Jan '11  
QuestionUsing flash activeX control using this code Pinmembersnehayp22:35 14 Jan '10  
AnswerRe: Using flash activeX control using this code PinmemberMichael Chourdakis22:43 14 Jan '10  
GeneralRe: Using flash activeX control using this code Pinmembersnehayp23:52 14 Jan '10  
GeneralRe: Using flash activeX control using this code PinmemberMichael Chourdakis2:23 15 Jan '10  
GeneralRe: Using flash activeX control using this code Pinmembersnehayp0:05 19 Jan '10  
GeneralRe: Using flash activeX control using this code PinmemberMichael Chourdakis3:41 19 Jan '10  
GeneralRe: Using flash activeX control using this code Pinmembersnehayp19:46 19 Jan '10  
GeneralRe: Using flash activeX control using this code PinmemberMichael Chourdakis2:38 20 Jan '10  
Questionhow to make it in WinForm Pinmembertanya_kuraeva7:03 5 Oct '09  
AnswerRe: how to make it in WinForm PinmemberMichael Chourdakis23:07 14 Jan '10  
GeneralMy vote of 2 Pinmembernityasantosh2:31 23 Sep '09  
GeneralDevCpp compilation and usage PinmemberDanilo Bonsignore15:06 5 Sep '09  
GeneralRe: DevCpp compilation and usage PinmemberMichael Chourdakis4:14 6 Sep '09  
GeneralRe: DevCpp compilation and usage Pinmembersyntotic15:45 6 Sep '09  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120209.1 | Last Updated 15 Apr 2007
Article Copyright 2007 by Michael Chourdakis
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid