|
-
Mar 14th, 2000, 12:52 AM
#1
Thread Starter
Member
Hello, i need to use Windows API or any other tool to find out that a program have been executed on the computer.
I need to find that a program with X caption has been executed and get her window-handle back.
Thank you very much,
Kiron.
-
Mar 14th, 2000, 01:51 AM
#2
Junior Member
Hi,
I could not understand you clearly frame your question in a more detailed manner as for know i recomend using the CreateToolhelp32Snapshot along with Process32First And Process32Next API's to get a list of all the programs running and then get what you want with a host of window APi's like enumthreadwindows .
i may not be right but if you be clear maybe i can help you.
Reply to
<[email protected]>
-
Mar 14th, 2000, 04:43 AM
#3
Frenzied Member
Use the FindWindow API
It sounds like you know the window's caption, so it's easy to get the handle with the FindWindow API.
For this example, start a project and drop a command button on the form. Then paste the following into the form's code window.
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32.dll" Alias _
"FindWindowA" (ByVal lpClassName As Long, _
ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
'Say you want to get the handle to Notepad and display
'it to the user. Call the function like this:
Dim lHandle As Long, _
sWindowCaption As String
sWindowCaption = "Untitled - Notepad"
lHandle = FindWindow(CLng(0), sWindowCaption)
If lHandle = 0 Then 'The window isn't running
MsgBox "The window: """ & sWindowCaption & """ is not currently open."
Else
MsgBox "The handle to """ & sWindowCaption & """ is: " & lHandle
End If
End Sub
Run the project without Notepad running and click the command button. Now, leave the project running and open a new Notepad document (Start->Programs->Accessories->Notepad). Click the command button again and you get the handle.
-
Mar 15th, 2000, 11:22 PM
#4
Junior Member
Well Seeweed i think that would be perfect if we know the window caption well but we get a problem if we want to check for a part of the string i nwhich case findwindow won't work so the best thing according to me is to the EnumWindows API get handle and then find out to see if it a toplevel window or not by calling the GetParent Api depending upon the requirement and then use the GetWindowText Api to get the caption and search for a part of the string using the Instring function.
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
|