May 8th, 2002, 12:00 PM
In a window, i try to set the focus on another window here's my code :
Private Declare Function SetActiveWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
'lhWnd is a variable containing the hwnd of the form i want to set focus on
But for a reason or another the focus stays on the window in wich i called this function. is there something wrong here? thanks
May 8th, 2002, 12:15 PM
MSDN description of the function
In other words, the window you are messing with has to belong to your current application.
The SetActiveWindow function activates a window. The window must be attached to the calling thread's message queue.
Try this where:
hWnd = other window
Me.hWnd - current window's hWnd
Private Const WM_KILLFOCUS = &H8
Private Const WM_SETFOCUS = &H7
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
Long, ByVal wParam As Long, lParam As Any) As Long
retval= SendMessage( Me.hWnd, WM_KILLFOCUS,0&,0&)
retval= SendMessage( hWnd, WM_SETFOCUS,0&,0&)
May 8th, 2002, 01:05 PM
Can this function work with MDI childs
May 8th, 2002, 01:26 PM
Yes, it will work on any window.
May 8th, 2002, 02:54 PM
it's weird because when I use those functions, it execute the activate of the form i want the focus on but it doesn't set the focus. No mather when during that I print the MDIMother.ActiveFOrm.Name it gives me the name of the form from the one I want focus is called
May 8th, 2002, 03:13 PM
Try the SetForegroundWindow function.
May 8th, 2002, 03:31 PM
well there must be soimething weird in my code cuz
all the above don't work + setfocus (API) don't work
May 8th, 2002, 06:01 PM
Post all of your code maxl, not just a portion of it, and we will take a look. I ask this because the responses I've seen from Megatron and jim mcnamara make sense, based on your original question. If their code/suggestions are not working then me thinks their might be variables in your equation that haven't been shown.
Last edited by Hack; May 8th, 2002 at 06:05 PM.
May 9th, 2002, 08:28 AM
Anyway, I found a way to make it work without api so Thanks everybody for your response there must have been something weird in my code somewhere. Thanks again
May 9th, 2002, 03:31 PM
I hope it's not too late, but you could also use VB's ZOrder method too (is this what you're using now?).
Click Here to Expand Forum to Full Width
Survey posted by VBForums.