Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Doing direct Win32 API programming... before I post a bunch of code, I'll just ask the question and see if anyone has any quick ideas:

I create my main WS_OVERLAPPED window. During the WM_CREATE message, I create a WS_CHILD window. To differentiate between the two, I made the background color of the main window the APPWORKSPACE color and the child window simply white. Everything displays correctly. However, all of the WM_KEYUP and WM_KEYDOWN messages come in with the main window handle.

This problem goes away immediately if I change WM_CHILD to WM_POPUP. Of course, that doesn't really help since I specifically want a child window. But I think it at least shows that the general setup of my message processing is OK. I thought maybe it had something to do with creating the child during the parent WM_CREATE process, but I'm not sure what. I tried clicking in the child area to force focus, but the key messages are still dispatched to the parent.

Can anyone think of a reason that WS_CHILD would not receive WM_KEY* messages?
Posted
Updated 13-Dec-16 0:48am

Johny10151981: Interesting. I'll have to give that a try.

Mbue: WM_ACTIVATE had no effect, but setting the child focus from the parent WM_SETFOCUS message does seem to work for me:

HWND child = GetFirstChild( mHwnd );
if( child )
{
    SetFocus( child );
}

Thanks for the responses.
 
Share this answer
 
v2
Comments
mbue 10-Aug-11 11:01am    
I said:

LRESULT WndProc(HWND h,int m,WPARAM w,LPARAM l)
{
switch(m)
{
case WM_ACTIVATE:
if(w) SetFocus(GetWindow(h,GW_HWNDCHILD));
return 0;
}
return DefWindowProc(h,m,w,l);
}

Regards.
Call SetFocus(hChild); on WM_ACTIVATE or/and WM_MOUSEACTIVATE of the parent window.
Regards.
 
Share this answer
 
if you are looking for focus ON pressing tab two thing needed to be done
1. set style WM_TABSTOP
2. Use IsDialogMessage function to operate tabstop. here is an example:
C++
while(GetMessage(&msg,0,0,0))
{
 if(!IsDialogMessage(hwnd,&msg))
 {
  ..
  ..
  
 }
}
 
Share this answer
 
Because the main window gets the focus automatically on creation. It is then up to your application to set the focus to whatever child windows it chooses. In the case of a popup or dialog, that is treated the same as a main window.
 
Share this answer
 
If you use the WM_MOUSEMOVE , check current hWnd == old hWnd,
when current handle was change, set SetFourcs() with current hWnd.

-----

static HWND _CurHWnd = nullptr, _ZenHWnd = nullptr;

case WM_MOUSEMOVE:
_CurHWnd = hWnd;
if (_CurHWnd != _ZenHWnd) {
::SetFocus(_CurHWnd);
_ZenHWnd = _CurHWnd;
}
 
Share this answer
 
Comments
Richard MacCutchan 13-Dec-16 12:08pm    
This question was opened and answered 5 years ago! Why are you posting here?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900