Home All Groups Group Topic Archive Search About

System Menu (On Top) VB.NET 2003

Author
4 May 2007 8:01 PM
Newbie Coder
Hi All

It's rare for me to ask a question in this newsgroup

VB.NET 2003 ONLY - FRAMEWORK 1.1
--------------------------------------------------

How do I check/uncheck an extended System Menu item & handle the Click
Event?

Imports System.Runtime.InteropServices

    <DllImport("user32")> _
    Public Shared Function GetSystemMenu(ByVal hwnd As IntPtr, _
        ByVal bRevert As Boolean) As IntPtr
    End Function

    <DllImport("user32")> _
    Public Shared Function AppendMenu(ByVal hMenu As IntPtr, _
        ByVal wFlags As MenuFlags, ByVal wIDNewItem As Int32, _
        ByVal lpNewItem As String) As Boolean
    End Function

    <Flags()> _
    Public Enum MenuFlags As Integer
        MF_BYPOSITION = 1024
        MF_REMOVE = 4096
        MF_SEPARATOR = 2048
        MF_STRING = 0
    End Enum

    Private Const WM_SYSCOMMAND As Integer = &H112

Form Load Event:

     Dim ptrHandle As IntPtr = GetSystemMenu(Me.Handle, False)
     AppendMenu(ptrHandle, MenuFlags.MF_SEPARATOR, 1000, "") 'Seperator
     AppendMenu(ptrHandle, MenuFlags.MF_STRING, 1001, "On Top") ' New Menu
Item

WndProc:

#Region "WndProc (SUB)"

    Protected Overrides Sub WndProc(ByRef m As Message)
        If m.Msg = WM_SYSCOMMAND Then
            Select Case m.WParam.ToInt32
                Case 1000 'Do nothing as it's seperator
                Case 1001
                   ' Handle The TopMost Click Event Here
            End Select
        End If
        MyBase.WndProc(m)
    End Sub

#End Region

------------------------------------

The way I want the System Menu to be handles is like so:

MenuItem.Checked = Not MenuItem.Checked
Me.TopMost = MenuItem.Checked

Any ideas?

Thanks in advance

Author
6 May 2007 9:57 PM
Mattias Sjögren
>How do I check/uncheck an extended System Menu item & handle the Click
>Event?

Use the CheckMenuItem or SetMenuItemInfo function.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
8 May 2007 9:56 PM
Newbie Coder
Mattias,

SYSTEM MENU not standard menu

I have asked this question in C++ & VB.NET 2003 & no-one can come up with an
answer & your suggestion is completely wrong

Thanks for taking the time to TRY to help me though

--
Newbie Coder
(It's just a name)





Show quoteHide quote
"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
news:OuamTlCkHHA.1240@TK2MSFTNGP04.phx.gbl...
> >How do I check/uncheck an extended System Menu item & handle the Click
> >Event?
>
> Use the CheckMenuItem or SetMenuItemInfo function.
>
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP]  mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.