Click here to Skip to main content
13,868,406 members
Click here to Skip to main content
Add your own
alternative version

Stats

181.9K views
4.3K downloads
53 bookmarked
Posted 15 Apr 2007
Licenced

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

Share

About the Author

Michael Chourdakis
Engineer
Greece Greece
I'm working in C++, PHP , Java, Windows, iOS and Android.

I 've a PhD in Digital Signal Processing and Artificial Intelligence and I specialize in Pro Audio and AI applications.

My home page: http://www.michaelchourdakis.com

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralRe: Flash using this code? Pin
Gregor Casar9-May-09 9:25
memberGregor Casar9-May-09 9:25 
QuestionHow to add mozilla fire fox activeX in this example Pin
Member 46202168-Dec-08 21:07
memberMember 46202168-Dec-08 21:07 
AnswerRe: How to add mozilla fire fox activeX in this example Pin
Michael Chourdakis8-Dec-08 21:47
mvaMichael Chourdakis8-Dec-08 21:47 
GeneralRe: How to add mozilla fire fox activeX in this example Pin
Member 46202168-Dec-08 21:54
memberMember 46202168-Dec-08 21:54 
Questionwhat about this clsid ? Pin
Frédéric Steczycki25-Nov-08 23:57
memberFrédéric Steczycki25-Nov-08 23:57 
GeneralThe thread wont exit Pin
wamu6-Nov-08 2:31
memberwamu6-Nov-08 2:31 
GeneralRe: The thread wont exit Pin
Michael Chourdakis6-Nov-08 3:05
mvaMichael Chourdakis6-Nov-08 3:05 
GeneralSpecify AX control with CtreateWindowEx() Pin
rexwang130-Sep-08 6:40
memberrexwang130-Sep-08 6:40 
GeneralRe: Specify AX control with CtreateWindowEx() Pin
Michael Chourdakis30-Sep-08 9:12
mvaMichael Chourdakis30-Sep-08 9:12 
GeneralRe: Specify AX control with CtreateWindowEx() Pin
rexwang130-Sep-08 15:56
memberrexwang130-Sep-08 15:56 
GeneralRe: Specify AX control with CtreateWindowEx() Pin
Michael Chourdakis30-Sep-08 20:52
mvaMichael Chourdakis30-Sep-08 20:52 
QuestionCompatibility Pin
BMW74023-Sep-08 23:43
memberBMW74023-Sep-08 23:43 
AnswerRe: Compatibility Pin
Michael Chourdakis24-Sep-08 2:55
mvaMichael Chourdakis24-Sep-08 2:55 
GeneralRe: Compatibility Pin
BMW74024-Sep-08 3:55
memberBMW74024-Sep-08 3:55 
QuestionMethods and Events Pin
zevo10-Sep-08 6:01
memberzevo10-Sep-08 6:01 
AnswerRe: Methods and Events Pin
Michael Chourdakis10-Sep-08 8:29
mvaMichael Chourdakis10-Sep-08 8:29 
GeneralRe: Methods and Events Pin
zevo10-Sep-08 11:07
memberzevo10-Sep-08 11:07 
GeneralRe: Methods and Events Pin
Michael Chourdakis10-Sep-08 20:42
mvaMichael Chourdakis10-Sep-08 20:42 
GeneralRe: Methods and Events Pin
Eusebiu Marcu18-Nov-08 9:41
memberEusebiu Marcu18-Nov-08 9:41 
GeneralRe: Methods and Events Pin
Michael Chourdakis19-Nov-08 5:54
mvaMichael Chourdakis19-Nov-08 5:54 
GeneralRe: Methods and Events Pin
Eusebiu Marcu19-Nov-08 23:58
memberEusebiu Marcu19-Nov-08 23:58 
GeneralRe: Methods and Events Pin
Michael Chourdakis20-Nov-08 6:12
mvaMichael Chourdakis20-Nov-08 6:12 
GeneralRe: Methods and Events [modified] Pin
Eusebiu Marcu21-Nov-08 1:34
memberEusebiu Marcu21-Nov-08 1:34 
GeneralRe: Methods and Events Pin
Daktor24-Aug-10 10:48
memberDaktor24-Aug-10 10:48 
GeneralRe: Methods and Events Pin
Daktor8-Sep-10 11:06
memberDaktor8-Sep-10 11:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Cookies | Terms of Use | Mobile
Web02 | 2.8.190214.1 | Last Updated 15 Apr 2007
Article Copyright 2007 by Michael Chourdakis
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid