How to get hWnd from app name?
Hi, is it possible to get the hWnd of a program, say Notepad.exe just from the name "Notepad.exe"? Or do I need more?
I want to be able to destroy a window without ever looking at it's caption or anything, just the process name eg. "Notepad.exe"
Is this possible? If so, how would I get the hWnd. (I already know how to destroy it...he he)
Thanx you guys,
Scott
Re: How to get hWnd from app name?
Quote:
Originally posted by killer_cobra
Hi, is it possible to get the hWnd of a program, say Notepad.exe just from the name "Notepad.exe"? Or do I need more?
I want to be able to destroy a window without ever looking at it's caption or anything, just the process name eg. "Notepad.exe"
Is this possible? If so, how would I get the hWnd. (I already know how to destroy it...he he)
Thanx you guys,
Scott
If you know the class, you can find its handle
Try this:
VB Code:
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_CLOSE = &H10
Private Const WM_DESTROY = &H2
Private Sub Form_Load()
Dim nPad As Long
nPad = FindWindow("Notepad", vbNullString)
PostMessage nPad, WM_CLOSE, ByVal CLng(0), ByVal CLng(0)
End Sub