Click here to Skip to main content
Licence 
First Posted 3 Jan 2003
Views 46,477
Bookmarked 33 times

Simple ActiveX control interface support via CAxWindow

By | 3 Jan 2003 | Article
HOWTO support AX control interface via CAxWindow

Introduction

Code below describes only idea using CComQIPtr template in pair with CAxWindow.
class CAxOwnControl : 
public CWindowImpl< CAxOwnControl , CAxWindow >,
public CComQIPtr< IControl, &IID_IControl >
{
public:
DECLARE_WND_SUPERCLASS("AxOwnControl", CAxWindow::GetWndClassName());
CAxOwnControl(){}
virtual ~CAxOwnControl(){}

HWND Create(HWND hWndParent, RECT& rcPos, 
        DWORD dwStyle = 0, DWORD dwExStyle = 0, 
        UINT nID = 0, LPVOID lpCreateParam = NULL)
{
	AtlAxWinInit(); // initialize AxHost stuff
	LPOLESTR pstrCLSID_CAxOwnControl = NULL;
	StringFromCLSID( CLSID_Control, &pstrCLSID_CAxOwnControl );
	ATLASSERT( pstrCLSID_CAxOwnControl != NULL );
	if( !pstrCLSID_CAxOwnControl )
		return NULL;

	USES_CONVERSION;
	HWND hWnd = CWindowImpl<CAxOwnControl , 
                     CAxWindow>::Create(hWndParent, rcPos, 
                     OLE2T(pstrCLSID_CAxOwnControl ), 
                     dwStyle, dwExStyle, nID, lpCreateParam);
	CoTaskMemFree(pstrCLSID_CAxOwnControl);

	if( hWnd ){
		IControlPtr pControl = NULL;
		QueryControl( IID_IControl, (void**)&pControl );
		*((CComQIPtr< IControl, &IID_IControl >*)this) = pControl;
	}

	return hWnd;
}

BEGIN_MSG_MAP_EX(CAxOwnControl)
END_MSG_MAP()
};

HOWTO use:
    CAxOwnControl m_ctrl;
    m_ctrl.Create(...);
    m_ctrl->SomeControlMethod();

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

Vasyl Zakharko

Web Developer

Ukraine Ukraine

Member



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
QuestionCan I add CWindow Ctrl in ATL Simble Object class Pinmembersiva_codeproject21:10 24 Mar '04  
GeneralToo wide AND no real content PinsitebuilderUwe Keim4:48 4 Jan '03  

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
Web04 | 2.5.120517.1 | Last Updated 4 Jan 2003
Article Copyright 2003 by Vasyl Zakharko
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid