How can I tell if window creation process is complete with Window Handle(HWND)?

0

Hello, Thanks a lot for reading this question.

I am currently building a program which captures creation/termination of windows.

Gratefully, I have managed to implement WinEvents and SetWinEventHook to capture Window creation / modification / termination events.

Following is my code.

if (idObject == OBJID_WINDOW)
{
    BOOL isWin = IsWindow(hwnd);
    if (event == EVENT_OBJECT_CREATE && isWin)
    {
        LONG style;
        LONG EXstyle;

        style = GetWindowLong(hwnd, GWL_STYLE);
        EXstyle = GetWindowLong(hwnd, GWL_EXSTYLE);

        if (((style & WS_SYSMENU || style & WS_POPUPWINDOW) && style & WS_VISIBLE) && !(EXstyle & 0x000000a0) && (EXstyle & WS_TABSTOP || EXstyle & WS_EX_WINDOWEDGE || EXstyle & WS_EX_STATICEDGE || EXstyle & WS_EX_CLIENTEDGE || EXstyle & WS_EX_LAYERED))
        {
            AddHandleToMap(hwnd);
            printVector();
        }
    }

However in callback method, If I don't use Sleep(200~1000) program does not work properly.

I guess this is because I get Window style, EXstyle before the window is completely created.

Therefore, I am looking for a solution which can let my function wait until window is fully created.

If anyone knows the method, please share with me.

Again, Thanks a lot for reading this question.

windows
visual-c++
mfc
asked on Stack Overflow Jul 8, 2020 by Kigael Lee • edited Jul 8, 2020 by Andrew Truckle

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0