mr MFC please do something when I press a key
-
hello I am making a program in MFC I have a class for a window I want to achieve this: when a key is pressed something happens. To achieve this I did this I went to class view I right clicked on my class and clicked on propreties I clciked on messages I selected WM_KEYDOWN and from the right column I selected Add OnKeyDown this created a new function: void CViewListaLocatari::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { MessageBox("toader","toader",MB_OK); if (nChar==VK_DELETE) OnBnSterge(); else CFormView::OnKeyUp(nChar, nRepCnt, nFlags); CFormView::OnKeyDown(nChar, nRepCnt, nFlags); } and this line appeared in the message map ON_WM_KEYDOWN() I changed it to this ON_WM_KEYDOWN(WM_KEYDOWN,OnKeyDown) because it made more sense for it to be like that although I don't know if I did right anyway it doesn't work and no messagebox appears even how do I make it work? or do you know another way to do this?
-
hello I am making a program in MFC I have a class for a window I want to achieve this: when a key is pressed something happens. To achieve this I did this I went to class view I right clicked on my class and clicked on propreties I clciked on messages I selected WM_KEYDOWN and from the right column I selected Add OnKeyDown this created a new function: void CViewListaLocatari::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { MessageBox("toader","toader",MB_OK); if (nChar==VK_DELETE) OnBnSterge(); else CFormView::OnKeyUp(nChar, nRepCnt, nFlags); CFormView::OnKeyDown(nChar, nRepCnt, nFlags); } and this line appeared in the message map ON_WM_KEYDOWN() I changed it to this ON_WM_KEYDOWN(WM_KEYDOWN,OnKeyDown) because it made more sense for it to be like that although I don't know if I did right anyway it doesn't work and no messagebox appears even how do I make it work? or do you know another way to do this?
First -- don't screw around with the code that ClassWizard writes unles you know what you are doing. Change it back the way it was. WM_KEYDOWN events are not handled by CDialog-derived classes. You have to use PreTranslateMessage() to capture the key events. Key events always go to the window that has focus.
-
hello I am making a program in MFC I have a class for a window I want to achieve this: when a key is pressed something happens. To achieve this I did this I went to class view I right clicked on my class and clicked on propreties I clciked on messages I selected WM_KEYDOWN and from the right column I selected Add OnKeyDown this created a new function: void CViewListaLocatari::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { MessageBox("toader","toader",MB_OK); if (nChar==VK_DELETE) OnBnSterge(); else CFormView::OnKeyUp(nChar, nRepCnt, nFlags); CFormView::OnKeyDown(nChar, nRepCnt, nFlags); } and this line appeared in the message map ON_WM_KEYDOWN() I changed it to this ON_WM_KEYDOWN(WM_KEYDOWN,OnKeyDown) because it made more sense for it to be like that although I don't know if I did right anyway it doesn't work and no messagebox appears even how do I make it work? or do you know another way to do this?
-
First -- don't screw around with the code that ClassWizard writes unles you know what you are doing. Change it back the way it was. WM_KEYDOWN events are not handled by CDialog-derived classes. You have to use PreTranslateMessage() to capture the key events. Key events always go to the window that has focus.
Thank you. It works fine.
-
First -- don't screw around with the code that ClassWizard writes unles you know what you are doing. Change it back the way it was. WM_KEYDOWN events are not handled by CDialog-derived classes. You have to use PreTranslateMessage() to capture the key events. Key events always go to the window that has focus.
can you please elaborate on this PreTranslateMessage() where exactly should I put this ? It is not a method that I can use can you please explain more please
-
Rick York wrote: Have you tried catching WM_CHAR ? doesn't work