How do I determine the internal HWND used by COM i

2019-09-22 19:09发布

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?

标签: c winapi com hwnd sta
1条回答
老娘就宠你
2楼-- · 2019-09-22 19:37

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.

查看更多
登录 后发表回答