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.
Printable View
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.
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
When using FindWindow, it's a good idea to specify a classname as well (just to help narrow down your search).
Good point! :)Quote:
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).
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.
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.