Results 1 to 2 of 2

Thread: How to get hWnd from app name?

  1. #1

    Thread Starter
    Addicted Member killer_cobra's Avatar
    Join Date
    Jun 2001
    Location
    Lost in space
    Posts
    131

    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
    Error... What Error?!?! I've only typed a single character!
    ______________________________
    VB 6.0 EE, Win 2k Pro on AMD Duron 1Ghz/ 384 MB SDRAM

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Re: How to get hWnd from app name?

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width