Thanks in advance!
Maimee
Well, use CoCreateInstance to get an interface to the control, and use the
various interfaces probably implemented by the control (IOleObject,
IOleControl etc.) to set a client site, activate the control etc. Your
client site should implement - among others - IOleWindow (ie. via
IOleInPlaceSite), and the control will take care of parenting itself
correctly.
What helped me a lot figuring out the steps was using CAxHostWindow, and
stepping through the code with the debugger to see what happens, and in
which order.
--
Volker
Also, I recommend you to read "Inside OLE" by Kraig Brockschmidt.
All of it, even though OLE Controls (the predecessors to ActiveX
Controls) are only in the last chapter... (specifically you need
chapters 17-24)
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnic...@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"MaiMee" <maime...@hotmail.com> wrote in message news:eBKjItaTCHA.2780@tkmsftngp09...
Thanks again.
Regards,
Maimee
P.S. I think you could make a tutorial webpage on what you did. I believe
there are a lot of people who would be interested: out of curiosity
and/or to implement in their
own programs.
"Inside OLE" by Kraig Brockschmidt, found in MSDN circa 1998, was a good
read, though I couldn't find complete
working examples of activex/ole control in a dialog box(and other window),
either in C or C++. Maybe the paper book had a CDROM where working examples
are stored? (Browsed through amazon.com, it said there is a cdrom for it,
but out of print).
Thanks again
Regards,
Maimee
"Alexander Nickolov" <agnic...@mvps.org> wrote in message
news:#arJnCfTCHA.3620@tkmsftngp08...
I've been working on a generic ActiveX control wrapper for the Qt toolkit,
and I'm afraid I can't make all of it available here, but the releveant
initialization part is below. It uses a very limited number of Qt specific
classes, but it should be translateable to generic HWND's etc. As Alexander
pointed out it's of course written in C++ (I was assuming your "C" was
referring to the Win32 API).
The only non-Qt header I have to include is olectl.h.
hr = CoCreateInstance( QUuid(widget->control()), 0, CLSCTX_SERVER,
IID_IUnknown, (void**)ppUnk );
bool bInited = hr == S_FALSE;
if ( !SUCCEEDED(hr) || !*ppUnk )
return;
hr = S_OK;
m_spOleObject = 0;
widget->queryInterface( IID_IOleObject, (void**)&m_spOleObject );
if (m_spOleObject) {
DWORD dwMiscStatus = 0;
m_spOleObject->GetMiscStatus( DVASPECT_CONTENT, &dwMiscStatus );
if( dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST )
m_spOleObject->SetClientSite( this );
if ( !bInited ) {
IPersistStreamInit *spPSI = 0;
m_spOleObject->QueryInterface( IID_IPersistStreamInit,
(void**)&spPSI );
if ( spPSI ) {
spPSI->InitNew();
spPSI->Release();
}
}
if( !(dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) )
m_spOleObject->SetClientSite( this );
IViewObject *spViewObject = 0;
m_spOleObject->QueryInterface(IID_IViewObject, (void**) &spViewObject);
m_spOleObject->Advise( this, &m_dwOleObject );
IAdviseSink *spAdviseSink = 0;
QueryInterface( IID_IAdviseSink, (void**)&spAdviseSink );
if ( spAdviseSink && spViewObject ) {
if ( spViewObject )
spViewObject->SetAdvise( DVASPECT_CONTENT, 0, spAdviseSink );
spAdviseSink->Release();
}
if ( spViewObject )
spViewObject->Release();
m_spOleObject->SetHostNames( OLESTR("AXWIN"), 0 );
QPaintDeviceMetrics pdm( widget );
if ( !(dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME) ) {
SIZEL hmSize;
hmSize.cx = MAP_PIX_TO_LOGHIM( 250, pdm.logicalDpiX() );
hmSize.cy = MAP_PIX_TO_LOGHIM( 250, pdm.logicalDpiY() );
m_spOleObject->SetExtent( DVASPECT_CONTENT, &hmSize );
m_spOleObject->GetExtent( DVASPECT_CONTENT, &hmSize );
sizehint.setWidth( MAP_LOGHIM_TO_PIX( hmSize.cx, pdm.logicalDpiX() ) );
sizehint.setHeight( MAP_LOGHIM_TO_PIX( hmSize.cy,
pdm.logicalDpiY() ) );
} else {
sizehint = QSize( 0, 0 );
}
if ( !(dwMiscStatus & OLEMISC_NOUIACTIVATE ) ) {
host->setFocusPolicy( QWidget::StrongFocus );
} else {
host->setFocusPolicy( QWidget::NoFocus );
}
RECT rcPos = { host->x(), host->y(),
host->x()+sizehint.width(), host->y()+sizehint.height() };
hr = m_spOleObject->DoVerb( OLEIVERB_INPLACEACTIVATE, 0,
(IOleClientSite*)this, 0, host->winId(), &rcPos );
m_spOleObject->QueryInterface( IID_IOleControl, (void**)&m_spOleControl );
if ( m_spOleControl ) {
m_spOleControl->OnAmbientPropertyChange( DISPID_AMBIENT_BACKCOLOR );
m_spOleControl->OnAmbientPropertyChange( DISPID_AMBIENT_FORECOLOR );
m_spOleControl->OnAmbientPropertyChange( DISPID_AMBIENT_FONT );
controlInfo.cb = sizeof(controlInfo);
m_spOleControl->GetControlInfo( &controlInfo );
}
BSTR userType;
m_spOleObject->GetUserType( USERCLASSTYPE_SHORT, &userType );
widget->setCaption( BSTRToQString( userType ) );
CoTaskMemFree( userType );
}
IObjectWithSite *spSite;
widget->queryInterface(IID_IObjectWithSite, (void**)&spSite);
if ( spSite ) {
spSite->SetSite( (IUnknown*)(IDispatch*)this );
spSite->Release();
}
The implementation of the client site interfaces is basically by the book,
and the whole control container implementation is about 1600 LOC, with a
good deal of it taking care of the Qt specifics.
--
Volker
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnic...@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"MaiMee" <maime...@hotmail.com> wrote in message news:O4wRnsnTCHA.384@tkmsftngp12...
What references (books,documents, etc.) did you used to write your
implementation?
With those references, did you employ little trial and error to implement a
"skeleton?"
Or it took much trial and error that during the coding you opted to go the
way of ATL/MFC?
Regards,
Maimee
"Volker Hilsheimer" <vo...@trolltech.com> wrote in message
news:#kvqLEoTCHA.4328@tkmsftngp09...
Regards,
Maimee
"Alexander Nickolov" <agnic...@mvps.org> wrote in message
news:uqKgkmrTCHA.3740@tkmsftngp08...
I've mainly relied on MSDN for the implementation details, and on "OLE
Controls Inside Out" by Adam Denning, which includes a helpful chapter about
the Microsoft specifications.
--
Volker
Regards,
Maimee
"Volker Hilsheimer" <vo...@trolltech.com> wrote in message
news:#m2RTL2TCHA.2928@tkmsftngp13...