Hello,

I don't mean to double post, however I was just wondering if it is because I
am not subclassing my child window that the following program doesn't work?

Here is the problem:

I realized that the WM_KEYDOWN handler did not pick up my keystrokes on my
child window.

I have a WM_KEYDOWN handler in my main window, and when I press say F1 key,
I can trap it with a break point, but when I am in my second window, which is
a 2nd WindProc, I cannot trap the WM_KEYDOWN messages.

here is the basic code:
===================================WndProc.CPP
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
...other code...

switch(message)
{
case WM_KEYDOWN:

switch(wParam) //**********Break point recognized at debug time
{
case VK_F2:
ShowWindow(hdCW1,SW_HIDE);
break;
}
return 0;
case WM_COMMAND:

if (LOWORD(wParam) == WindowButtons[1].MW_btC_ID) //If Button #1
{
hdCW1 = CreateWindow( //Create Child window #1
szCW1_ClassName,szCW1_Name,
WS_CHILD | WS_CAPTION | WS_SYSMENU,
150,50,400,300,hwnd,(HMENU)CW1_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);

ShowWindow(hdCW1,SW_SHOW); //Show child window #1
}
return 0;

...other code....
===============================================

And here is the code pertaining to the child window, pressing F1 key does
not get trapped by break point in this winproc?
===================================WndProc_CW1.CPP
LRESULT CALLBACK WndProc_CW1 (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{

...other code...

case WM_KEYDOWN:
switch (wParam) //Break point here! Break point NOT recognized at debug time
{
case 0: //Dummy case
break;
}
return 0;

...other code....
=================================================

Its like as if when I am in the child window and I press say F1 key, the
WM_KEYDOWN message is not sent, and even if I have a break point on the
following line:

switch (wParam)

debug doesn't stop on that line, it goes right through as if I had no break
point ????

So, again... can this be because I should use WM_KEYDOWN in a subclassing
proc?

If anyone has any ideas, please get back!

All help appreciated!

Thanks

--
Best regards
Robert

Re: Is it because of SubClassing? by John

John
Sat Jun 24 01:04:05 CDT 2006

Subclassing is only relevant for overriding window procedures written by
someone else; it has no relevance for window procedures that you are free to
author as you see fit.

For a window to receive keyboard input, it must have the keyboard focus. You
probably assume that this happens automatically when a window is clicked
because clicking on Windows controls always seems to give them the focus.
However, it does not happen automatically. You need to call the SetFocus
function in response to mouseclicks (which is what the Windows controls do).

--
John Carson





Re: Is it because of SubClassing? by Robby

Robby
Sat Jun 24 12:44:01 CDT 2006

Hey John!

You were 100% right! I did need to setfocus on the current window....

--
Best regards
Robert


"John Carson" wrote:

> Subclassing is only relevant for overriding window procedures written by
> someone else; it has no relevance for window procedures that you are free to
> author as you see fit.
>
> For a window to receive keyboard input, it must have the keyboard focus. You
> probably assume that this happens automatically when a window is clicked
> because clicking on Windows controls always seems to give them the focus.
> However, it does not happen automatically. You need to call the SetFocus
> function in response to mouseclicks (which is what the Windows controls do).
>
> --
> John Carson
>
>
>
>
>