Discussion:
TPanel descendant and arrow keys
(too old to reply)
JohnG
2008-06-25 15:55:33 UTC
Permalink
Hello

I am inheriting from a TPanel to create a container control
for other panels. I want the user to be able to move the
child panels using the arrow keys. I know that in a form
I can use the following code to accomplish this:

//header file
void __fastcall CMDialogKey(TMessage &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(CM_DIALOGKEY, TMessage, CMDialogKey)
END_MESSAGE_MAP(TForm)

//source
void __fastcall TForm1::CMDialogKey(TMessage &Msg)
{
switch(Msg.WParam)
{
case VK_LEFT:
case VK_UP:
case VK_RIGHT:
case VK_DOWN:
{
// do something
Msg.Result = false;
break;
}
default: TForm::Dispatch(&Msg);
}
}

However if I try something similar in my TPanel descendant,
the arrow keys are not trapped. Is there any way I can trap the
arrow key for the TPanel descendant directly?

Regards,

JohnG
Remy Lebeau (TeamB)
2008-06-25 16:35:55 UTC
Permalink
Post by JohnG
However if I try something similar in my TPanel descendant,
the arrow keys are not trapped. Is there any way I can
trap the arrow key for the TPanel descendant directly?
Your Panel needs to intercept the WM_GETDLGCODE message and return the
DLGC_WANTARROWS in reply.


Gambit
JohnG
2008-06-25 19:08:46 UTC
Permalink
Thanks Gambit.

I used the following and the OnKeyUp event of the panel

//header
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_GETDLGCODE, TMessage, WMGetDLGCode)
END_MESSAGE_MAP(TPanel)

//source
void __fastcall WMGetDLGCode(TMessage &Msg)
{
Msg.Result = DLGC_WANTARROWS;
}

If I can also ask:

Is it also possible for the event to be triggered repeatly if the user continues to keep the arrow key pressed?

JohnG
JohnG
2008-06-25 19:54:33 UTC
Permalink
Nevermind... Just use the OnKeyDown event!!!

Loading...