博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自定义标题栏右键菜单
阅读量:4697 次
发布时间:2019-06-09

本文共 1819 字,大约阅读时间需要 6 分钟。

摘自:http://stackoverflow.com/questions/4615940/how-can-i-customize-the-system-menu-of-a-windows-form

在单击窗体左上角图标,或标题栏右击时,显示自定义菜单

 

Imports System.Windows.FormsImports System.Runtime.InteropServicesPublic Class CustomForm    Inherits Form    ' P/Invoke constants    Private Const WM_SYSCOMMAND As Integer = &H112    Private Const MF_STRING As Integer = &H0    Private Const MF_SEPARATOR As Integer = &H800    ' P/Invoke declarations    
Private Shared Function GetSystemMenu(hWnd As IntPtr, bRevert As Boolean) As IntPtr End Function
Private Shared Function AppendMenu(hMenu As IntPtr, uFlags As Integer, uIDNewItem As Integer, lpNewItem As String) As Boolean End Function
Private Shared Function InsertMenu(hMenu As IntPtr, uPosition As Integer, uFlags As Integer, uIDNewItem As Integer, lpNewItem As String) As Boolean End Function ' ID for the About item on the system menu Private SYSMENU_ABOUT_ID As Integer = &H1 Public Sub New() End Sub Protected Overrides Sub OnHandleCreated(e As EventArgs) MyBase.OnHandleCreated(e) ' Get a handle to a copy of this form's system (window) menu Dim hSysMenu As IntPtr = GetSystemMenu(Me.Handle, False) ' Add a separator AppendMenu(hSysMenu, MF_SEPARATOR, 0, String.Empty) ' Add the About menu item AppendMenu(hSysMenu, MF_STRING, SYSMENU_ABOUT_ID, "&About…") End Sub Protected Overrides Sub WndProc(ByRef m As Message) MyBase.WndProc(m) ' Test if the About item was selected from the system menu If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SYSMENU_ABOUT_ID Then MessageBox.Show("Custom About Dialog") End If End SubEnd Class

  

转载于:https://www.cnblogs.com/hironpan/p/6817721.html

你可能感兴趣的文章
翻译:TRUNCATE TABLE(已提交到MariaDB官方手册)
查看>>
ASP.NET MVC 5 自动生成的代码框架
查看>>
在ASP.NET Core 2.2 中创建 Web API并结合Swagger
查看>>
新装Windows 2003 + IIS 6.0的问题
查看>>
http基础
查看>>
学习Selenium 自动化从一张藏宝图开始
查看>>
第一次冲刺阶段(五)
查看>>
Android ADB 用法
查看>>
Chaos网络库(三)- 主循环及异步消息的实现
查看>>
Oracle EBS 查看执行计划
查看>>
获取 Transaction Source
查看>>
iOS设计模式汇总
查看>>
win7 64下安装mysql-python报错的解决办法
查看>>
【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之集群概念介绍(一)
查看>>
Java内部类
查看>>
SQL Server 2008杀数据库连接
查看>>
ExtJs自学教程(1):一切从API開始
查看>>
MfC 进度条控件
查看>>
java推断字符串是否为乱码
查看>>
设计牛人——设计入门答疑番外篇有感
查看>>