From: Crispen, Bob (bob.crispen_at_boeing.com)
Date: 27 February 2003
Subject: Re: Keypress functionality in a dialog
Date: Mon, 03 Feb 2003 16:07:30 +0100
From: Lucian Wischik <lu.nn_at_wischik.com>
Organization: University of Bologna
Newsgroups: comp.os.ms-windows.programmer.win32
"Espen Ruud Schultz" <default_at_nospam.invalid> wrote:
>I have a simple modeless dialog where I need some global keypress
>functionality. It seems like a simple WM_KEYDOWN is not enough to detect
>keypresses in a dialog. I also think that my main loop isn't correct for
>handling dialogs. Any help about anything with my code is appreciated...
>while( GetMessage( &msg, NULL, 0, 0 ) > 0 ) {
> TranslateMessage( &msg );
> DispatchMessage( &msg );
>}
I had to do exactly the same thing. I did it with an accelerator table, since it seemed easiest. (Also, your messageloop should have IsDialogMessage). Here's my loop:
MSG msg;
while (GetMessage(&msg,NULL,0,0) && fd.QuitForm==0)
{ BOOL handled = TranslateAccelerator(hform,haccf,&msg);
if (!handled) handled = IsDialogMessage(hform,&msg);
if (!handled)
{ TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Then I handle the global keypresses just as normal accelerators - i.e. through WM_COMMAND.
-- Lucian
This archive was generated by hypermail pre-2.1.8 : 26 April 2003 EDT