How to simulate button click?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: How to simulate button click?

  1. #1
    Serge Guest

    How to simulate button click?


    Hi,

    Does someone know a method for sending a message or whatever to simulate
    the mouse button click on a "OK" button inside an application runnig beside
    my VB application?... I can easily find the handle of this button but i
    dont know how to click on the button.. it's surely a fuction or a trapping
    of WindowProc but how to do that?? if someone knows then please write me
    some code in VB to tell me the way

    Thanks
    Serge


  2. #2
    Jim Edgar Guest

    Re: How to simulate button click?

    Serge --

    The following code snippet (from the 101 VB Tips) might be
    what you need.

    Option Explicit
    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 BM_CLICK = &HF5

    Call SendMessage(Command1.hWnd, BM_CLICK, 0, ByVal 0&)

    Hope it helps,

    Jim Edgar

    "Serge" <bouchard.serge@videotron.ca> wrote in message
    news:3942d549$1@news.devx.com...
    >
    > Hi,
    >
    > Does someone know a method for sending a message or whatever to simulate
    > the mouse button click on a "OK" button inside an application runnig

    beside
    > my VB application?... I can easily find the handle of this button but i
    > dont know how to click on the button.. it's surely a fuction or a

    trapping
    > of WindowProc but how to do that?? if someone knows then please write me
    > some code in VB to tell me the way
    >
    > Thanks
    > Serge
    >




  3. #3
    Jim Edgar Guest

    Re: How to simulate button click?

    Serge --

    The following code snippet (from the 101 VB Tips) might be
    what you need.

    Option Explicit
    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 BM_CLICK = &HF5

    Call SendMessage(Command1.hWnd, BM_CLICK, 0, ByVal 0&)

    Hope it helps,

    Jim Edgar

    "Serge" <bouchard.serge@videotron.ca> wrote in message
    news:3942d549$1@news.devx.com...
    >
    > Hi,
    >
    > Does someone know a method for sending a message or whatever to simulate
    > the mouse button click on a "OK" button inside an application runnig

    beside
    > my VB application?... I can easily find the handle of this button but i
    > dont know how to click on the button.. it's surely a fuction or a

    trapping
    > of WindowProc but how to do that?? if someone knows then please write me
    > some code in VB to tell me the way
    >
    > Thanks
    > Serge
    >




  4. #4
    mrfelis Guest

    Re: How to simulate button click?

    Jim,

    These a good article on VB Net:

    http://www.mvps.org/vbnet/code/intri...uttonpress.htm


    --
    ~~~
    C'Ya,
    mrfelis
    mrfelis@yahoo.NOSPAM.com
    just remove the spam


    Jim Edgar <djedgar@home.com> wrote in message news:39432962@news.devx.com...
    > Serge --
    >
    > The following code snippet (from the 101 VB Tips) might be
    > what you need.
    >
    > Option Explicit
    > 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 BM_CLICK = &HF5
    >
    > Call SendMessage(Command1.hWnd, BM_CLICK, 0, ByVal 0&)
    >
    > Hope it helps,
    >
    > Jim Edgar
    >
    > "Serge" <bouchard.serge@videotron.ca> wrote in message
    > news:3942d549$1@news.devx.com...
    > >
    > > Hi,
    > >
    > > Does someone know a method for sending a message or whatever to simulate
    > > the mouse button click on a "OK" button inside an application runnig

    > beside
    > > my VB application?... I can easily find the handle of this button but i
    > > dont know how to click on the button.. it's surely a fuction or a

    > trapping
    > > of WindowProc but how to do that?? if someone knows then please write

    me
    > > some code in VB to tell me the way
    > >
    > > Thanks
    > > Serge
    > >

    >
    >




  5. #5
    mrfelis Guest

    Re: How to simulate button click?

    Jim,

    These a good article on VB Net:

    http://www.mvps.org/vbnet/code/intri...uttonpress.htm


    --
    ~~~
    C'Ya,
    mrfelis
    mrfelis@yahoo.NOSPAM.com
    just remove the spam


    Jim Edgar <djedgar@home.com> wrote in message news:39432962@news.devx.com...
    > Serge --
    >
    > The following code snippet (from the 101 VB Tips) might be
    > what you need.
    >
    > Option Explicit
    > 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 BM_CLICK = &HF5
    >
    > Call SendMessage(Command1.hWnd, BM_CLICK, 0, ByVal 0&)
    >
    > Hope it helps,
    >
    > Jim Edgar
    >
    > "Serge" <bouchard.serge@videotron.ca> wrote in message
    > news:3942d549$1@news.devx.com...
    > >
    > > Hi,
    > >
    > > Does someone know a method for sending a message or whatever to simulate
    > > the mouse button click on a "OK" button inside an application runnig

    > beside
    > > my VB application?... I can easily find the handle of this button but i
    > > dont know how to click on the button.. it's surely a fuction or a

    > trapping
    > > of WindowProc but how to do that?? if someone knows then please write

    me
    > > some code in VB to tell me the way
    > >
    > > Thanks
    > > Serge
    > >

    >
    >




  6. #6
    christiaan vancraeyenest Guest

    Re: How to simulate button click?


    'Do mouse button action
    Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx
    As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Const MOUSEEVENTF_LEFTDOWN = &H2
    Const MOUSEEVENTF_LEFTUP = &H4
    Const MOUSEEVENTF_RIGHTDOWN = &H8
    Const MOUSEEVENTF_RIGHTUP = &H10

    '****************************************************
    '* Do a left mouse click on current position
    '****************************************************
    Sub Do_LMouseClick()
    Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    End Sub


  7. #7
    christiaan vancraeyenest Guest

    Re: How to simulate button click?


    'Do mouse button action
    Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx
    As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Const MOUSEEVENTF_LEFTDOWN = &H2
    Const MOUSEEVENTF_LEFTUP = &H4
    Const MOUSEEVENTF_RIGHTDOWN = &H8
    Const MOUSEEVENTF_RIGHTUP = &H10

    '****************************************************
    '* Do a left mouse click on current position
    '****************************************************
    Sub Do_LMouseClick()
    Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center