将About加入系统菜单

类别:.NET开发 点击:0 评论:0 推荐:

在VB.net中想要实现这个也很简单,不过需要重载窗口的WndProc过程才能处理WM_SYSCOMMAND消息

具体代码:
    Private Declare Function GetSystemMenu Lib "user32" Alias "GetSystemMenu" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
    Private Declare Function InsertMenu Lib "user32" Alias "InsertMenuA" (ByVal hMenu As Int32, ByVal nPosition As Int32, ByVal wFlags As Int32, ByVal wIDNewItem As Int32, ByVal lpNewItem As String) As Int32
    Private Const MF_BYCOMMAND = &H0&
    Private Const MF_BYPOSITION = &H400&
    Private Const MF_STRING = &H0&
    Private Const MF_SEPARATOR = &H800&
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InsertMenu(GetSystemMenu(Me.Handle.ToInt32, False), 6, MF_BYPOSITION Or MF_STRING, 8888, "关于我...  :)")
        InsertMenu(GetSystemMenu(Me.Handle.ToInt32, False), 7, MF_BYPOSITION Or MF_SEPARATOR, 8889, "")
    End Sub

   
    Private Const WM_SYSCOMMAND As Integer = 274
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_SYSCOMMAND And m.WParam.ToInt32 = 8888 Then
            MsgBox(System.Environment.MachineName)
        End If
        MyBase.WndProc(m)
    End Sub

本文地址:http://com.8s8s.com/it/it45955.htm