• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

添加菜单到系统菜单

发布: 2007-7-01 21:48 | 作者: admin | 来源: | 查看: 11次 | 进入软件测试论坛讨论

领测软件测试网

添加菜单到系统菜单

Private Sub Form_Load()

    OldWindowProc = GetWindowLong(Form1.hwnd, GWL_WNDPROC)
    ´ 取得窗口函数的地址
    Call SetWindowLong(Form1.hwnd, GWL_WNDPROC, AddressOf SubClass1_WndMessage)
    ´ 用SubClass1_WndMessage代替窗口函数处理消息

    SysMenuHwnd = GetSystemMenu(Form1.hwnd, False)

    Call AppendMenu(SysMenuHwnd, MF_SEPARATOR, 2000, vbNullString)
    Call AppendMenu(SysMenuHwnd, MF_STRING, 2001, "关于本程序(&A)")
    Call AppendMenu(SysMenuHwnd, MF_SEPARATOR, 2002, vbNullString)
    Call AppendMenu(SysMenuHwnd, MF_STRING, 2003, "恢复系统菜单(&R)")
End Sub

Private Sub Form_Unload(Cancel As Integer)
    If OldWindowProc <> GetWindowLong(Form1.hwnd, GWL_WNDPROC) Then
        Call SetWindowLong(Form1.hwnd, GWL_WNDPROC, OldWindowProc)
    End If
End Sub

Option Explicit

´ API函数声明
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long,
ByVal nIndex As Long) 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 GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long)
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 Any) As Long
Public 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

´ 常数声明
Public Const WM_SYSCOMMAND = &H112
´ 单击控制框产生此消息
Public Const MF_SEPARATOR = &H800&
´ 为菜单加一条分隔线
Public Const MF_STRING = &H0&
´ 在菜单中加一个字符串
Public Const GWL_WNDPROC = (-4)

´ 全局变量
Public OldWindowProc As Long
´ 保存默认的窗口函数地址
Public SysMenuHwnd As Long
´ 保存系统菜单句柄

Public Function SubClass1_WndMessage(ByVal hwnd As Long, ByVal Msg As Long, ByVal wp As Long,
ByVal lp As Long) As Long
    If Msg <> WM_SYSCOMMAND Then
        SubClass1_WndMessage = CallWindowProc(OldWindowProc, hwnd, Msg, wp, lp)
        ´ 如果消息不是WM_SYSCOMMAND,就调用默认的窗口函数处理
        Exit Function
    End If

    Select Case wp
        Case 2001
            Call MsgBox("本程序实现了修改系统菜单的功能  ", vbOKOnly + vbInformation)
        Case 2003
            Call GetSystemMenu(Form1.hwnd, True)
            Call SetWindowLong(Form1.hwnd, GWL_WNDPROC, OldWindowProc)
            Call MsgBox("已经恢复了默认的系统菜单  ", vbOKOnly + vbInformation)
        Case Else
            SubClass1_WndMessage = CallWindowProc(OldWindowProc, hwnd, Msg, wp, lp)
            Exit Function
    End Select

    SubClass1_WndMessage = True

End Function

 

       以上代码来自: 源代码数据库(SourceDataBase)
           当前版本: 1.0.538
               作者: Shawls
           个人主页:
             E-Mail:
                 QQ: 9181729


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网