Results 1 to 3 of 3

Thread: Clicking and Disabling Menus

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210
    How do i click a menu in another application using API, and how do i disable a sub menu like:

    File-
    --Open
    --Save


    how would i go about disabling the open menu? Thanks
    < o >

  2. #2
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    you will have to send the WM_COMMAND message. don't have the exact code now, have seen it on the forum, but search is disabled

    To disable menuitems


    Code:
    Private Const MIIM_SUBMENU = &H4
    Private Const MIIM_STATE = &H1
    Private Const MFS_GRAYED = &H1
    Private Const MFS_ENABLED = &H0
    
    
    Private Type MENUITEMINFO
      cbSize As Long
      fMask As Long
      fType As Long
      fState As Long
      wID As Long
      hSubMenu As Long
      hbmpChecked As Long
      hbmpUnchecked As Long
      dwItemData As Long
      dwTypeData As String
      cch As Long
    End Type
    Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As Boolean, lpmii As MENUITEMINFO) As Long
    Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal uItem As Long, ByVal fByPosition As Long, lpmii As MENUITEMINFO) As Long
    Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    
    Private Sub SetEnabled(bEnabled As Boolean, hWnd As Long, index As Integer)
    
        Dim hMenu As Long, hSubMenu As Long, MII As MENUITEMINFO
        'get the handle of the current menu
        hMenu = GetMenu(hWnd)
        'get the handle of the first submenu
        hSubMenu = GetSubMenu(hMenu, index)
        'initialize the structure
        
        MII.cbSize = Len(MII)
        
        MII.fMask = MIIM_STATE 'state mask
        If bEnabled Then
            MII.fState = MFS_ENABLED
        Else
            MII.fState = MFS_GRAYED 'gray menu item
        End If
        SetMenuItemInfo hSubMenu, 0, True, MII
    End Sub
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  3. #3
    Member
    Join Date
    Aug 2001
    Location
    BX, NY
    Posts
    42

    Disable the Save sub item

    How would you go about disabling the "Save" submenu item?

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