|
-
Sep 30th, 2002, 06:44 AM
#1
Thread Starter
New Member
How to find a running application?
Hi Everybody,
I need your help. Actually I want to find whether an application is open and if open, the window of that app. should get focus and be restored to normal position.
How can i do this.
Thanks in advance.
-
Sep 30th, 2002, 07:33 AM
#2
By "Open" I assume you mean running. Here is an example that should work for you.
VB 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_SHOWNORMAL = 1
Private Sub Command1_Click()
Dim WinWnd As Long
WinWnd = FindWindow(vbNullString, "Calculator")
If WinWnd > 0 Then
'Calculator Is Running - restore it to normal position
ShowWindow WinWnd, SW_SHOWNORMAL
End If
End Sub
-
Sep 30th, 2002, 09:04 AM
#3
Software Eng.
When using FindWindow, it's a good idea to specify a classname as well (just to help narrow down your search).
-
Sep 30th, 2002, 09:15 AM
#4
Originally posted by Megatron
When using FindWindow, it's a good idea to specify a classname as well (just to help narrow down your search).
Good point!
-
Sep 30th, 2002, 05:01 PM
#5
New Member
Hey there,
But how can I find who was the last window who has the focus BEFORE I click on my form and my form has the focus? Is there any way? Thank you.
-
Sep 30th, 2002, 11:59 PM
#6
Thread Starter
New Member
Re: How to find a running application?
Thank you very much for the help. I tried using the code in my application. I have one problem. The hWnd, returned by the FindWindow function is always -1. So ShowWindow function is not working. I have not used the classname in the FindWindow function. Will, using the classname will solve my problem? By classname u mean, the Form name?
With regards,
Surfy.
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
|