Results 1 to 5 of 5

Thread: Click a button with code?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    Somerset, UK
    Posts
    93

    Post

    Does anyone know how to click a button using code. Probaly using the sendmessage command??

  2. #2
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126

    Post

    If it's a vb button, simply call the event procedure for that button!

    For example, to click the cmdExit button on the current form use cmdExit_Click

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    Somerset, UK
    Posts
    93

    Post

    It's another button in another application

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    If you know the Window Handle (hWnd) for that button then you can use SendMessage API to do that:

    Code:
    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_KEYDOWN = &H100
    Private Const WM_KEYUP = &H101
    Private Const VK_SPACE = &H20
    
    
    Public Sub ClickButton(hwnd As Long)
        Call SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0)
        Call SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0)
    End Sub
    Usage: ClickButton ButtonHwnd


    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]



  5. #5
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    I couldn't get Serge's code to work for a menu, though I'm using the correct menu handle (submenu actually).

    Any ideas??
    Thanks,
    Wade

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