API声明和常量声明我就不粘了:
Public Sub Hook(frm As Form)0D
Set appForm = frm
gHW = frm.hwnd
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProcEx)
0AEnd Sub
Public Sub UnHook()
Dim lReturnValue As Long0D
lReturnValue = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub
Public Sub FindHiLight(theForm As Form)
Dim hMenu As Long
Dim hSubMenu As Long
Dim i As Long
Dim MenuCount As Long
0A
frmTest.Caption = ""
hMenu = GetMenu(theForm.hwnd)
If hMenu <> 0 Then
MenuCount = GetMenuItemCount(hMenu)
theForm.Label2 = CStr(MenuCount)
For i = 0 To MenuCount - 1
If GetMenuState(hMenu, i, MF_BYPOSITION) And _
MF_HILITE Then
hSubMenu = GetSubMenu(hMenu, i)
WalkSubMenu hSubMenu
End If
Next i
End If
End Sub
Private Function GetDescription(MenuCaption As String) As String
Select Case MenuCaption
Case "New"
GetDescription = "Creates a new document"
0A Case "Open"
GetDescription = "Opens a Document"
Case "Close"
GetDescription = "Closes Document"
Case "Cut"
GetDescription = "Cuts Selection to Clipboard"
Case "Copy"
GetDescription = "Copies Selection to Clipboard"
Case "Paste"
GetDescription = "Pastes Contents of Clipboard"
Case "Normal"
GetDescription = "Regular Paste"
Case "Special"
GetDescription = "Special Paste"
Case Else
GetDescription = "other"
End Select
End Function
Private Sub WalkSubMenu(hSubMenu As Long)
Dim i As Long
Dim MenuItems As Long
0A Dim hSubSubMenu As Long
Dim buffer As String
Dim result As Long
MenuItems = GetMenuItemCount(hSubMenu)
For i = 0 To MenuItems - 1
If GetMenuState(hSubMenu, i, MF_BYPOSITION) And _
MF_HILITE Then0D
hSubSubMenu = GetSubMenu(hSubMenu, i)
If hSubSubMenu And AnyLit(hSubSubMenu) Then
WalkSubMenu hSubSubMenu
Else 'This is it.
buffer = Space(255)
result = GetMenuString(hSubMenu, i, buffer, _
Len(buffer), MF_BYPOSITION)
buffer = Left$(buffer, result)
frmTest.Caption = GetDescription(buffer)
Exit Sub
End If
End If
Next i
End Sub
Function AnyLit(hSubSubMenu As Long) As Long
Dim i As Long
Dim MenuCount As Long
0A
MenuCount = GetMenuItemCount(hSubSubMenu)
For i = 0 To MenuCount - 1
If GetMenuState(hSubSubMenu, i, MF_BYPOSITION) And _
MF_HILITE Then0D
AnyLit = True
Exit Function
0A End If
Next i
AnyLit = False
End Function
Function WindowProcEx(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Select Case uMsg
Case WM_MENUSELECT
0A FindHiLight frmTest
End Select
WindowProcEx = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)0D
End Function
==============================
我得龌龊女友
============================
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hwnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long
Private Sub LoadRes()
Dim I As Long
For I = 1 To 11
ImgList1.ListImages.Add , , LoadResPicture(I + 100, vbResIcon)
Next I
WM_MENUSELECT
The WM_MENUSELECT message is sent to a menu's owner window when the user selects a menu item.
WM_MENUSELECT
uItem = (UINT) LOWORD(wParam); // menu item or submenu index
fuFlags = (UINT) HIWORD(wParam); // menu flags
hmenu = (HMENU) lParam; // handle to menu clicked
Parameters
uItem
Value of the low-order word of wParam. If the selected item is a command item, this parameter contains the identifier of the menu item. If the selected item opens a drop-down menu or submenu, this parameter contains the menu index of the drop-down menu or submenu in the main menu, and the hMenu parameter then contains the handle to the main (clicked) menu; use the GetSubMenu function to get the menu handle to the drop-down menu or submenu.
fuFlags
Value of the high-order word of wParam. Specifies one or more menu flags. This parameter can be a combination of the following values: Value Description
MF_BITMAP Item displays a bitmap.
MF_CHECKED Item is checked.
MF_DISABLED Item is disabled.
MF_GRAYED Item is grayed.
MF_HILITE Item is highlighted.
MF_MOUSESELECT Item is selected with the mouse.
MF_OWNERDRAW Item is an owner-drawn item.
MF_POPUP Item opens a drop-down menu or submenu.
MF_SYSMENU Item is contained in the window menu (also known as the System menu or Control menu). The hmenu parameter identifies the window menu associated with the message.
hmenu
Value of lParam. Handle to the menu that was clicked.
Return Values
If an application processes this message, it should return zero.
Remarks
If the fuFlags parameter contains 0xFFFF and the hmenu parameter contains NULL, the system has closed the menu.
Do not use the value –1 for fuFlags. That is because fuFlags is specified as (UINT) HIWORD(wParam). If HIWORD(wParam) were 0xFFFF, fuFlags (because of the UINT cast) would be 0x0000FFFF, not –1.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winuser.h.
1>如果StatusBar的style属性为0-sbrnormal,用StatusBar的simpletext属性
例:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
StatusBar1.Panels(1).Text = "Picture1_MouseMove"
End Sub
2>如果StatusBar的style属性为1-sbrSimple,用StatusBar的simpletext属性
例:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
StatusBar1.simpleText = "Picture1_MouseMove"
End Sub