If I'm using a resource file with a dialog with the UI I designed (all the controls; edit boxes, buttons, etc.) and from the winmain(...) I called the dialog with a return which handles it on a BOOL DlgProc(...) function, eveything works swiftly but I have a question. How do I get input from the keyboard to be recognized on this dialog? WM_KEYDOWN and WM_CHAR don't work on a dialog window, though they work perfectly if it is a normal window. Say I wanted the keys F1, F2, 'a', 's', enter, and ESC to be recognized it just doesn't. Delving a little in the win32 Borland help file it seems that this stuff is dependant on the DefWindow...(...) stuff function that gets returned on a normal window WinProc(...), but since a dialog works differently I suppose that's why it doesn't work. I know that 'enter' and 'tab' and 'esc' might have trouble working on a dialog since dialogs have these already built in for specific messages like IDOK, IDCANCEL, and tabbing between controls, but what about any other key?
How do I something like this on a dialog?
case WM_KEYDOWN:
switch(wParam)
{
case VK_F1:
MessageBox(NULL, "pressed F1", "KeyPressed F1", MB_OK);
break;
case VK_A:
MessageBox(NULL, "pressed A", "KeyPressed F1", MB_OK);
break;
}
break;
or something like...
case WM_CHAR:
switch(TCHAR(lParam)) //or wParam don't remember
{
case 'a':
//the same message box
break;
}
break;
P.D. Oh, also a technical question, MinGW doesn't seem to have VK_A or any of the other keyboard keys in <winuser.h>, you have to add them manually if you want to use them like "#define VK_A 0x41" why is that?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your switch statement has to be in the dialog procedure for the dialog box, not in the main window procedure. If it is a modal dialog box you also have to modify the WinMain procedure.
Also, do a search of your borland .h files and see where the VK_* keys are defined.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The switch, IS on the BOOL dlgproc(...), it is a resource file containing the dialog which I call by a return from the winmain. I'm using DevC++ (MinGW) not Borland. And VK_* keys are defined on <winuser.h> as hexadecimal values. As I said, WM_KEYDOWN & WM_CHAR work if it were a normal window, but since it is a dialog they don't seem to work and I suspect they are dependant on the DefWindow...(...) function, so is there a way to get input on a dialog???
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If I'm using a resource file with a dialog with the UI I designed (all the controls; edit boxes, buttons, etc.) and from the winmain(...) I called the dialog with a return which handles it on a BOOL DlgProc(...) function, eveything works swiftly but I have a question. How do I get input from the keyboard to be recognized on this dialog? WM_KEYDOWN and WM_CHAR don't work on a dialog window, though they work perfectly if it is a normal window. Say I wanted the keys F1, F2, 'a', 's', enter, and ESC to be recognized it just doesn't. Delving a little in the win32 Borland help file it seems that this stuff is dependant on the DefWindow...(...) stuff function that gets returned on a normal window WinProc(...), but since a dialog works differently I suppose that's why it doesn't work. I know that 'enter' and 'tab' and 'esc' might have trouble working on a dialog since dialogs have these already built in for specific messages like IDOK, IDCANCEL, and tabbing between controls, but what about any other key?
How do I something like this on a dialog?
case WM_KEYDOWN:
switch(wParam)
{
case VK_F1:
MessageBox(NULL, "pressed F1", "KeyPressed F1", MB_OK);
break;
case VK_A:
MessageBox(NULL, "pressed A", "KeyPressed F1", MB_OK);
break;
}
break;
or something like...
case WM_CHAR:
switch(TCHAR(lParam)) //or wParam don't remember
{
case 'a':
//the same message box
break;
}
break;
P.D. Oh, also a technical question, MinGW doesn't seem to have VK_A or any of the other keyboard keys in <winuser.h>, you have to add them manually if you want to use them like "#define VK_A 0x41" why is that?
Does then dialog proc look something like this? If it is not too long you should post your dialog proc code.
BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM)
{
switch (iMsg)
{
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDOK :
EndDialog (hDlg, 0);
return TRUE;
}
break ;
}
return FALSE ;
}
Check the following.
Your switch statement has to be in the dialog procedure for the dialog box, not in the main window procedure. If it is a modal dialog box you also have to modify the WinMain procedure.
Also, do a search of your borland .h files and see where the VK_* keys are defined.
The switch, IS on the BOOL dlgproc(...), it is a resource file containing the dialog which I call by a return from the winmain. I'm using DevC++ (MinGW) not Borland. And VK_* keys are defined on <winuser.h> as hexadecimal values. As I said, WM_KEYDOWN & WM_CHAR work if it were a normal window, but since it is a dialog they don't seem to work and I suspect they are dependant on the DefWindow...(...) function, so is there a way to get input on a dialog???