WM_KILLFOCUS problem
-
In the main window callback function I get the WM_KILLFOCUS message when I click on the window, and only then I get the WM_SETFOCUS message. Is that OK? I thought that WM_KILLFOCUS message is sent to a window immediatly before it looses focus. I want to register some values when the window has keyboard focus and unregister the values when the window looses focus. How can I do that?
danginkgo
-
then probably WM_KILLFOCUS is for one of the child window which was having focus earlier. Check the vlaue of wParam in WM_KILLFOCUS. It is a handle to new window which will get the focus. You can verify that WM_KILLFOCUS was not for your main window by comparing wParam with your main window handle. And to find which window lost the focus check value of wParam in WM_SETFOCUS.
Regards, Sandip.
-
In the main window callback function I get the WM_KILLFOCUS message when I click on the window, and only then I get the WM_SETFOCUS message. Is that OK? I thought that WM_KILLFOCUS message is sent to a window immediatly before it looses focus. I want to register some values when the window has keyboard focus and unregister the values when the window looses focus. How can I do that?
danginkgo
-
then probably WM_KILLFOCUS is for one of the child window which was having focus earlier. Check the vlaue of wParam in WM_KILLFOCUS. It is a handle to new window which will get the focus. You can verify that WM_KILLFOCUS was not for your main window by comparing wParam with your main window handle. And to find which window lost the focus check value of wParam in WM_SETFOCUS.
Regards, Sandip.
-
then probably WM_KILLFOCUS is for one of the child window which was having focus earlier. Check the vlaue of wParam in WM_KILLFOCUS. It is a handle to new window which will get the focus. You can verify that WM_KILLFOCUS was not for your main window by comparing wParam with your main window handle. And to find which window lost the focus check value of wParam in WM_SETFOCUS.
Regards, Sandip.
-
I dont have much idea about SDK, but Try this I hope it works, WM_SETFOCUS: if the wParam is handle to your main window then it means that your window has lost the focus. (Unregister ur hot keys) WM_KILLFOCUS: if wParam is handle to your main window then it means that your window is going to get the focus (register your hot keys). If this doesnt work may be some one can correct as i am really not sure. Ohh I forgot about HWND parameter of WindowProc. I guess It will point to your main window whenever whenever WM_KILLFOCUS will be generated for it and similarly for SetFocus.
Regards, Sandip.
modified on Tuesday, June 24, 2008 5:07 AM
-
I dont have much idea about SDK, but Try this I hope it works, WM_SETFOCUS: if the wParam is handle to your main window then it means that your window has lost the focus. (Unregister ur hot keys) WM_KILLFOCUS: if wParam is handle to your main window then it means that your window is going to get the focus (register your hot keys). If this doesnt work may be some one can correct as i am really not sure. Ohh I forgot about HWND parameter of WindowProc. I guess It will point to your main window whenever whenever WM_KILLFOCUS will be generated for it and similarly for SetFocus.
Regards, Sandip.
modified on Tuesday, June 24, 2008 5:07 AM
I tried but it doesn't work. For WM_SETFOCUS and WM_KILLFOCUS , the wParam is not the main window HWND. Ex. wParam = 0x000209fc This->hwndView = 0x000209ee hWnd = 0x000209ee (HWND parameter of WindowProc) So, I can't register and unregister if I get those messages.
danginkgo
-
I tried but it doesn't work. For WM_SETFOCUS and WM_KILLFOCUS , the wParam is not the main window HWND. Ex. wParam = 0x000209fc This->hwndView = 0x000209ee hWnd = 0x000209ee (HWND parameter of WindowProc) So, I can't register and unregister if I get those messages.
danginkgo
-
did you manage to get it working it or not can you paste some code snippets for the same.
Regards, Sandip.
This is the callback function for the main (view) window:
LRESULT CALLBACK FldViewWndProc (HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam){ PluginInstance* This; ................................................ case WM_KILLFOCUS: This = (PluginInstance*) GetWindowLong(hWnd, 0); if((HWND)wParam==This->hwndView) register hotkeys break; case WM_SETFOCUS: This = (PluginInstance*) GetWindowLong(hWnd, 0); if((HWND)wParam==This->hwndView) unregister hotkeys break; .................................................. }
danginkgo
-
This is the callback function for the main (view) window:
LRESULT CALLBACK FldViewWndProc (HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam){ PluginInstance* This; ................................................ case WM_KILLFOCUS: This = (PluginInstance*) GetWindowLong(hWnd, 0); if((HWND)wParam==This->hwndView) register hotkeys break; case WM_SETFOCUS: This = (PluginInstance*) GetWindowLong(hWnd, 0); if((HWND)wParam==This->hwndView) unregister hotkeys break; .................................................. }
danginkgo
-
did you manage to get it working it or not can you paste some code snippets for the same.
Regards, Sandip.
In the documentation I found that the wParam for WM_KILLFOCUS is the window handler for the window that receive focus, so I'll get this message in the WindowProc function if I click on the main window. So, I can't use this message, because I want to unregister the hotkeys when the main window loses focus, not immediately before it gains focus. Is it wright what I wrote?
danginkgo
modified on Tuesday, June 24, 2008 7:31 AM
-
are you getting the same values in both cases you mentioned in your previous reply.
Regards, Sandip.
-
did you manage to get it working it or not can you paste some code snippets for the same.
Regards, Sandip.
-
The problem is I don't get any message in WindowProc if the window loses focus.
danginkgo
Hi I tried it in a sample application 1> Main window with two edit controls. 2> In WM_LBUTTONDOWN i called SetFocus(hWnd); I noticed is that if i dont call setfocus explicitly i dont get the WM_SETFOCUS notification. and moreover when i switch between the two edit control i dont get any notification. may be you can try something like following. i dont see any need of using GetWindowLong. case WM_LBUTTONDOWN: SetFocus(hWnd); break; case WM_KILLFOCUS: unregisterkeys; break; case WM_SETFOCUS: registerkeys; break; I hope it helps.
Regards, Sandip.
-
Hi I tried it in a sample application 1> Main window with two edit controls. 2> In WM_LBUTTONDOWN i called SetFocus(hWnd); I noticed is that if i dont call setfocus explicitly i dont get the WM_SETFOCUS notification. and moreover when i switch between the two edit control i dont get any notification. may be you can try something like following. i dont see any need of using GetWindowLong. case WM_LBUTTONDOWN: SetFocus(hWnd); break; case WM_KILLFOCUS: unregisterkeys; break; case WM_SETFOCUS: registerkeys; break; I hope it helps.
Regards, Sandip.
-
My code is exactly like what you wrote. The problem is I don't get the WM_KILLFOCUS message only when I return to the app window. If the focus is on the app window and I go to other window then I don't get any message.
danginkgo
-
Hi I tried it in a sample application 1> Main window with two edit controls. 2> In WM_LBUTTONDOWN i called SetFocus(hWnd); I noticed is that if i dont call setfocus explicitly i dont get the WM_SETFOCUS notification. and moreover when i switch between the two edit control i dont get any notification. may be you can try something like following. i dont see any need of using GetWindowLong. case WM_LBUTTONDOWN: SetFocus(hWnd); break; case WM_KILLFOCUS: unregisterkeys; break; case WM_SETFOCUS: registerkeys; break; I hope it helps.
Regards, Sandip.
-
It works now. It seems that the problem was that I called MessageBox() function in my code with wrong HWND. That massed up the messages. I took it out of the code and it works fine. Thank you very much for your help.
danginkgo
-
In the main window callback function I get the WM_KILLFOCUS message when I click on the window, and only then I get the WM_SETFOCUS message. Is that OK? I thought that WM_KILLFOCUS message is sent to a window immediatly before it looses focus. I want to register some values when the window has keyboard focus and unregister the values when the window looses focus. How can I do that?
danginkgo
danginkgo wrote:
I want to register some values when the window has keyboard focus and unregister the values when the window looses focus.
It sounds like you need to use
WM_ACTIVATEAPP
instead."Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne