iCAx开思工具箱

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 19431|回复: 0
打印 上一主题 下一主题

[技术交流] Solidworks宏怎么建立弹出菜单

[复制链接]
跳转到指定楼层
楼主
发表于 2015-2-7 09:26:27 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

马上注册登录,享用更多网站功能!

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

x
我用下面代码

   
    Const MF_CHECKED = &H8&
    Const MF_APPEND = &H100&
    Const TPM_LEFTALIGN = &H0&
    Const MF_DISABLED = &H2&
    Const MF_GRAYED = &H1&
    Const MF_SEPARATOR = &H800&
    Const MF_STRING = &H0&
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    Private Declare Function CreatePopupMenu Lib "user32" () As Long
    Private 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, ByVal lprc As Any) As Long
    'Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
    Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Dim hMenu As Long
Sub main()

    Dim swApp As SldWorks.SldWorks
    Dim swModelDoc As SldWorks.ModelDoc2
    Dim swFrame As SldWorks.Frame
   
    Set swApp = Application.SldWorks


    hMenu = CreatePopupMenu()
    'Append a few menu items
    AppendMenu hMenu, MF_STRING, ByVal 0&, "Hello !"
    AppendMenu hMenu, MF_GRAYED Or MF_DISABLED, ByVal 0&, "Testing ..."
    AppendMenu hMenu, MF_SEPARATOR, ByVal 0&, ByVal 0&
    AppendMenu hMenu, MF_CHECKED, ByVal 0&, "TrackPopupMenu"

    Dim Pt As POINTAPI
    'Get the position of the mouse cursor
    GetCursorPos Pt
    Set swFrame = swApp.Frame
    Dim i As Integer
    i = TrackPopupMenu(hMenu, TPM_LEFTALIGN, Pt.x, Pt.y, 0, swFrame.GetHWnd, ByVal 0&)
    MsgBox i
    DestroyMenu hMenu
End Sub
运行时,结果如下
javascript:;

弹出菜单.gif (9.26 KB, 下载次数: 36)

弹出菜单.gif
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 支持支持
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手板模型制作,在线3D打印服务

QQ|小黑屋|手机版|开思工具箱 CAD工具箱_CAM工具箱  

GMT+8, 2024-12-22 02:09 , Processed in 0.016963 second(s), 8 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2024 www.iCAx.org

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