I have a problem like this:
In MDI, there are several Child windows, they are opened when frame window created...
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...
....WinProc() //frame window proc...
char szBuf; // to hold activated child window name.
in message handler,
// get the active child window handle
hwndChild = (HWND)SendMessage (hwndClient, MDIGETACTIVE, 0, 0);
//get the active child window title name
//display the title name
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,
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().
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...
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?
hActiveWnd = (HWND)wParam;
// other code here
return(DefMDIWndProc(hwnd, Msg, wParam, lParam);