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:
  1. 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
  2. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  3. Private Const WM_CLOSE = &H10
  4. Private Const WM_DESTROY = &H2
  5. Private Sub Form_Load()
  6. Dim nPad As Long
  7. nPad = FindWindow("Notepad", vbNullString)
  8. PostMessage nPad, WM_CLOSE, ByVal CLng(0), ByVal CLng(0)
  9. End Sub