Results 1 to 7 of 7

Thread: using API, how to send message to click menu item programmatically..

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    7

    Thumbs up using API, how to send message to click menu item programmatically..

    Hi

    the problem :

    how to click menu item using Windows API programmatically , i have the window handle for Menu.

    please help me out ....

    Adesh. ( adesh_y@yahoo.com )

  2. #2
    New Member
    Join Date
    Aug 2002
    Posts
    2

    Click a menu item

    Call SendMessage( X, WM_COMMAND, Y, ByVal 0)

    X = Handle to the owner window
    Y = menu item ID

    *get the item id using the GetMenuItemID function

  3. #3
    Junior Member scrapersNbots.com's Avatar
    Join Date
    Dec 2016
    Location
    Torrington, CT
    Posts
    25

    Re: using API, how to send message to click menu item programmatically..

    You could do PopUp Menu for the menu item which will cause it to show near your mouse instead of at the menu bar, can probably mess with x and y to fix that. Scrapers〘N〙Bots
    〘SCRAPER〙software that extracts, organizes and displays data from the web.
    〘BOT〙software that automates and speeds up tasks on the web, mimicking human behavior.

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621

    Re: using API, how to send message to click menu item programmatically..

    you can get the rest of the required info with spy++. You can also send alt-keystrokes if the menu supports them.
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

  5. #5
    Junior Member scrapersNbots.com's Avatar
    Join Date
    Dec 2016
    Location
    Torrington, CT
    Posts
    25

    Re: using API, how to send message to click menu item programmatically..

    Quote Originally Posted by adesh View Post
    Hi

    the problem :

    how to click menu item using Windows API programmatically , i have the window handle for Menu.

    please help me out ....

    Adesh. ( adesh_y@yahoo.com )

    Here is what to do.

    [1] Make a shortcut key for the menu item
    [2] to open the menu run this code changing the "%f" to whatever the appropriate sendkeys is.


    Sub subSendAltF()

    Dim wshShell: Set wshShell = CreateObject("WScript.Shell")

    If Not (wshShell Is Nothing) Then
    wshShell.SendKeys "%f"
    DoEvents
    Set wshShell = Nothing
    End If

    End Sub
    〘SCRAPER〙software that extracts, organizes and displays data from the web.
    〘BOT〙software that automates and speeds up tasks on the web, mimicking human behavior.

  6. #6
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,625

    Re: using API, how to send message to click menu item programmatically..

    You know... I got my start as a 90s teen on AOL making addons. Clicking menus was a big part of it back in the day. None of my code survives, but I've got a module from someone elses...

    Code:
    Public Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
    Public Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Public Declare Function GetMenuString Lib "user32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long
    Public Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Public Sub RunMenuByString(SearchString As String)
        Dim AOL As Long, aMenu As Long, mCount As Long
        Dim LookFor As Long, sMenu As Long, sCount As Long
        Dim LookSub As Long, sID As Long, sString As String
        AOL& = FindWindow("AOL Frame25", vbNullString)
        aMenu& = GetMenu(AOL&)
        mCount& = GetMenuItemCount(aMenu&)
        For LookFor& = 0& To mCount& - 1
            sMenu& = GetSubMenu(aMenu&, LookFor&)
            sCount& = GetMenuItemCount(sMenu&)
            For LookSub& = 0 To sCount& - 1
                sID& = GetMenuItemID(sMenu&, LookSub&)
                sString$ = String$(100, " ")
                Call GetMenuString(sMenu&, sID&, sString$, 100&, 1&)
                If InStr(LCase(sString$), LCase(SearchString$)) Then
                    Call SendMessage(AOL&, WM_COMMAND, sID&, ByVal 0&)
                    Exit Sub
                End If
            Next LookSub&
        Next LookFor&
    End Sub
    You'd replace AOL with your window handle.

    Edit: ...no I didn't see the dates before the last post

  7. #7
    New Member
    Join Date
    Feb 2022
    Posts
    5

    Re: using API, how to send message to click menu item programmatically..

    Thanks for your code, it helped me select some menus in Adobe Reader.

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