|
楼主 |
发表于 2023-2-1 16:02
|
显示全部楼层
- Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- Private Declare PtrSafe Function SetMenu Lib "user32" (ByVal Hwnd As LongPtr, ByVal hMenu As LongPtr) As Long
- Private Declare PtrSafe Function CreateMenu Lib "user32" () As Long
- Private Declare PtrSafe Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As LongPtr, ByVal wFlags As LongPtr, ByVal wIDNewItem As LongPtr, ByVal lpNewItem As Any) As Long
- Private Declare PtrSafe Function DestroyMenu Lib "user32" (ByVal hMenu As LongPtr) As Long
- Private Declare PtrSafe Function CreatePopupMenu Lib "user32" () As Long
- Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As LongPtr, ByVal nIndex As LongPtr, ByVal dwNewLong As LongPtr) As Long
- Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As LongPtr, ByVal nIndex As Long) As Long
- Private Const GWL_WNDPROC = (-4)
- Private Const MF_STRING = &H0&
- Private Const MF_POPUP = &H10&
- Dim MenuWnd As Long
- Dim Dump As Long
- Dim PopupMenuID As Long
- Private Sub UserForm_Initialize()
- Hwnd = FindWindow(vbNullString, Me.Caption)
- MenuWnd = CreateMenu()
- PopupMenuID = CreatePopupMenu()
- Dump = AppendMenu(MenuWnd, MF_STRING + MF_POPUP, PopupMenuID, "采购订单")
- Dump = AppendMenu(PopupMenuID, MF_STRING, 100, "同步采购订单")
- Dump = AppendMenu(PopupMenuID, MF_STRING, 101, "刷新")
- Dump = SetMenu(Hwnd, MenuWnd)
- PreWinProc = GetWindowLong(Hwnd, GWL_WNDPROC)
- SetWindowLong Hwnd, GWL_WNDPROC, AddressOf MsgProcess
- End Sub
- Private Sub UserForm_Terminate()
- DestroyMenu MenuWnd
- DestroyMenu PopupMenuID
- SetWindowLong Hwnd, GWL_WNDPROC, PreWinProc
- End Sub
复制代码- Private Declare PtrSafe Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As LongPtr, ByVal Hwnd As LongPtr, ByVal Msg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long
- Public PreWinProc As LongPtr, Hwnd As LongPtr
- Public Function MsgProcess(ByVal Hwnd As LongPtr, ByVal Msg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
- Select Case wParam.Value
- Case 100
- MsgBox "订单同步"
- Case 101
- MsgBox "刷新"
- Case Else
- MsgProcess = CallWindowProc(PreWinProc, Hwnd, Msg, wParam, lParam)
- End Select
- End Function
复制代码 |
|