Link to home
Start Free TrialLog in
Avatar of aniston
aniston

asked on

Giving Focus to an App with this hWND

I have used the GetForegroundWindow() fn. to obtain the handle to the window who currently has focus.  Now i am planning on moving the focus from this app to another via the AppActivate() fn.  What i want to know is, is there an function i can call that will allow me to set the original app as having focus again once i am done?  Specifically, is there a SetForegroundWindow() fn so that i may pass the hWnd that i got from GetForegroundWindow()?

Thanks
Avatar of caraf_g
caraf_g

SetForegroundWindow()

Guess what. Yes.
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Huh? You've already had this answered in your other question.
By the way, if you want to know if the window is minimized and you need to show it, add the following to a module:

    Public Const WS_MINIMIZE = &H20000000
    Public Const GWL_STYLE = (-16)
    Declare Function GetWindowLong Lib "user32" _
        Alias "GetWindowLongA" (ByVal hWnd As Long, _
        ByVal nIndex As Long) As Long
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
     

Then in a subroutine, you can do:

   Dim lWinfo As Long
   Dim lhWnd As Long

   lhWnd = FindWindow(vbNullString, "Win32api.txt - WordPad")
   lWinfo = GetWindowLong(lhWnd, GWL_STYLE)
   If (lWinfo And WS_MINIMIZE) = WS_MINIMIZE Then
       Debug.Print "minimized"
   Else
       Debug.Print "not minimized"
   End If



By the way, I am using the FindWindow API above to find the window handle... To use it, all you have to do is pass the title of the window as the 2nd argument...


Cheers!®©
Cool. Behold the "Answer Grade" at the top of the thread. I only just spotted it now. So now you can get a clue whether an answer is worth looking at!
Thanks for the points! Glad I could help!


Cheers!®©