Com 如何获取无窗口ATL控件的HWND?
我创建了一个ATL windows less控件,类定义如下:Com 如何获取无窗口ATL控件的HWND?,com,activex,atl,Com,Activex,Atl,我创建了一个ATL windows less控件,类定义如下: class ATL_NO_VTABLE CRSPClient : public IObjectSafetyImpl<CRSPClient, INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA>, public CComObjectRootEx<CComSingleThreadModel>, pu
class ATL_NO_VTABLE CRSPClient :
public IObjectSafetyImpl<CRSPClient, INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA>,
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<IRSPClient, &IID_IRSPClient, &LIBID_axBanckleRSPClientLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
public IPersistStreamInitImpl<CRSPClient>,
public IOleControlImpl<CRSPClient>,
public IOleObjectImpl<CRSPClient>,
public IOleInPlaceActiveObjectImpl<CRSPClient>,
public IQuickActivateImpl<CRSPClient>,
public IViewObjectExImpl<CRSPClient>,
public IOleInPlaceObjectWindowlessImpl<CRSPClient>,
#ifdef _WIN32_WCE // IObjectSafety is required on Windows CE for the control to be loaded correctly
public IObjectSafetyImpl<CRSPClient, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
#endif
public CComCoClass<CRSPClient, &CLSID_RSPClient>,
public CComControl<CRSPClient>
class ATL\u NO\u VTABLE CRSP客户端:
公共IObjectSafetyImpl,
公共CComObjectRootEx,
公共场所,
公共IPersistStreamInImpl,
公共经济控制,
公共IOleObjectImpl,
公共IOleInPlaceActiveObjectImpl,
公共IquickaActivateImpl,
公共IViewObjectExImpl,
公共IOleInPlaceObjectWindowlessImpl,
#要正确加载控件,Windows CE上需要ifdef _WIN32_WCE//IObjectSafety
公共IObjectSafetyImpl,
#恩迪夫
公共课程,
公共控制
然后出于某种目的,我需要将消息发布到窗口。我尝试了很多方法来控制窗口,但都失败了:
HWND CRSPClient::GetHwnd()
{
HWND hwndRet = NULL;
// hwndRet = m_hWnd;
//IOleInPlaceActiveObjectImpl<CRSPClient>::GetWindow(&hwndRet);
//IOleWindow<CRSPClient>::GetWindow(&hwndRet);
//this->m_spInPlaceSite->GetWindow(&hwndRet);
//CComQIPtr<IOleInPlaceSite> spSite = this->m_spClientSite;
//spSite->GetWindow(&hwndRet);
//hwndRet = ::WindowFromDC(GetDC());
return hwndRet;
}
HWND CRSPClient::GetHwnd()
{
HWND hwndRet=NULL;
//hwndRet=m_hWnd;
//IOleInPlaceActiveObjectImpl::GetWindow(&HwnRet);
//IOleWindow::GetWindow(&hwndRet);
//此->m_spInPlaceSite->GetWindow(&HwnRet);
//CComQIPtr spSite=this->m_spClientSite;
//spSite->GetWindow(&hwnret);
//hwndRet=::WindowFromDC(GetDC());
返回hwndRet;
}
有人知道有什么办法可以拿到HWND吗
天哪,我对微软伟大的ATL框架感到非常失望 以下是一些取自Microsoft Direct3D ATL示例的代码。我还没有测试过
// Get the window we need to use. This will either be the window that has already
// been created if we are window. If we are windowless the HWND of the client
// will be retrieved from the HDC.
void GetOurWindow()
{
// If we're windowless we still need an HWND for Direct3d
if (m_bWndLess)
{
HDC hDC;
// Get the HDC from the client
m_spInPlaceSite->GetDC(NULL, OLEDC_NODRAW, &hDC);
m_hOurWnd = WindowFromDC(hDC);
#if 1
// Code to make VB5 paint properly now it has clipped it's own hDC
RECT rect;
::GetClientRect(m_hOurWnd,&rect);
HRGN hRegion = CreateRectRgn(rect.left,rect.top,rect.right,rect.bottom);
SelectClipRgn(hDC,hRegion);
#endif
m_spInPlaceSite->ReleaseDC(hDC);
}
else
m_hOurWnd = m_hWnd;
}
下面是一些来自微软Direct3D ATL示例的代码。我还没有测试过
// Get the window we need to use. This will either be the window that has already
// been created if we are window. If we are windowless the HWND of the client
// will be retrieved from the HDC.
void GetOurWindow()
{
// If we're windowless we still need an HWND for Direct3d
if (m_bWndLess)
{
HDC hDC;
// Get the HDC from the client
m_spInPlaceSite->GetDC(NULL, OLEDC_NODRAW, &hDC);
m_hOurWnd = WindowFromDC(hDC);
#if 1
// Code to make VB5 paint properly now it has clipped it's own hDC
RECT rect;
::GetClientRect(m_hOurWnd,&rect);
HRGN hRegion = CreateRectRgn(rect.left,rect.top,rect.right,rect.bottom);
SelectClipRgn(hDC,hRegion);
#endif
m_spInPlaceSite->ReleaseDC(hDC);
}
else
m_hOurWnd = m_hWnd;
}
无窗口控件的全部要点是,它在没有窗口句柄的情况下工作。如果您想使用窗口句柄,以防它存在并且控件返回到窗口模式,那么很容易: 否则,您必须有一个窗口,然后您必须在构造函数中标记并指示您将需要一个
HWND
:
指示控件应打开窗口的标志,即使容器支持无窗口控件
如果您仍然希望它是无窗口的,并且有时需要一个窗口,在运行时出现的特定条件下,您总是可以选择创建一个私有窗口并通过它发送消息。无窗口控件的全部要点是它在没有窗口句柄的情况下工作。如果您想使用窗口句柄,以防它存在并且控件返回到窗口模式,那么很容易: 否则,您必须有一个窗口,然后您必须在构造函数中标记并指示您将需要一个
HWND
:
指示控件应打开窗口的标志,即使容器支持无窗口控件
如果您仍然希望它是无窗口的,并且有时需要一个窗口,在运行时出现的特定条件下,您总是可以选择创建一个私有窗口并通过它发送消息