How do I determine the internal HWND used by COM i

2019-09-22 18:59发布

问题:

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.



标签: c winapi com hwnd sta