How do I determine the internal HWND used by COM in my current process?

故事扮演 提交于 2019-12-14 04:14:36

问题


I want to Post messages directly to the HWND that's owned by COM in my process. How do I get the HWND that COM is using in single-threaded-apartment mode?


回答1:


Try this:

HWND prevWindow = NULL;
HWND hwnd;
for ( ;; )
{
    hwnd = FindWindowEx( HWND_MESSAGE, prevWindow, L"OleMainThreadWndClass", NULL );
    if ( !hwnd )
        break;

    if ( GetWindowThreadProcessId( hwnd, NULL ) == GetCurrentThreadId() )
        break;

    prevWindow = hwnd;


    WCHAR className[255];
    *className = 0;
    ::GetClassName( hwnd, className, 255 );
}

Let me know if it works.



来源:https://stackoverflow.com/questions/45385193/how-do-i-determine-the-internal-hwnd-used-by-com-in-my-current-process

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!