OnChar() in Dialog
-
I have a problem with mapping keys to buttons on the dialog. I tried by catching WM_CHAR message like this void CDialogbasedDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { switch(nChar) { case '1': //do sth break; //... } CDialog::OnChar(nChar, nRepCnt, nFlags); } but it didn't work. The application just beeps when I press '1'.
-
I have a problem with mapping keys to buttons on the dialog. I tried by catching WM_CHAR message like this void CDialogbasedDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { switch(nChar) { case '1': //do sth break; //... } CDialog::OnChar(nChar, nRepCnt, nFlags); } but it didn't work. The application just beeps when I press '1'.
Does the dialog have keyboard focus ? Did you set a breakpoint ? Your code WILL do nothing when a '1' is pressed. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Does the dialog have keyboard focus ? Did you set a breakpoint ? Your code WILL do nothing when a '1' is pressed. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
I put SetFocus() in OnInitDialog(), but I don't know anything about setting a breakpoint. Could you please, just in a few steps, explain me what I need to do?
You shouldn't have to call SetFocus, try removing it. A breakpoint is set with F9 ( from memory ), it's a little black circle on the left of your code. Then if you're in debug mode, when you run your program and it gets to the point where the circle is, it will stop and you can examine the state of memory/variables/etc. and step through code. The point here would just be to see if the code is being reached. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
You shouldn't have to call SetFocus, try removing it. A breakpoint is set with F9 ( from memory ), it's a little black circle on the left of your code. Then if you're in debug mode, when you run your program and it gets to the point where the circle is, it will stop and you can examine the state of memory/variables/etc. and step through code. The point here would just be to see if the code is being reached. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
Ok I see what you mean. I know what debugging breakpoint is. I thought you ment it was some kind of a function or something similar. It doesn't work though. The code doesn't get executed. I did manage, however, to trap keysrokes with PreTranslateMessage() like this
BOOL CDialogbasedDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_CHAR) { switch(pMsg->wParam) { case '1': // do sth break; case '2': // do sth break; //.... } return TRUE; } else return CDialog::PreTranslateMessage(pMsg); }
and it works. But I guess this is not how it should be done. Is there a better way of trapping keystrokes in dialog? -
Ok I see what you mean. I know what debugging breakpoint is. I thought you ment it was some kind of a function or something similar. It doesn't work though. The code doesn't get executed. I did manage, however, to trap keysrokes with PreTranslateMessage() like this
BOOL CDialogbasedDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_CHAR) { switch(pMsg->wParam) { case '1': // do sth break; case '2': // do sth break; //.... } return TRUE; } else return CDialog::PreTranslateMessage(pMsg); }
and it works. But I guess this is not how it should be done. Is there a better way of trapping keystrokes in dialog?This plainly means that the message is not getting through to your onChar handler. The question is, why ? Did you remove the SetFocus call ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
This plainly means that the message is not getting through to your onChar handler. The question is, why ? Did you remove the SetFocus call ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder