PDA

Click to See Complete Forum and Search --> : Desperately need help!


Joey_k29
Sep 23rd, 2001, 02:55 PM
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

Patoooey
Sep 23rd, 2001, 03:31 PM
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. :)

Joey_k29
Sep 23rd, 2001, 04:16 PM
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

Patoooey
Sep 23rd, 2001, 05:31 PM
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 ??


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

Joey_k29
Sep 23rd, 2001, 06:02 PM
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

Patoooey
Sep 23rd, 2001, 06:43 PM
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.


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