locked
SetParent()

    Question

  • Any idea how to correctly use of SetParent() to make a window of my process a child window of another process?

    What I am trying to achieve is make a HUD application for poker. So my app has to display user stats on top of the poker app window.

    What I do is:

    fhWnd = FindWindow(_T("Notepad"), NULL);
    
     hWnd = CreateWindowEx(WS_EX_TOPMOST , _T("test"), _T("test"),
            WS_POPUP,
            20, 20, 400, 400, NULL, NULL, hInst, NULL);
    
     SetParent(hWnd, fhWnd);
    
     DWORD style = GetWindowLong(hWnd, GWL_STYLE);
     style = style & ~(WS_POPUP);
     style = style | WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
     SetWindowLong(hWnd, GWL_STYLE, style);
     SetWindowLong(fhWnd, GWL_STYLE, GetWindowLong(fhWnd, GWL_STYLE) | WS_CLIPCHILDREN);

    However in order to see what I drawn in my window I have to move the parent window out of the screen and back in again.

    Any ideas how to do this right?


    • Edited by Stav_9 Wednesday, December 26, 2012 6:20 AM
    Wednesday, December 26, 2012 6:10 AM

Answers

  • Hello Stav_9,

    Welcome to MSDN forum.

    According to your description, the child window did not repaint (because the child window area is not refreshed). When you move the child window, a WM_PAINT message is sent to the window and it will be repainted. Any change of the window's client area(resizing, moving) will trigger a WM_PAINT message.

    To refresh the window's update region, you can use InvalidateRect function or InvalidateRgn. They can indirectly generate WM_PAINT messages for a window by marking all or part of a client area as invalid (that must be redrawn).

    You can refer to: Invalidating the Client Area

    Thanks,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 27, 2012 10:51 AM
    Moderator