zoukankan      html  css  js  c++  java
  • 自定义标题栏右键菜单

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

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

    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    
    Public 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
        <DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
        Private Shared Function GetSystemMenu(hWnd As IntPtr, bRevert As Boolean) As IntPtr
        End Function
    
        <DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
        Private Shared Function AppendMenu(hMenu As IntPtr, uFlags As Integer, uIDNewItem As Integer, lpNewItem As String) As Boolean
        End Function
    
        <DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
        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 Sub
    End Class
    

      

  • 相关阅读:
    Spring Boot SockJS应用例子
    Spring Boot+STOMP解决消息乱序问题
    Spring boot集成Websocket,前端监听心跳实现
    吐槽Windows 8,就没见过这么烂的平板操作系统
    怎样在MyEclipse上耍Chrome
    HDOJ 4876 ZCC loves cards
    IIS7.5 配置 PHP 5.3.5
    关于ANDROID模拟器的一些事
    性能測试命令字段解释
    排序算法复习
  • 原文地址:https://www.cnblogs.com/hironpan/p/6817721.html
Copyright © 2011-2022 走看看