明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1285|回复: 0

[求助]请版主们帮我调试一下该快捷菜单的程序

[复制链接]
发表于 2005-7-6 11:48:00 | 显示全部楼层 |阅读模式
在VB下是可以完全执行的,我转成VBA时,连续执行就会退出cad, 请版主们帮我调试一下该快捷菜单的程序,感谢! 相应vb程序代码: '模块
Option Explicit Public Const mFileId1 = &H1&
Public Const mFileId2 = &H2& Public Const TPM_LEFTALIGN = &H0&
Public Const TPM_LEFTBUTTON = &H0&
Public Const MF_STRING = &H0&
Public Const GWL_WNDPROC = (-4)
Public Const WM_COMMAND = &H111 Public OldWinProc As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public 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
Public Declare Function CreatePopupMenu Lib "user32" () As Long
Public Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As String) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function GetActiveWindow Lib "user32" () As Long
Public Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As Any) As Long
Public Type POINTAPI
x As Long
y As Long
End Type Public Function NewWindowProc(ByVal inHWND As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_COMMAND Then
If wParam = mFileId1 Then
MsgBox "菜单1"
Exit Function
End If
If wParam = mFileId2 Then
MsgBox "菜单2"
Exit Function
End If
End If
NewWindowProc = CallWindowProc(OldWinProc, inHWND, Msg, wParam, lParam)
End Function
'窗体
Option Explicit
Private Sub Form_Load()
OldWinProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim lResult As Long, hPopupMenu As Long

If Button = 2 Then

hPopupMenu = CreatePopupMenu()

lResult = AppendMenu(hPopupMenu, MF_STRING, mFileId1, "菜单1")
lResult = AppendMenu(hPopupMenu, MF_STRING, mFileId2, "菜单2")

Dim Pt As POINTAPI

GetCursorPos Pt
lResult = TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN Or TPM_LEFTBUTTON, Pt.x, Pt.y, 0, GetActiveWindow, 0&)
End If
End Sub

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 12:43 , Processed in 0.184327 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表