我想在Thread中的SendMessage或PostMessage函數的ATL DLL中獲取HWND。 但是,ATL DLL沒有窗口。如何獲取ATL DLL中的HWND(用於SendMessage或PostMessage)
如何在ATL DLL中獲取HWND?
項目應用程序設置:DLL(動態鏈接庫),安全開發生命週期( '不' 支持MFC)
Class選項:公寓,匯聚是,雙接口,連接點。
HelloCtrl.cpp
(VB客戶端處理ShowMessage())
STDMETHODIMP CHelloCtrl::ShowMessage(BSTR bstrCaption, VARIANT_BOOL* lpvbResult)
{
DWORD dwThreadID;
m_hThread_ReadData = CreateThread(NULL, 0, T_ReadData, (LPVOID)this, 0, &dwThreadID);
return S_OK;
}
DWORD WINAPI CHelloCtrl::T_ReadData(LPVOID pParam)
{
CHelloCtrl* hCtrl = (CHelloCtrl*) pParam;
::PostMessage(hCtrl->m_hWnd, WM_KEYDOWN, (WPARAM)NULL, (LPARAM)NULL);
return S_OK;
}
void CHelloCtrl::LeftButton()
{
Fire_OnMouseClick(123, 123);
}
HelloCtrl.h
#define WM_THREADFIREEVENT (WM_USER+1)
BEGIN_MSG_MAP(CHelloCtrl)
CHAIN_MSG_MAP(CComControl<CHelloCtrl>)
DEFAULT_REFLECTION_HANDLER()
MESSAGE_HANDLER(WM_THREADFIREEVENT, OnLeftButtonDown)
END_MSG_MAP()
public:
STDMETHOD(ShowMessage)(BSTR bstrCaption, VARIANT_BOOL* lpvbResult);
LRESULT OnLeftButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
void LeftButton();
private:
HANDLE m_hThread_ReadData;
static DWORD WINAPI T_ReadData(LPVOID pParam);
[MSDN](http://msdn.microsoft.com/en-us/library/aa979055(v = vs.71).aspx)如果它沒有窗口,則它沒有hWnd 。 – 2014-10-30 07:43:06