|
-
Feb 24th, 2001, 12:48 AM
#1
Thread Starter
Member
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!
-
Feb 24th, 2001, 04:04 AM
#2
Lively Member
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
-
Feb 24th, 2001, 04:14 AM
#3
Lively Member
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.
-
Feb 24th, 2001, 04:22 AM
#4
Use the ShowWindow API function.
Code:
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
-
Feb 24th, 2001, 04:26 AM
#5
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:
Code:
Dim hWin As Long
hWin = FindWindow(vbNullString, "Microsoft Word")
If hWin <> 0 Then
Msgbox "Application Running"
End If
-
Feb 24th, 2001, 04:37 AM
#6
Lively Member
Yes Mathews. I understand.
Thanx.
-
Feb 24th, 2001, 11:54 AM
#7
This will get the Windowname as well as the handle
Code:
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
-
Feb 26th, 2001, 11:42 PM
#8
Thread Starter
Member
Thanks
Got it all figured out. Thanks for all your help!
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
|