Archived

This topic is now archived and is closed to further replies.

Catch key press in dialog boxes

This topic is 5799 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im doing some help stuff for a big project and I have a big problem…im not to good with windows API programming and I hope that someone here can help me. I want to be able to press “F1” and depending on which dialog window(or main) that is open I want to show different part of the help file…for example if the a search dialog is open(in focus) and I press F1 I want the help on “Search” to show up. The problem is that if I put a WM_KEYDOWN in the “SearchProc” nothing happens..it doesn’t register the key press…It only works on the “MainWinProc”…when the MainWindow is on focus that is. I searched the web and found out the it was a problem with WM_KEYDOWN and other messages in a dialogprocedure and that you could use a virtual function PreTranslateMessage...but that only works if you use classes I guess and the people who wrote this program doesn’t use classes. Does anyone know how I can catch a key press(F1) in a dialog without using classes… I would really appreciate if someone could help me with this. Edited by - S_Z on January 29, 2002 5:27:48 PM

Share this post


Link to post
Share on other sites
I have been working all day on this and I still haven’t found a good solution

Im using IsDialogMessage like this:
if (!IsWindow(hDlg) || !IsDialogMessage(hDlg, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

I have made a little test program with a main window and a dialogbox with 2 buttons and editbox.
I have a WinProc and a DialogProc. Getting a WM_KEYDOWN message in the WinProc when the main window is in focus is no problem but as I said before when the dialog box is in focus you never get a WM_KEYDOWN.
I read that you could make a subclassproc(so that the edit box key get its own proc for example) and then in this
EditSubclassProc you will get a WM_GETDLGCODE and then you get that message you return DLGC_WANTALLKEYS.
Now you will get a WM_KEYDOWN when the Edit box in the dialog is in focus.
I thought I could do so for every control (Editbox, OK and Cancel button) but I couldn’t get that to work…it only worked with one of the controls

Should it be that hard to be able to trap an F1 keypress in a dialog window??
Please...does anyone know a different way to solve this or could tell me what im doing wrong…
I cant use MFC or any classes because this it's a big project and the people who wrote it doesn’t use classes or MFC.


Edited by - S_Z on January 30, 2002 2:31:18 PM

Share this post


Link to post
Share on other sites