-
May 8th, 2002, 12:00 PM
#1
Thread Starter
Hyperactive Member
SetActiveWindow
In a window, i try to set the focus on another window here's my code :
VB Code:
Private Declare Function SetActiveWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
'...
SetActiveWindow lhWnd
'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
#2
MSDN description of the function
The SetActiveWindow function activates a window. The window must be attached to the calling thread's message queue.
In other words, the window you are messing with has to belong to your current application.
Try this where:
hWnd = other window
Me.hWnd - current window's hWnd
Code:
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
Dim retval
retval= SendMessage( Me.hWnd, WM_KILLFOCUS,0&,0&)
retval= SendMessage( hWnd, WM_SETFOCUS,0&,0&)
-
May 8th, 2002, 01:05 PM
#3
Thread Starter
Hyperactive Member
Can this function work with MDI childs
-
May 8th, 2002, 01:26 PM
#4
Yes, it will work on any window.
-
May 8th, 2002, 02:54 PM
#5
Thread Starter
Hyperactive Member
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
#6
Try the SetForegroundWindow function.
-
May 8th, 2002, 03:31 PM
#7
Thread Starter
Hyperactive Member
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
#8
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
#9
Thread Starter
Hyperactive Member
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
#10
I hope it's not too late, but you could also use VB's ZOrder method too (is this what you're using now?).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|