|
-
Sep 23rd, 2001, 02:55 PM
#1
Thread Starter
Hyperactive Member
Desperately need help!
I am writing a program that includes subclassing. I am successfully able to use wm_activateapp to determine when the active winodow has changed. The problem comes in determining the handle of the window that has become active. What I originally attemped to do was to respond the case wm_activateapp with getforegroundwindow(), but it does not work. I can not determine why. Is there any way to make it work with getforeground window? Is it possible to get the handle of the active window without using get foregroundwindow when subclassing with wm_activateapp? Thank you very much for the help.
Pulling out my hair,
Joseph
-
Sep 23rd, 2001, 03:31 PM
#2
Fanatic Member
Off the top of my head....The GetForeGroundWindow isn't working properly because your STILL in your subclass function and the app focus hasn't really changed yet.
Set a timer after the wm_activateapp message and get the active window in the timer function ???
Just a semi-educated guess. If I'm completley wrong, then I dis-avow any knowledge of this post and it will self destruct in 5 seconds.
-
Sep 23rd, 2001, 04:16 PM
#3
Thread Starter
Hyperactive Member
Thank you but....
Can you suggest a reasonable amount of time if I want to know the foreground window as immediately as possible? Also, is there anyway that by subclassing a form, you can gain access to the handle of the window that is becoming activated? Thank you for your help.
Joe
-
Sep 23rd, 2001, 05:31 PM
#4
Fanatic Member
OK...The timer idea was a guess but I just tried the following as my WinProc function and it gives me the handle to the active app with no problems. I was able to switch to several other apps from my form and it gave me the correct handle every time(used an API SPY to verify)
What problems are you having ??
VB Code:
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim l As Long
Select Case wMsg
Case WM_ACTIVATEAPP
l = GetForegroundWindow
Form1.Label1.Caption = CStr(l)
Case Else
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Select
End Function
-
Sep 23rd, 2001, 06:02 PM
#5
Thread Starter
Hyperactive Member
Maybe I misunderstand subclassing...
When I subclass, does the wm_activateapp only get triggered when you switch from you app to another or from another app to yours? I was assuming it would send it regardless of which app was active at the time. Thank you very much for your help. Thank you very much again.
Joe
-
Sep 23rd, 2001, 06:43 PM
#6
Fanatic Member
Whether your app is getting or losing focus depends on the value in wParam. If it's zero, then your losing focus. Non-zero, your getting focus.
VB Code:
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case wMsg
Case WM_ACTIVATEAPP
If (wParam = 0) Then
' losing focus
Else
' getting focus
End If
Case Else
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Select
End Function
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
|