CSDN博客

img 40Star

将About加入系统菜单

发表于2002/8/26 11:28:00  892人阅读

分类: Visual Basic .net

在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

0 0

相关博文

我的热门文章

img
取 消
img