我做了一个多文档窗口,现在想当鼠标指向下拉菜单的某一项时,能在状态栏中显示该菜单项的相关提示?该如何实现?谢谢各位。

解决方案 »

  1.   

    在单击某一菜单时:
     MdiFrm.StatusBar1.Panels(1) = "我单击了这个菜单"
      

  2.   

    '判断当前佩选择的菜单项,并在statusbar中显示信息
        Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
          (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
        Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
          (ByVal hwnd As Long, ByVal nIndex As Long) As Long
        Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
          (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, _
          ByVal wParam As Long, ByVal lParam As Long) As Long
        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
        Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
        Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
        
        Public Const GWL_WNDPROC = (-4)
        Public Const WM_MENUSELECT = &H11F
        Public Const MF_BYCOMMAND = &H0&
        Public Const MF_BYPOSITION = &H400&
        
    '判断当前被选中的菜单项,并显示相应信息
    Public Function wndproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long    Dim MenuItemStr As String, SubMenuStr As String
        Dim hSubmenu As Long, MenuId As Long, i As Long
        Dim tmpl As tLong, tmpt As TwoWord
        '以下程式会截取WM_MENUSELECT处理完後,再将之送往原来的Window Procedure
        If Msg = WM_MENUSELECT Then
            SubMenuStr = String(255, 0)
            MenuItemStr = String(255, 0)
        
            tmpl.ll = wParam
            LSet tmpt = tmpl
            MenuId = tmpt.LowWord
        
            hSubmenu = GetSubMenu(lParam, MenuId)
            If hSubmenu = 0 Then '表示该item之下没有popupMenu了
                Call GetMenuString(lParam, MenuId, MenuItemStr, 256, MF_BYCOMMAND)
                MenuItemStr = Left(MenuItemStr, InStr(1, MenuItemStr, Chr(0)) - 1)
                GetMenuInfo MenuItemStr
    '            If Not Trim(MenuItemStr) = "" Then
    '                frmMain.stbStatus.Panels(2).Text = MenuItemStr
    '            End If
            Else
                Call GetMenuString(hMenu, hSubmenu, SubMenuStr, 256, MF_BYCOMMAND)
                SubMenuStr = Left(SubMenuStr, InStr(1, SubMenuStr, Chr(0)) - 1)
                GetMenuInfo SubMenuStr
    '            If Not Trim(MenuItemStr) = "" Then
    '                frmMain.stbStatus.Panels(2).Text = SubMenuStr
    '            End If
            End If
        End If
        '将之送往原来的Window Procedure
        wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
    End Function'在statusbar显示当前菜单信息
    Private Sub DisplayMenu()
        Dim Ret As Long
        hMenu = GetMenu(Me.hwnd)
        '记录原本的Window Procedure的位址
        preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
        '设定Combo1的window Procedure到wndproc
        SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf wndproc
    End Sub
      

  3.   

    谢谢楼上两位!不过,Leftie(Leftie) 可能理解错了我的意思(或许是我没写清楚问题)。
    我要得是yefanqiu(叶帆) 的答案,现在是你的意思我也知道拉,不过,谁能在具体的代码方面给些提示?谢!!
      

  4.   

    fishzone(阿愚-本ID已经消毒) 这是厉害了,太谢谢拉
    我这就试一试!!
      

  5.   

    '还有最后一个函数,自定义的,忘了写进去。其实就是显示字符串那部分。
    '现在只是显示菜单的文字,你可以根据这些文字设定具体要显示的内容。Private Sub GetMenuInfo(str As String)
     '   Str = Left(Str, InStr(1, Str, Chr(0)) - 1)    Dim strMenu As String
        Dim n As Long
        strMenu = ""
        If Not Trim(str) = "" Then
            For n = 1 To Len(str) - 1
                If Mid(str, n, 1) = "(" Then
                    strMenu = Mid(str, 1, n - 1)
                    Exit For
                End If
            Next n
            frmMain.stbStatus.Panels(2).Text = strMenu
        End If
    End Sub