Home All Groups Group Topic Archive Search About
Author
21 Mar 2006 7:13 PM
Rick
How can you click on a menu, virtually?(programatically speaking)
an API call?

VB6, please...
--
Rick

Author
21 Mar 2006 8:18 PM
Veign
If what way do you mean?

If its within your application than create a function that is called from
the menu click event and call this from anywhere else you want the menu item
code executed.



--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


Show quote
"Rick" <R***@discussions.microsoft.com> wrote in message
news:DBA44A00-BD88-48A8-AE0A-DD840A3EF513@microsoft.com...
> How can you click on a menu, virtually?(programatically speaking)
> an API call?
>
> VB6, please...
> --
> Rick
Author
21 Mar 2006 8:35 PM
Tom Esh
On Tue, 21 Mar 2006 11:13:28 -0800, Rick
<R***@discussions.microsoft.com> wrote:

>How can you click on a menu, virtually?(programatically speaking)
>an API call?
>
>VB6, please...

Usually by sending or posting (SendMessage, PostMessage) a WM_COMMAND
message with the menu item's ID in wParam to the menu's owner window.
You can use the Spy++ tool to obtain the ID. The owner hwnd of course
must be obtained at runtime.
Note this assumes it's really a windows menu, for example like Notepad
uses, and not some menu-like or toolbar dropdown control. Also it may
or may not work with popup (context) menus depending on how the app's
author chose to handle them.

Ex:
'Declares...
Public Const WM_COMMAND = &H111
Public Declare Function PostMessage Lib "user32" _
    Alias "PostMessageA" _
    (ByVal hWnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, lParam As Any) As Long
Public Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

'usage...
'simulate click on menu item with ID 6
    Dim hwndOwner As Long

    'find owner hwnd from it's caption text...
    hwndOwner = FindWindow(vbNullString, "caption text here")

    If hwndOwner <> 0 Then 'found
        'post the msg...
        PostMessage hwndOwner, WM_COMMAND, 6, ByVal 0&
    End If


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
Author
21 Mar 2006 9:17 PM
Rick
Maybe this is wierd, but I'm trying to hav e a popmenu but it shows at the
beginning
but after I made a query(DAO) and the grid becomes populated (where I made
the right button mouse click), it doesn't show the popupmenu.

The menus are dynamically created.
So, I resorted to use normal dynamic menus(not hidden) and I wanted to
create a virtual click so the user could make the selection from the submenus.

Weird? How can solve the first problem? any ideas?




--
Rick


Show quote
"Tom Esh" wrote:

> On Tue, 21 Mar 2006 11:13:28 -0800, Rick
> <R***@discussions.microsoft.com> wrote:
>
> >How can you click on a menu, virtually?(programatically speaking)
> >an API call?
> >
> >VB6, please...
>
> Usually by sending or posting (SendMessage, PostMessage) a WM_COMMAND
> message with the menu item's ID in wParam to the menu's owner window.
> You can use the Spy++ tool to obtain the ID. The owner hwnd of course
> must be obtained at runtime.
> Note this assumes it's really a windows menu, for example like Notepad
> uses, and not some menu-like or toolbar dropdown control. Also it may
> or may not work with popup (context) menus depending on how the app's
> author chose to handle them.
>
> Ex:
> 'Declares...
> Public Const WM_COMMAND = &H111
> Public Declare Function PostMessage Lib "user32" _
>     Alias "PostMessageA" _
>     (ByVal hWnd As Long, ByVal wMsg As Long, _
>     ByVal wParam As Long, lParam As Any) As Long
> Public Declare Function FindWindow Lib "user32" _
>     Alias "FindWindowA" _
>     (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
>
> 'usage...
> 'simulate click on menu item with ID 6
>     Dim hwndOwner As Long
>    
>     'find owner hwnd from it's caption text...
>     hwndOwner = FindWindow(vbNullString, "caption text here")
>
>     If hwndOwner <> 0 Then 'found
>         'post the msg...
>         PostMessage hwndOwner, WM_COMMAND, 6, ByVal 0&
>     End If
>
>
> -Tom
> MVP - Visual Basic
> (please post replies to the newsgroup)
>
Author
21 Mar 2006 9:30 PM
Rick
Sorry folks. I solved the problem.
For the ones interested: I created the menus right after the queries.
(not on the mousedown event on the grid!).



--
Rick


Show quote
"Rick" wrote:

> Maybe this is wierd, but I'm trying to hav e a popmenu but it shows at the
> beginning
> but after I made a query(DAO) and the grid becomes populated (where I made
> the right button mouse click), it doesn't show the popupmenu.
>
> The menus are dynamically created.
> So, I resorted to use normal dynamic menus(not hidden) and I wanted to
> create a virtual click so the user could make the selection from the submenus.
>
> Weird? How can solve the first problem? any ideas?
>
>
>
>
> --
> Rick
>
>
> "Tom Esh" wrote:
>
> > On Tue, 21 Mar 2006 11:13:28 -0800, Rick
> > <R***@discussions.microsoft.com> wrote:
> >
> > >How can you click on a menu, virtually?(programatically speaking)
> > >an API call?
> > >
> > >VB6, please...
> >
> > Usually by sending or posting (SendMessage, PostMessage) a WM_COMMAND
> > message with the menu item's ID in wParam to the menu's owner window.
> > You can use the Spy++ tool to obtain the ID. The owner hwnd of course
> > must be obtained at runtime.
> > Note this assumes it's really a windows menu, for example like Notepad
> > uses, and not some menu-like or toolbar dropdown control. Also it may
> > or may not work with popup (context) menus depending on how the app's
> > author chose to handle them.
> >
> > Ex:
> > 'Declares...
> > Public Const WM_COMMAND = &H111
> > Public Declare Function PostMessage Lib "user32" _
> >     Alias "PostMessageA" _
> >     (ByVal hWnd As Long, ByVal wMsg As Long, _
> >     ByVal wParam As Long, lParam As Any) As Long
> > Public Declare Function FindWindow Lib "user32" _
> >     Alias "FindWindowA" _
> >     (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
> >
> > 'usage...
> > 'simulate click on menu item with ID 6
> >     Dim hwndOwner As Long
> >    
> >     'find owner hwnd from it's caption text...
> >     hwndOwner = FindWindow(vbNullString, "caption text here")
> >
> >     If hwndOwner <> 0 Then 'found
> >         'post the msg...
> >         PostMessage hwndOwner, WM_COMMAND, 6, ByVal 0&
> >     End If
> >
> >
> > -Tom
> > MVP - Visual Basic
> > (please post replies to the newsgroup)
> >

AddThis Social Bookmark Button