Results 1 to 2 of 2

Thread: Does the a window's handle change.......

  1. #1

    Thread Starter
    Addicted Member Daniel_Christie's Avatar
    Join Date
    Jan 2000
    Location
    USA
    Posts
    245

    Post

    Does a window's handle change everytime the parent window is closed and opened?

    I have a "hWnd spy" program, that informs me of a specific window's hWnd. However when a program is closed and then lauched again it's hWnd and all child hWnd's are different.
    Now either the "hWnd Spy" program is either providing me false information or my suspicions concerning hWnd's changing, is true. Can anyone end my madness and kindly tell me the answer, please and thanks?

    p.s. If hWnd's do periodically change, How can I make my program get the handle of a specific window? (I know this is asking a lot )

    Daniel Christie

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Window Handles do change every time a Window is Created, you can find the Window Handle using the API FindWindowEx().

    You can Pass a Window Caption or Class, you can also search within other Windows, in the case of searching for a Textbox for example, ie.
    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_SETTEXT = &HC
    
    Private Sub Command1_Click()
        Dim sText As String
        Dim lHwnd As Long
        
        lHwnd = FindWindowEx(0, 0, "3rdPartyAppClass", vbNullString)
        lHwnd = FindWindowEx(lHwnd, 0, "Edit", vbNullString)
        sText = Text1
        Call SendMessage(lHwnd, WM_SETTEXT, Len(sText), ByVal sText)
    End Sub
    Where 3rdPartyAppClass is the Classname of the 3rd Party App and Edit is the Classname for a Standard Windows Textbox.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


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