Results 1 to 6 of 6

Thread: Desperately need help!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    Exclamation 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

  2. #2
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    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

  4. #4
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    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:
    1. Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    2. Dim l As Long
    3.  
    4.     Select Case wMsg
    5.         Case WM_ACTIVATEAPP
    6.             l = GetForegroundWindow
    7.             Form1.Label1.Caption = CStr(l)
    8.         Case Else
    9.             WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    10.     End Select
    11.  
    12. End Function

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    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

  6. #6
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    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:
    1. Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    2.  
    3.     Select Case wMsg
    4.         Case WM_ACTIVATEAPP
    5.            If (wParam = 0) Then
    6.                 ' losing focus
    7.            Else
    8.                 ' getting focus
    9.            End If
    10.         Case Else
    11.             WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    12.     End Select
    13. 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
  •  



Click Here to Expand Forum to Full Width