Click to See Complete Forum and Search --> : Maximizing Another Application
PatrickCorgan
Feb 23rd, 2001, 11:48 PM
I can get both the hWnd and the title bar text of another application. I can transfer focus to the app. But if it is minimized, it stays minimized. How can I restore it?
Thanks!
markwel
Feb 24th, 2001, 03:04 AM
Hai,
FindWindow API is useful to Find the Application. After that you should use sendkeys function.
Dim hWnd As Long
hWnd = FindWindow(vbNullString, "Microsoft Word")
If hWnd = 0 Then
Msgbox "Application Running"
Endif
markwel
Feb 24th, 2001, 03:14 AM
Hai,
You should declare that API Function also
At Module declaration section, you should paste this.
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Thanx and Best of Luck.
Use the ShowWindow API function.
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (Byval lpClassName As String, _
Byval lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" _
(Byval hwnd As Long, Byval nCmdShow As Long) As _
Long
Private Const SW_RESTORE = 9
Private Sub Command1_Click()
Dim hWin As Long
hWin = FindWindow("SciCalc", "Calculator")
If hWin <> 0 Then
ShowWindow hWin, SW_RESTORE
End If
End Sub
By the way, markwel, if the handle is 0, the window doesn't exist. Anything other than 0 and there's a handle that exists. And you shouldn't use hWnd as a variable, being that it's already being used in other places. So your code should be like this:
Dim hWin As Long
hWin = FindWindow(vbNullString, "Microsoft Word")
If hWin <> 0 Then
Msgbox "Application Running"
End If
markwel
Feb 24th, 2001, 03:37 AM
Yes Mathews. I understand.
Thanx.
This will get the Windowname as well as the handle
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Sub Command1_Click()
Dim hCalc As Long
Dim sName As String * 255
hCalc = FindWindowEx(0, 0, "SciCalc", "Calculator")
GetWindowText hCalc, sName, 255
sName = Left(sName, InStr(1, sName, vbNullChar) - 1)
Print sName
Print hCalc
End Sub
PatrickCorgan
Feb 26th, 2001, 10:42 PM
Got it all figured out. Thanks for all your help!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.