|
You need to handle PreTranslateMessage() instead.
|
|
|
|
|
two ways (that I know):
1. subclass the first control and handle the WM_SETFOCUS.
2. PreTranslateMessage in the dialog and handle the WM_SETFOCUS...
Hope this helps.
-- modified at 3:02 Wednesday 2nd May, 2007
Oooops! I've made a mistake... SEND WM_SetFocus (if needed) and HANDLE WM_KEYDOWN... in the pretranslatemessage.
|
|
|
|
|
Joan Murt wrote: 1. subclass the first control and handle the WM_SETFOCUS.
But what if there are plenty of controls? And the user may click on anything, any time; thus setting the focus on a random control.
Joan Murt wrote: 2. PreTranslateMessage in the dialog and handle the WM_SETFOCUS...
Why to handle WM_SETFOCUS within the PreTranslateMessage() ? Won't you rather be handling the key strokes within PreTranslateMessage() ? I know the OP asked how to set focus to the dialog. If you were to suggest him something for that reason, fine. Otherwise I think handling the key strokes directly is straight forward.
|
|
|
|
|
Oooops! my mistake... SEND WM_SetFocus and HANDLE WM_KEYDOWN...
thank you I'll modify it immediately...
|
|
|
|
|
Handling WM_KEYDOWN in PreTranslateMessage() will suffice. No need to do anything with WM_SETFOCUS
|
|
|
|
|
PreTranslateMessage() in the dialog will catch keystroke messages that go to a control??
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: keystroke messages that go to a control
That message has to go through PreTranslateMessage() and so, the answer is yes. Just give it a try.
|
|
|
|
|
Cool! I did try it.
Do you know off hand if it is MFC that forwards them to the parent or is it the system?
I dug a bit in MFC but didn't find where it was occurring - I didn't spend too much time on it
Just 'cuz I like to know these things!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: Do you know off hand if it is MFC that forwards them to the parent or is it the system?
I don't get that question. By stating "System", do you mean the OS? Can you please rephrase that? If you have to really dig this stuff out, check out "thrdcore.cpp".
Shog on learning VB6: Ah, that would have been VB6. Kicked my ass anyway. So easy to learn, just like falling down a flight of stairs...
|
|
|
|
|
Yes I meant the OS.
So, I looked again and found it right away LOL.
I had no idea PreTranslateMessage calls walked up the window heirarchy to the main window (not
that I ever came across a situation where it mattered until this discussion thread ).
Apparently it's for keyboard accelerator handling.
Ya learn something new everyday!
I wonder if this adds a danger to the misuse of PreTranslateMessage I see often on the message
boards...
Thank you so much!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: Apparently it's for keyboard accelerator handling.
Read this[^]
Mark Salsbery wrote: I wonder if this adds a danger to the misuse of PreTranslateMessage I see often on the message
boards...
PreTranslateMessage is one thing that is excessively misused.
Shog on learning VB6: Ah, that would have been VB6. Kicked my ass anyway. So easy to learn, just like falling down a flight of stairs...
|
|
|
|
|
brahmma wrote: PreTranslateMessage is one thing that is excessively misused.
Indeed!
Thanks for the link...bookmarked for future reference!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: Thanks for the link...bookmarked for future reference!
Glad that I could be of some help.
Shog on learning VB6: Ah, that would have been VB6. Kicked my ass anyway. So easy to learn, just like falling down a flight of stairs...
|
|
|
|
|
Hi,
First,Thanks for your (very) quick reply.
My problem is that I've overrided the PreTranslateMessage method,
and put a breakpoint in that function but I never get to that breakpoint.
However , when I move the focus to one of the controls(for example editbox),
the focused control gets the keyboard events...
Is it possible that the controls receives keyboard events but the parent window does'nt????
Thanks again,
With best regards,
Eli
|
|
|
|
|
eli15021979 wrote: I've overrided the PreTranslateMessage method,
and put a breakpoint in that function but I never get to that breakpoint.
Can you please post that code here?
|
|
|
|
|
You may try this...
BOOL CXDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN)
AfxMessageBox("ll");
return CDialog::PreTranslateMessage(pMsg);
}
Barna
|
|
|
|
|
|
send me your mobile number then I'll text message the code to you!
|
|
|
|
|
paras_s12 wrote: now i want code for this
You're obviously thinking of rent-a-coder.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
hi i have to get the data displayed in LCD when i clicked a button in mfc. how to do this.
-- modified at 23:58 Tuesday 1st May, 2007
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
deeps_cute wrote: hi i have to get the data displayed in LCD when i clicked a button in mfc. how to do this.
|
|
|
|
|
Sorry but you need to read an article to do this not post here.. start with controlling input ports from lpt and learn about lpt addresses and low/high values
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
I dont know you speak about special monitor or you want to get/set value of a control
|
|
|
|
|
deeps_cute wrote: hi i have to get the data displayed in LCD when i clicked a button in mfc. how to do this.
Do you need help responding to a button click, or displaying data?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|