|
// DDAxWindow.cpp: implementation of the CDDAxWindow class.
//
// Author : David Shepherd
// Copyright (c) 2003, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DDAxWindow.h"
#include "DDAxHostWindow.h"
/////////////////////////////////////////////////////////////////////////////
// CDDAxWindow
HRESULT CDDAxWindow::QueryHost(REFIID iid,void **ppUnknown)
{
IMP_BEGIN
// check parameters
if(ppUnknown==NULL)
{
throw CHResult(E_POINTER);
}
// initialise the interface pointer
*ppUnknown=NULL;
// get the host IUnknown interface
// todo : check the window is created and subclassed by the host if required
CComPtr<IUnknown> spUnknown;
HRESULT hr=AtlAxGetHost(*this,&spUnknown);
if(!SUCCEEDED(hr))
{
throw CHResult(hr);
}
// get the requested interface
hr=spUnknown->QueryInterface(iid,ppUnknown);
if(!SUCCEEDED(hr))
{
// a CHResult is not thrown here since QueryInterface can fail
// often and cause a lot of exception output in the debug window
return hr;
}
IMP_END
return RetVal;
}
HRESULT CDDAxWindow::QueryControl(REFIID iid,void **ppUnknown)
{
IMP_BEGIN
// check parameters
if(ppUnknown==NULL)
{
throw CHResult(E_POINTER);
}
// initialise the interface pointer
*ppUnknown=NULL;
// get the control IUnknown interface
// todo : check the window is created and subclassed by the host if required
CComPtr<IUnknown> spUnknown;
HRESULT hr=AtlAxGetControl(*this,&spUnknown);
if(!SUCCEEDED(hr))
{
throw CHResult(hr);
}
// get the requested interface
hr=spUnknown->QueryInterface(iid,ppUnknown);
if(!SUCCEEDED(hr))
{
// a CHResult is not thrown here since QueryInterface can fail
// often and cause a lot of exception output in the debug window
return hr;
}
IMP_END
return RetVal;
}
LRESULT CDDAxWindow::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
// the window text should not specify a control to create
TCHAR WindowText[16]=_T("");
ATLASSERT(GetWindowText(WindowText,NUM_ELEMENTS(WindowText,TCHAR))==0);
// initialise com
if(!SUCCEEDED(OleInitialize(NULL)))
{
throw std::exception();
}
// create the host
if(!SUCCEEDED(CDDAxHostWindow::_CreatorClass::CreateInstance(
NULL,__uuidof(IUnknown),(void**)&m_spHost)))
{
throw std::exception();
}
// get the host IAxWinHostWindow interface
CComQIPtr<IAxWinHostWindow> spAxWinHostWindow(m_spHost);
if(spAxWinHostWindow==NULL)
{
throw std::exception();
}
// initialise the host
if(!SUCCEEDED(spAxWinHostWindow->CreateControl(L"",*this,NULL)))
{
throw std::exception();
}
// ensure the control parent style is set
(void)ModifyStyleEx(0,WS_EX_CONTROLPARENT);
// allow default message processing
bHandled=FALSE;
CATCH_ALL
return Caught ? -1 : 0;
}
LRESULT CDDAxWindow::OnNCDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
TRY
// release the host
m_spHost=NULL;
// uninitialise com
OleUninitialize();
// allow default message processing
bHandled=FALSE;
CATCH_ALL
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.