开发者

sendmessage does not work

开发者 https://www.devze.com 2023-01-05 08:43 出处:网络
I try to sendmessage to an IE rebar/toolbar, but it seems that my toolbar does not take the message effect. Can someone tell me where is the fault ?

I try to sendmessage to an IE rebar/toolbar, but it seems that my toolbar does not take the message effect. Can someone tell me where is the fault ?

HRESULT CBut开发者_如何学PythontonDemoBHO::onDocumentComplete(IDispatch *pDisp, VARIANT *vUrl)     
{           
    m_hWnd = NULL;
    SHANDLE_PTR nBrowser = NULL;
    HRESULT hr = m_spWebBrowser2->get_HWND(&nBrowser);
    m_hWnd = (HWND)nBrowser;
    SendMessage(m_hWnd, WM_test, 0, 0);
    return S_OK;    
}


I would stronly recommned that you check the values of hr and m_hWnd and the return value of sendmessage(). I doubt that "Send message does not work", but am willing to believe "my message does not arrive". Are you sure that you are sending it to a valid destination?


You might want to wrap the call to SendMessage between SetLastError() and GetLastError(), like so...

SetLastError(0);
LRESULT rv = SendMessage(m_hWnd, WM_test, 0, 0);
DWORD errCode = GetLastError();
if(errCode != ERROR_SUCCESS) {
    // log error information here.
}

The return value from SendMessage depends on what WM_test returns from the handling function, so I would check the docs for that message too.

You can usually get a human-readable error message by passing the error code that GetLastError() returns as the dwMessageId parameter in FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ...).

FormatMessage docs.

0

精彩评论

暂无评论...
验证码 换一张
取 消