Hallo zusammen,
ich beschäftige mich mal wieder mit einem kleinen Tool. Die Grundfunktionalität ist soweit schon gegeben. Als Letztes möchte ich noch ein kleines Gimmick einfügen, mir dem ich das Formular 'Always On Top' umschaltbar machen kann. Dies möchte ich über das SystemMenu des Formulars bewerkstellingen.
Die Menueinträge, die ich benötige habe ich bereits integriert.
Spoiler anzeigen
Wie schaffe ich das nun, dass ein Haken links neben dem Menueintrag 'Always On Top' je nach boolschem Wert angezeigt wird, oder nicht?
Für Lösungsansätze bin ich wie immer dankbar....
Gruß Michael
ich beschäftige mich mal wieder mit einem kleinen Tool. Die Grundfunktionalität ist soweit schon gegeben. Als Letztes möchte ich noch ein kleines Gimmick einfügen, mir dem ich das Formular 'Always On Top' umschaltbar machen kann. Dies möchte ich über das SystemMenu des Formulars bewerkstellingen.
Die Menueinträge, die ich benötige habe ich bereits integriert.
VB.NET-Quellcode
- #Region "SystemMenu"
- 'Imports System.Runtime.InteropServices
- Private Const MF_STRING As Integer = &H0
- Private Const MF_ENABLED As Int32 = &H0I
- Private Const MF_GRAYED As Int32 = &H1I
- Private Const MF_DISABLED As Integer = &H2I
- Private Const MF_BITMAP As Integer = &H4&
- Private Const MF_SEPARATOR As Integer = &H800&
- Private Const MF_BYCOMMAND As Integer = &H0
- Private Const MF_BYPOSITION As Integer = &H400
- Private Const MF_POPUP As Integer = &H10
- Private Const WM_SYSCOMMAND As Integer = &H112
- ' The constants we'll use to identify our custom system menu items
- Public Const _DynamicLogin As Int32 = 1000
- Public Const _AlwaysOnTop As Int32 = 1001
- <DllImport("user32.dll", CallingConvention:=CallingConvention.Cdecl)> _
- Private Shared Function GetSystemMenu(hWnd As IntPtr, bRevert As Boolean) As IntPtr
- End Function
- <DllImport("user32.dll", CallingConvention:=CallingConvention.Cdecl)> _
- Private Shared Function AppendMenu(hMenu As IntPtr, uFlags As Int32, uIDNewItem As IntPtr, lpNewItem As String) As Boolean
- End Function
- <DllImport("user32.dll", CallingConvention:=CallingConvention.Cdecl)> _
- Private Shared Function InsertMenu(hMenu As IntPtr, uPosition As Integer, uFlags As Integer, uIDNewItem As IntPtr, lpNewItem As String) As Boolean
- End Function
- <DllImport("user32.dll", CallingConvention:=CallingConvention.Cdecl)> _
- Private Shared Function SetMenuItemBitmaps(hMenu As IntPtr, uPosition As Integer, uFlags As Integer, hBitmapUnchecked As IntPtr, hBitmapChecked As IntPtr) As Boolean
- End Function
- Private Sub AddSysMenuItems()
- 'Get the System Menus Handle.
- Dim hSysMenu As IntPtr = GetSystemMenu(Me.Handle, False)
- 'and a separator at position 5.
- InsertMenu(hSysMenu, 5, MF_BYPOSITION Or MF_SEPARATOR, IntPtr.Zero, Nothing)
- Dim hImage As IntPtr = My.Resources.Key.GetHbitmap
- InsertMenu(hSysMenu, 6, MF_BYPOSITION, _DynamicLogin, "Login...")
- SetMenuItemBitmaps(hSysMenu, 6, MF_BYPOSITION, hImage, hImage)
- 'Create a glyph for About MenuItem
- Dim bmpBitmapUnchecked As New Bitmap(16, 16)
- Dim gBitmapUnchecked As Graphics = Graphics.FromImage(bmpBitmapUnchecked)
- gBitmapUnchecked.Clear(Color.White)
- gBitmapUnchecked.Dispose()
- 'Get a gdi bitmap object from our bitmap.
- Dim hImageUnchecked As IntPtr = bmpBitmapUnchecked.GetHbitmap
- bmpBitmapUnchecked.Dispose()
- hImage = My.Resources.check.GetHbitmap()
- InsertMenu(hSysMenu, 7, MF_BYPOSITION, _AlwaysOnTop, "Always on top")
- SetMenuItemBitmaps(hSysMenu, 7, MF_BITMAP Or MF_BYPOSITION, hImageUnchecked, hImage)
- End Sub
- Protected Overrides Sub WndProc(ByRef m As Message)
- ' Check if a System Command has been executed
- If m.Msg = WM_SYSCOMMAND Then
- ' Execute the appropriate code for the System Menu item that was clicked
- Select Case m.WParam.ToInt32()
- Case _DynamicLogin
- If fDynamicLogin.ShowDialog() = Windows.Forms.DialogResult.OK Then
- mPLCSpyTabsLocked = Not mPLCSpyTabsLocked
- CheckStateOfControls()
- If mPLCSpyTabsLocked Then
- If tcPLCSpy.TabPages.Contains(tpPLCSpyPreSelection) Then tcPLCSpy.TabPages.Remove(tpPLCSpyPreSelection)
- Else
- If Not tcPLCSpy.TabPages.Contains(tpPLCSpyPreSelection) Then tcPLCSpy.TabPages.Add(tpPLCSpyPreSelection)
- End If
- HideNotUsedColumns()
- End If
- Exit Select
- Case _AlwaysOnTop
- Exit Select
- End Select
- End If
- MyBase.WndProc(m)
- End Sub
- #End Region
Wie schaffe ich das nun, dass ein Haken links neben dem Menueintrag 'Always On Top' je nach boolschem Wert angezeigt wird, oder nicht?
Für Lösungsansätze bin ich wie immer dankbar....
Gruß Michael