修改系统菜单,鼠标右健弹出菜单,执行系统菜单事件

原创 2003年01月15日 09:22:00

(仅供参考)

向系统菜单中添加新项,并且执行对应事件,在窗体任意位置弹出系统菜单,并且执行事件
'窗体
Option Explicit

Private Sub Form_Load()
    On Error Resume Next
   
    lhSysMenu = GetSystemMenu(hwnd, 0&)
    lRet = AppendMenu(lhSysMenu, MF_SEPARATOR, 0&, vbNullString)
    lRet = AppendMenu(lhSysMenu, MF_STRING, IDM_ABOUT, "About...")
    Show
   
    ProcOld = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim r As RECT
    Dim p As POINTAPI
    If Button = vbRightButton Then
        GetCursorPos p
        TrackPopupMenu lhSysMenu, 0, p.X, p.Y, 0, Me.hwnd, r
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    SetWindowLong hwnd, GWL_WNDPROC, ProcOld
End Sub

'-------------------------------------------------------------
'模块
Option Explicit
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 RECT) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 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 GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Public Type POINTAPI
        X As Long
        Y As Long
End Type
Public ProcOld As Long
Public Const TPM_LEFTALIGN = &H0&
Public Const WM_SYSCOMMAND = &H112
Public Const MF_SEPARATOR = &H800&
Public Const MF_STRING = &H0&
Public Const GWL_WNDPROC = (-4)
Public Const IDM_ABOUT As Long = 1010
Public Const WM_COMMAND = &H111
Public lhSysMenu As Long, lRet As Long

Public Function WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Select Case iMsg
    Case WM_SYSCOMMAND
        If wParam = IDM_ABOUT Then
            MsgBox "VB Web Append to System Menu Example", vbInformation, "About"
            Exit Function
        End If
    Case WM_COMMAND
        If wParam = IDM_ABOUT Then
            MsgBox "VB Web Append to System Menu Example", vbInformation, "About"
            Exit Function
        Else
            CallWindowProc ProcOld, hwnd, WM_SYSCOMMAND, wParam, lParam
            WindowProc = 0
            Exit Function
        End If
    End Select
    WindowProc = CallWindowProc(ProcOld, hwnd, iMsg, wParam, lParam)
End Function

winform 右键点击行时选中行,并弹出操作菜单

①. 添加一个快捷菜单contextMenuStrip1; ②. 给dataGridView1的CellMouseDown事件添加处理程序: private void DataGridView1_...
  • jsjpanxiaoyu
  • jsjpanxiaoyu
  • 2015年07月30日 20:49
  • 3819

Jquery鼠标右键点击弹出菜单

今天分享一个Jquery鼠标右键点击弹出菜单的组合功能。在项目中,主要是用在表格中,点击单元格, 弹出右键菜单,选择下一步的功能。 首先是,右键点击事件的获取: 鼠标的事件e,e.which: ...
  • u010832551
  • u010832551
  • 2016年02月25日 15:16
  • 1376

整理文档,搜刮出一个vue2.0的contextmenu右键弹出菜单的实例代码

整理文档,搜刮出一个vue2.0的contextmenu右键弹出菜单的实例代码,稍微整理精简一下做下分享。  1.事情对象 ? 1 2 3...
  • sinat_39430615
  • sinat_39430615
  • 2017年10月12日 11:37
  • 1895

Win32的菜单编程

    WIN32用户界面设计基础之Menus篇 2003-3-29 13:05:28   YESKY   陈孝强   阅读次数: 4835  一个菜单条总是属于一个窗口,当用户选定一个菜单项后,系统...
  • MikeFeng
  • MikeFeng
  • 2006年05月12日 10:01
  • 7834

QT实现鼠标右键快捷菜单(QTableWidget)

对于右键点击事件,这里用到的是Qt::CustomContextMenu方法,本例通过右点QTableWidget,显示下拉菜单,同时获得点击的行号。 ui界面如下图: //customCon...
  • TanChengkai
  • TanChengkai
  • 2016年08月03日 16:31
  • 2931

如何更改右键菜单?

一、右键菜单大揭密 1、在所有的文件右键菜单中加入命令 如果你的系统上安装有Winzip、UltraEdit等,当你对任一文件点右键时,都会有“Add to zip”、“UltraEdit-32”等命...
  • johnny_83
  • johnny_83
  • 2007年07月22日 09:53
  • 1733

java弹出菜单

import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; clas...
  • qq_33665647
  • qq_33665647
  • 2016年07月19日 15:08
  • 841

JTree不同节点上的右击弹出不同的快捷菜单

这段时间要实现这个功能,在网上只有点哪啊都一样的 快捷菜单,没能具体实现功能。现在问题解决了写下来和大家一块交流。import  javax.swing.*;import java.awt.*;imp...
  • happyandsad
  • happyandsad
  • 2008年03月14日 08:38
  • 3409

webview长按弹出菜单

2012-01-12 16:51 android webview 长按事件处理 webview 中可以增加长按监听事件来弹出菜单。 具体实现下面这个函数即可: //webview 长...
  • Azhuoyanyan
  • Azhuoyanyan
  • 2013年12月24日 16:27
  • 2363

[Dev]DevExpress之treelist右键菜单实现

添加BarManager和popupMenu组件:设置popupMenu组件的Manager属性:右键点击popupMenu主键,点击Customize选项添加菜单代码:using System; u...
  • david_520042
  • david_520042
  • 2016年02月16日 15:56
  • 4796
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:修改系统菜单,鼠标右健弹出菜单,执行系统菜单事件
举报原因:
原因补充:

(最多只允许输入30个字)