Results 1 to 8 of 8

Thread: [2008] Api Wm_settext

  1. #1

    Thread Starter
    Lively Member RedGunner's Avatar
    Join Date
    Oct 2008
    Location
    Ireland
    Posts
    67

    Question [2008] Api Wm_settext

    Code:
    Public Class Form1
        Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
        Public Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
        Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As String) As Int32
        Public Const WM_SETTEXT As Int32 = &HC
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSEND.Click
    
            Dim hWnd As Int32 = FindWindow("#32770", vbNullString)
            If hWnd > 0 Then
    
                Dim hWndChild As Int32 = FindWindowEx(hWnd, 0, "ATL:00B4C870", vbNullString)
    
                If hWndChild > 0 Then
                    MsgBox("Found!") ' Check to see if it is working
                    Dim strText As String = textbox1.Text
                    SendMessage(hWndChild, WM_SETTEXT, 0, strText)
                End If
            End If
        End Sub
    
    End Class
    This is working fine for, however my question is now... how do I make it press a button.

    http://img399.imageshack.us/my.php?image=btnqa6.jpg

    Above is the properties of the button.

    Thanks guys!!

  2. #2
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: [2008] Api Wm_settext

    I assume your question is how do i click a button using sendMessage

    there are two ways,
    1. Sending WM_LBUTTON Down
    2. Sending a BM_CLICK

    Code:
    SendMessage(buttonHnd, BM_CLICK, 0,0)

  3. #3

    Thread Starter
    Lively Member RedGunner's Avatar
    Join Date
    Oct 2008
    Location
    Ireland
    Posts
    67

    Re: [2008] Api Wm_settext

    What if I want to click a popup menu and select something on it... what would that use?

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: [2008] Api Wm_settext

    Quote Originally Posted by Fazi
    I assume your question is how do i click a button using sendMessage

    there are two ways,
    1. Sending WM_LBUTTON Down
    2. Sending a BM_CLICK

    Code:
    SendMessage(buttonHnd, BM_CLICK, 0,0)
    Fazi, if the Button you want to click is already selected (the default) that code alone won't actually click the button but will only highlight it.

    To test, lets say one VB program launches this,
    rsp = MsgBox("Copy all files?", vbYesNo + vbDefaultButton1, "Copy All?")

    Now in the other VB program tell it to click the "Yes" button (which is the selected/default) , notice the button will only get highlighted and not clicked!

    Here's the fix,
    Code:
    SendMessage buttonHnd, WM_ACTIVATE, WA_ACTIVE, 0
    SendMessage buttonHnd, BM_CLICK, 0, 0
    hope that helps someone, it drove me nuts for a long time.

  5. #5
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: [2008] Api Wm_settext

    Thanks Edgemel for the useful tips,

    i got very useful informations from your last few post in various threads. but i cold not rate you coz "Spread some points to some one else before give it to edgemel" it says.

    Need to find a JS code to unlock this limitation

  6. #6
    New Member
    Join Date
    Jan 2009
    Posts
    2

    Re: [2008] Api Wm_settext

    RedGunner, thanks for your post, helped me a bit.

    Are there any wMsg parameters for appending text to the hWnd?

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [2008] Api Wm_settext

    Quote Originally Posted by forcumang
    RedGunner, thanks for your post, helped me a bit.

    Are there any wMsg parameters for appending text to the hWnd?
    forcumang, it would be better if you will start a thread of yours so the responses would be directed to you. I am not sure about appending but I using WM_GETTEXT to get the current text should be one option, after you have received the current text then you could just append a text to it then use WM_SETTEXT.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8
    New Member
    Join Date
    Jan 2009
    Posts
    2

    Re: [2008] Api Wm_settext

    Quote Originally Posted by dee-u
    forcumang, it would be better if you will start a thread of yours so the responses would be directed to you. I am not sure about appending but I using WM_GETTEXT to get the current text should be one option, after you have received the current text then you could just append a text to it then use WM_SETTEXT.
    perfect, thanks

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