Results 1 to 7 of 7

Thread: [resolved]Getting Window Handle

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    [resolved]Getting Window Handle

    hello, i am trying to get the hwnd of the start button on windows.
    I can get it in C++ but in vb6 i cannot.
    i have this: (yes all these functions are declared, correctly.)
    vb Code:
    1. Dim blnLock As Boolean
    2. Dim strText As String
    3. Dim whWnd As Long
    4. Dim lResult As Single
    5.  
    6.     blnLock = chkLock.Value
    7.     strText = txtToChange.Text
    8.     whWnd = GetDlgItem(FindWindow("Shell_TrayWnd", vbNull), 103)
    9. 'i believe 103 is where my error is coming from.
    10. 'in c++ 103 would be 0x103 so im assuming this is where the problem is..
    11.    
    12.     Debug.Print whWnd 'returns whWnd as 0
    13.     If whWnd = 0 Then
    14.         lblError.Caption = "Error: " & _
    15.         Err.LastDllError & ": Error finding start button handle."
    16. 'last dllerror gives me error 1400, window handle not found
    17.         Exit Sub
    18.     End If
    19.        
    20.     lResult = ChangeText(whWnd, blnLock, strText)
    21.    
    22.     Select Case lResult
    23.         Case 1
    24.             lblError.Caption = "Changed without error"
    25.         Case 0
    26.             lblError.Caption = "Error setting text"
    27.         Case -1
    28.             lblError.Caption = "Error locking start button"
    29.     End Select

    i have comments in the code about my problem. if anyone knows what im doing wrong with getdlgitem please help me out.
    Last edited by bluehairman; Apr 17th, 2008 at 09:47 PM.

  2. #2
    Fanatic Member DrUnicode's Avatar
    Join Date
    Mar 2008
    Location
    Natal, Brazil
    Posts
    631

    Re: Getting Window Handle

    C++ 0x103 in Vb would be &H103

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    Re: Getting Window Handle

    i tried that with my code but it still returns 0..
    but i got it working with this.
    vb Code:
    1. Dim blnLock As Boolean
    2. Dim strText As String
    3. Dim whWnd As Long
    4. Dim lResult As Single
    5. Dim thWnd As Long
    6.  
    7.     whWnd& = FindWindow("Shell_TrayWnd", vbNullString)
    8.     thWnd& = FindWindowEx(whWnd&, 0, "Button", vbNullString)
    9.    
    10.     blnLock = chkLock.Value
    11.     strText = txtToChange.Text
    12.  
    13.     Debug.Print thWnd
    14.     If whWnd = 0 Then
    15.         lblError.Caption = "Error: " & _
    16.         Err.LastDllError & ": Error finding start button handle."
    17.         Exit Sub
    18.     End If
    19.        
    20.     lResult = ChangeText(thWnd, blnLock, strText)
    21.    
    22.     Select Case lResult
    23.         Case 1
    24.             lblError.Caption = "Changed without error"
    25.         Case 0
    26.             lblError.Caption = "Error setting text"
    27.         Case -1
    28.             lblError.Caption = "Error locking start button"
    29.     End Select

    but the start button text just turns to all strange characters.. it most likely from the lparam part of SendMessage. (I'm changing the text with WM_SETTEXT)
    so how can i get around this?
    i noticed even when strText equals the same thing the start buttons text is different every time my function is called. even if the save value is being sent.

  4. #4
    Fanatic Member DrUnicode's Avatar
    Join Date
    Mar 2008
    Location
    Natal, Brazil
    Posts
    631

    Re: Getting Window Handle

    Can you post code for ChangeText?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    Re: Getting Window Handle

    i would but i am not at home.
    I do know what the code is though.

    Heres the sendmessage i use in changetext (the only part of code that actually does something)

    lhwnd and strText are entered with the byval parameters in the function changetext.
    SendMessage lhWnd, WM_SETTEXT, vbNull, strText

  6. #6
    Fanatic Member DrUnicode's Avatar
    Join Date
    Mar 2008
    Location
    Natal, Brazil
    Posts
    631

    Re: Getting Window Handle

    What is your SendMessage Declare?
    If it is this:
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long

    Then use it like this:
    SendMessage lhWnd, WM_SETTEXT, vbNull, ByVal strText

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    Re: Getting Window Handle


    thanks that did it!

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