Thread: Wm_mdigetactive??

  1. #1
    Registered User
    Join Date
    Sep 2001



    I have a problem like this:

    In MDI, there are several Child windows, they are opened when frame window created...

    ....WinProc() //frame window proc...
    char szBuf[20]; // to hold activated child window name.
    HWND hwndChild;
    in message handler, 
    switch (mMsg)
    // get the active child window handle
    hwndChild = (HWND)SendMessage (hwndClient,     MDIGETACTIVE, 0, 0);
    //get the active child window title name
    GetW indowText(hwndChild,szBuf,20);
    //display the title name
    MessageBox(0,szBuf,"window title",MB_OK);
    it pops up the message only when I click the submenu item, but it always give the previous active child window title name... I don't how to solve that...

    And how can I get the active child window name only by clicking the child window, not from submenu item??

    I want to get the active Child window's title name when I simply click one child window,
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Your code is probably running before the child window becomes active. That's why you're getting the "previous" active child.

    Try running your code after DefWindowProc().


  3. #3
    Registered User
    Join Date
    May 2002
    You could also try to place your code above the switch(Msg) line thus you always get the active window, however, this leads to other problems incase you receive a WM_SETFOCUS or WM_KILLFOCUS message in which case your "active window" code would be wrong.

    Why not just inside of a WM_KILLFOCUS message, wParam holds the handle to the window receiving the focus. Thus just set it as so...

    case WM_KILLFOCUS:
            hActiveWnd = (HWND)wParam;
            // other code here
            return(DefMDIWndProc(hwnd, Msg, wParam, lParam);
    that way you always get the active window, and you don't have to reset a variable (even when not needed) everytime a message comes in?

Popular pages Recent additions subscribe to a feed