Thread: Child window cant receive keyboard inputs

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    133

    Child window cant receive keyboard inputs

    I have a parent window of this style:
    WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX

    then i have a child window of this style:
    WS_CHILD | WS_VISIBLE

    I want my child window to be able to handle keyboard msg. However, it is always the parent window that receives the WM_KEYDOWN msg.

    I tried using SetFocus(). It didnt work.

    Can someone tell me what should i do? Thanks alot!

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Here's what i do, i don't know if it's correct though:

    Mainform:
    Code:
    Stack<HWND> *ws;
    
    
    case WM_SETFOCUS:
    	BringWindowToTop(ws->GetTop());
    	SetActiveWindow(ws->GetTop());
    	break;
    case WM_CREATE:	// Init event
    	//Create, and push HWND to stack
    	ws = new Stack<HWND>(hwnd);
    Childform:
    Code:
    case WM_SETFOCUS:
    	BringWindowToTop(ws->GetTop());
    	SetFocus(ws->GetTop());
    	break;
    case WM_CREATE:	// Init event
    	ws->Push(tp[WND]);
    case WM_DESTROY:
    	ws->Pop();
    	SetFocus(ws->GetTop());
    The stack is a class i created on my own. The GetTop() function returns the handle of the last window pushed to the stack.
    In this way, whatever window receives focus, it will call SetFocus() for the correct window.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    133
    Thanks for the help. Your suggestion solved my problem. It took me a while to understand ur code. I managed to avoid the use of the stack ADT by storing the handle of the child window. Then I call SetFocus() on the child window each time the parent receives WM_SETFOCUS msg.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Taskbars; 'Cannot create top level child window'
    By Gerread in forum Windows Programming
    Replies: 4
    Last Post: 05-18-2007, 06:41 AM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM