OnKeyDown and OnPreTranslateMsg() problem...
-
Hi, I'm facing a problem which i don't know how to solve... I created a dialog which contains several edit boxes. When activating the dialog , the first edit box automatically receives the input focus. My problem is that I need to receive the ON_WM_KEYDOWN in the parent dialog, but since the focus is on the first edit box - I will never get it. I tried to catch the ON_WM_KEYDOWN message in PreTranslateMsg , but I'm facing the same problem. Anyone??? With best regards, Eli
-
Hi, I'm facing a problem which i don't know how to solve... I created a dialog which contains several edit boxes. When activating the dialog , the first edit box automatically receives the input focus. My problem is that I need to receive the ON_WM_KEYDOWN in the parent dialog, but since the focus is on the first edit box - I will never get it. I tried to catch the ON_WM_KEYDOWN message in PreTranslateMsg , but I'm facing the same problem. Anyone??? With best regards, Eli
If you want to monitor when the text in the edit box changes, you could do something with the EN_CHANGE notification which is sent when the text in an edit box changes.. If you want to monitor keyboard messages, then i'm not sure that the WM_KEYDOWN message is applicable to dialog boxes.. You could try creating a window using the CreateWindow() or CreateWindowEx API, then programatically creating the controls, and then testing for the WM_KEYDOWN message.. Hope this helps! --PerspX
-
If you want to monitor when the text in the edit box changes, you could do something with the EN_CHANGE notification which is sent when the text in an edit box changes.. If you want to monitor keyboard messages, then i'm not sure that the WM_KEYDOWN message is applicable to dialog boxes.. You could try creating a window using the CreateWindow() or CreateWindowEx API, then programatically creating the controls, and then testing for the WM_KEYDOWN message.. Hope this helps! --PerspX
Hi PerspX , First,thanks for your quick reply. What is the difference between creating the control during the design time and during runtime(the control is being created in a different way???). Anyway,My problem is not catching the messages in the control, but catching the messages in the dialog... Thanks again, Eli
-
Hi, I'm facing a problem which i don't know how to solve... I created a dialog which contains several edit boxes. When activating the dialog , the first edit box automatically receives the input focus. My problem is that I need to receive the ON_WM_KEYDOWN in the parent dialog, but since the focus is on the first edit box - I will never get it. I tried to catch the ON_WM_KEYDOWN message in PreTranslateMsg , but I'm facing the same problem. Anyone??? With best regards, Eli
eli15021979 wrote:
I need to receive the ON_WM_KEYDOWN in the parent dialog, but since the focus is on the first edit box - I will never get it.
May this link help you setting focus to dialog Best Regards, Suman
-
Hi PerspX , First,thanks for your quick reply. What is the difference between creating the control during the design time and during runtime(the control is being created in a different way???). Anyway,My problem is not catching the messages in the control, but catching the messages in the dialog... Thanks again, Eli
No i mean creating the window using the CreateWindow() or CreateWindowEx() API as opposed to creating a dialog window. Creating a window like this will create a "proper" window as opposed to a dialog window - take a look at this article for more information. I think - but im not sure - that some window messages dont get passed to dialog windows and i think WM_KEYDOWN is one of them.. I think I have tried that in the past to no avail.. So create the window "properly", then create the controls in it using CreateWindow() and CreateWindowEx(), and specifying the control classes (see this article on MSDN if you do not know these classes). Hope this helps! --PerspX
-
eli15021979 wrote:
I need to receive the ON_WM_KEYDOWN in the parent dialog, but since the focus is on the first edit box - I will never get it.
May this link help you setting focus to dialog Best Regards, Suman
Hi Suman, Thanks for the link... However,it doesn't say how to set the focus to the dialog itself,but only to one of the controls in the dialog(or maybe I didn't saw it?) Thanks again, Eli
-
Hi Suman, Thanks for the link... However,it doesn't say how to set the focus to the dialog itself,but only to one of the controls in the dialog(or maybe I didn't saw it?) Thanks again, Eli
-
Hi, I'm facing a problem which i don't know how to solve... I created a dialog which contains several edit boxes. When activating the dialog , the first edit box automatically receives the input focus. My problem is that I need to receive the ON_WM_KEYDOWN in the parent dialog, but since the focus is on the first edit box - I will never get it. I tried to catch the ON_WM_KEYDOWN message in PreTranslateMsg , but I'm facing the same problem. Anyone??? With best regards, Eli
Try returning FALSE from your dialog's OnInitDialog() override. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Try returning FALSE from your dialog's OnInitDialog() override. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Mark Salsbery wrote:
Try returning FALSE from your dialog's OnInitDialog() override.
Dear Mark, I created test application and tried returning FALSE, but the focus is still in edit box. There should be some way to do this. Best Regards, Suman
hmmm Yes I tested that and I couldn't get it to work. The dialog wants the keyboard focus on a control no matter what. Trying to remove the focus was fruitless as well. I tried both SetFocus() and WM_NEXTDLGCTL. *trying some more stuff...* This looks promising ... add a ON_WM_SETFOCUS() entry to the dialog's message map Add an empty OnSetFocus() handler method: void CMYDlg::OnSetFocus(CWnd*) { } At the end of the dialog's OnInitDialog() override (instead of returning TRUE), add: SetFocus(); return FALSE; See if that works for you... Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Hi, I'm facing a problem which i don't know how to solve... I created a dialog which contains several edit boxes. When activating the dialog , the first edit box automatically receives the input focus. My problem is that I need to receive the ON_WM_KEYDOWN in the parent dialog, but since the focus is on the first edit box - I will never get it. I tried to catch the ON_WM_KEYDOWN message in PreTranslateMsg , but I'm facing the same problem. Anyone??? With best regards, Eli
You can only trace queued message in PreTranslateMessage. Manish Rastogi
-
hmmm Yes I tested that and I couldn't get it to work. The dialog wants the keyboard focus on a control no matter what. Trying to remove the focus was fruitless as well. I tried both SetFocus() and WM_NEXTDLGCTL. *trying some more stuff...* This looks promising ... add a ON_WM_SETFOCUS() entry to the dialog's message map Add an empty OnSetFocus() handler method: void CMYDlg::OnSetFocus(CWnd*) { } At the end of the dialog's OnInitDialog() override (instead of returning TRUE), add: SetFocus(); return FALSE; See if that works for you... Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Hi Mark, Thanks, now there is no focus on controls in a dialog. What is happening if you are not calling SetFocus() in OnInitDialog()? I hope Eli can get the messages in dialog! Best Regards, Suman
rp_suman wrote:
What is happening if you are not calling SetFocus() in OnInitDialog()?
According to the docs, the default handler for WM_SETFOCUS is the one that sets the focus to the correct control (it tracks which control internally). WM_SETFOCUS is a notification so there should be no huge harm in not passing it to the default handler. It will effect the user interface - you may want to set the focus to a specific control at some point. Users expect dialogs to act a certain way. With this method, when the user switches to another app and then switches back, the focus will be set to the dialog but the default control for the dialog may/will be set as well. A solution should probably be a bit more robust and track which control should have focus when nevessary. My 2 cents, Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder