Results 1 to 10 of 10

Thread: Forms System Menu..? [done] fell like i've been talking to myself in here

  1. #1

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Forms System Menu..? [done] fell like i've been talking to myself in here

    How would I go about appending an item to a window forms system menu. In VB6 I would do this with the Win32 API does anyone know if it is easier now or if I will still need to bust out the API?
    Last edited by Magiaus; Apr 11th, 2002 at 05:45 PM.
    Magiaus

    If I helped give me some points.

  2. #2

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    GetSystemMenu..?

    is that it GetSystemMenu and AppendMenuItem..? I figured there would be a easier way now..?
    Magiaus

    If I helped give me some points.

  3. #3

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    ok

    here is how i would do what i want to do in vb6 this code is right off vbapi.com

    VB Code:
    1. Public Declare Function GetSystemMenu Lib "user32.dll" (ByVal hWnd As Long, ByVal bRevert _
    2.     As Long) As Long
    3. Public Declare Function GetMenuItemCount Lib "user32.dll" (ByVal hMenu As Long) As Long
    4. Public Type MENUITEMINFO
    5.     cbSize As Long
    6.     fMask As Long
    7.     fType As Long
    8.     fState As Long
    9.     wID As Long
    10.     hSubMenu As Long
    11.     hbmpChecked As Long
    12.     hbmpUnchecked As Long
    13.     dwItemData As Long
    14.     dwTypeData As String
    15.     cch As Long
    16. End Type
    17. Public Const MIIM_STATE = &H1
    18. Public Const MIIM_ID = &H2
    19. Public Const MIIM_TYPE = &H10
    20. Public Const MFT_SEPARATOR = &H800
    21. Public Const MFT_STRING = &H0
    22. Public Const MFS_ENABLED = &H0
    23. Public Const MFS_CHECKED = &H8
    24. Public Declare Function InsertMenuItem Lib "user32.dll" Alias "InsertMenuItemA" (ByVal _
    25.     hMenu As Long, ByVal uItem As Long, ByVal fByPosition As Long, lpmii _
    26.     As MENUITEMINFO) As Long
    27. Public Declare Function SetMenuItemInfo Lib "user32.dll" Alias "SetMenuItemInfoA" (ByVal _
    28.     hMenu As Long, ByVal uItem As Long, ByVal fByPosition As Long, lpmii _
    29.     As MENUITEMINFO) As Long
    30.  
    31. Public Declare Function SetWindowPos Lib "user32.dll" (ByVal hWnd As Long, ByVal _
    32.     hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal _
    33.     cy As Long, ByVal wFlags As Long) As Long
    34. Public Const HWND_TOPMOST = -1
    35. Public Const HWND_NOTOPMOST = -2
    36. Public Const SWP_NOMOVE = &H2
    37. Public Const SWP_NOSIZE = &H1
    38. Public Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd _
    39.     As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    40. Public Const GWL_WNDPROC = -4
    41. Public Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal _
    42.     lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam _
    43.     As Long, ByVal lParam As Long) As Long
    44. Public Const WM_SYSCOMMAND = &H112
    45. Public Const WM_INITMENU = &H116
    46.  
    47. ' Add an option to make window Form1 "Always On Top" to the bottom of its system
    48. ' menu.  A check mark appears next to this option when active.  The menu item acts as a toggle.
    49. ' Note how subclassing the window is necessary to process the two messages needed
    50. ' to give the added system menu item its full functionality.
    51.  
    52. ' *** Place the following code in a module. ***
    53.  
    54. Public pOldProc As Long  ' pointer to Form1's previous window procedure
    55. Public ontop As Boolean  ' identifies if Form1 is always on top or not
    56.  
    57. ' The following function acts as Form1's window procedure to process messages.
    58. Public Function WindowProc (ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam _
    59.         As Long, ByVal lParam As Long) As Long
    60.     Dim hSysMenu As Long     ' handle to Form1's system menu
    61.     Dim mii As MENUITEMINFO  ' menu item information for Always On Top
    62.     Dim retval As Long       ' return value
    63.    
    64.     Select Case uMsg
    65.     Case WM_INITMENU
    66.         ' Before displaying the system menu, make sure that the Always On Top
    67.         ' option is properly checked.
    68.         hSysMenu = GetSystemMenu(hwnd, 0)
    69.         With mii
    70.             ' Size of the structure.
    71.             .cbSize = Len(mii)
    72.             ' Only use what needs to be changed.
    73.             .fMask = MIIM_STATE
    74.             ' If Form1 is now always on top, check the item.
    75.             .fState = MFS_ENABLED Or IIf(ontop, MFS_CHECKED, 0)
    76.         End With
    77.         retval = SetMenuItemInfo(hSysMenu, 1, 0, mii)
    78.         WindowProc = 0
    79.     Case WM_SYSCOMMAND
    80.         ' If Always On Top (ID = 1) was selected, change the on top/not on top
    81.         ' setting of Form1 to match.
    82.         If wParam = 1 Then
    83.             ' Reverse the setting and make it the current one.
    84.             ontop = Not ontop
    85.             retval = SetWindowPos(hwnd, IIf(ontop, HWND_TOPMOST, HWND_NOTOPMOST), _
    86.                 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
    87.             WindowProc = 0
    88.         Else
    89.             ' Some other item was selected.  Let the previous window procedure
    90.             ' process it.
    91.             WindowProc = CallWindowProc(pOldProc, hwnd, uMsg, wParam, lParam)
    92.         End If
    93.     Case Else
    94.         ' If this is some other message, let the previous procedure handle it.
    95.         WindowProc = CallWindowProc(pOldProc, hwnd, uMsg, wParam, lParam)
    96.     End Select
    97. End Function
    98.  
    99. ' *** Place the following code inside Form1. ***
    100.  
    101. ' When Form1 loads, add Always On Top to the system menu and set up the
    102. ' new window procedure.
    103. Private Sub Form_Load()
    104.     Dim hSysMenu As Long     ' handle to the system menu
    105.     Dim count As Long        ' the number of items initially on the menu
    106.     Dim mii As MENUITEMINFO  ' describes a menu item to add
    107.     Dim retval As Long       ' return value
    108.    
    109.     ' Get a handle to the system menu.
    110.     hSysMenu = GetSystemMenu(Form1.hWnd, 0)
    111.     ' See how many items are currently in it.
    112.     count = GetMenuItemCount(hSysMenu)
    113.    
    114.     ' Add a separator bar and then Always On Top to the system menu.
    115.     With mii
    116.         ' The size of the structure.
    117.         .cbSize = Len(mii)
    118.         ' What parts of the structure to use.
    119.         .fMask = MIIM_ID Or MIIM_TYPE
    120.         ' This is a separator.
    121.         .fType = MFT_SEPARATOR
    122.         ' It has an ID of 0.
    123.         .wID = 0
    124.     End With
    125.     ' Add the separator to the end of the system menu.
    126.     retval = InsertMenuItem(hSysMenu, count, 1, mii)
    127.    
    128.     ' Likewise, add the Always On Top command.
    129.     With mii
    130.         .fMask = MIIM_STATE Or MIIM_ID Or MIIM_TYPE
    131.         ' This is a regular text item.
    132.         .fType = MFT_STRING
    133.         ' The option is enabled.
    134.         .fState = MFS_ENABLED
    135.         ' It has an ID of 1 (this identifies it in the window procedure).
    136.         .wID = 1
    137.         ' The text to place in the menu item.
    138.         .dwTypeData = "&Always On Top"
    139.         .cch = Len(.dwTypeData)
    140.     End With
    141.     ' Add this to the bottom of the system menu.
    142.     retval = InsertMenuItem(hSysMenu, count + 1, 1, mii)
    143.    
    144.     ' Set the custom window procedure to process Form1's messages.
    145.     ontop = False
    146.     pOldProc = SetWindowLong(Form1.hWnd, GWL_WNDPROC, AddressOf WindowProc)
    147. End Sub
    148.  
    149. ' Before unloading, restore the default system menu and remove the
    150. ' custom window procedure.
    151. Private Sub Form_Unload(Cancel As Integer)
    152.     Dim retval As Long  ' return value
    153.    
    154.     ' Replace the previous window procedure to prevent crashing.
    155.     retval = SetWindowLong(Form1.hWnd, GWL_WNDPROC, pOldProc)
    156.     ' Remove the modifications made to the system menu.
    157.     retval = GetSystemMenu(Form1.hWnd, 1)
    158. End Sub

    does anybody know of an easier or "new" way to do this? I already know i don't need SetWindowPos() but I can't find anything on the system menu .....

    if i find the answer or decided this is the only way i will post it

    thanks
    Last edited by Magiaus; Apr 11th, 2002 at 04:34 PM.
    Magiaus

    If I helped give me some points.

  4. #4
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    or you could do something like this...

    VB Code:
    1. MainMenu1.MenuItems.Add("NewItem")
    2.       ' Wire up Click event to the NewItem_Click procedure
    3.       AddHandler MainMenu1.MenuItems(MainMenu1.MenuItems.Count - 1).Click, AddressOf Me.NewItem_Click
    4.  
    5. ......  
    6.  
    7. Public Sub NewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    8.       'whatever
    9.    End Sub

  5. #5

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    no that isn't the same

    the menu i am speaking of is the one that comes up when you click the form's icom or it's taskbar button with Minimize, maximixe, restore and close in it

    i am convering the code right now i will post it in about an hr if my son will let me work...
    Magiaus

    If I helped give me some points.

  6. #6

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    @#$% Exception

    the code generates an exeption it is being cause by MENUITEMINFO but i am unsure of how to fix it

    module
    Code:
    Public Module Magiaus
    	Public Declare Function GetSystemMenu Lib "user32.dll" (ByVal hWnd As Long, ByVal bRevert As Integer) As Integer
    	Public Declare Function GetMenuItemCount Lib "user32.dll" (ByVal hMenu As Integer) As Integer
    	Public Declare Function InsertMenuItem Lib "user32.dll" Alias "InsertMenuItemA" (ByVal hMenu As Integer, ByVal uItem As Integer, ByVal fByPosition As Integer, lpmii As MENUITEMINFO) As Integer
    	Public Declare Function SetMenuItemInfo Lib "user32.dll" Alias "SetMenuItemInfoA" (ByVal hMenu As Integer, ByVal uItem As Integer, ByVal fByPosition As Integer, lpmii As MENUITEMINFO) As Integer
    
    	Public Structure MENUITEMINFO
    		Public cbSize As Integer
    		Public fMask As Integer
    		Public fType As Integer
    		Public fState As Integer
    		Public wID As Integer
    		Public hSubMenu As Integer
    		Public hbmpChecked As Integer
    		Public hbmpUnchecked As Integer
    		Public dwItemData As Integer
    		Public dwTypeData As String
    		Public cch As Integer
    		
    		Public Sub New(cbSize As Integer, fMask As Integer, fType As Integer, fState As Integer, wID As Integer, hSubMenu As Integer, hbmpChecked As Integer, hbmpUnchecked As Integer, dwItemData As Integer, dwTypeData As String, cch As Integer )
    			Me.cbSize = cbSize
    			Me.fMask = fMask
    			Me.fType = fType
    			Me.fState = fState
    			Me.wID = wID
    			Me.hSubMenu = hSubMenu
    			Me.hbmpChecked = hbmpChecked
    			Me.hbmpUnchecked = hbmpUnchecked
    			Me.dwItemData = dwItemData
    			Me.dwTypeData = dwTypeData
    			Me.cch = cch
    		End Sub
    	End Structure
    
    	Public Const MIIM_STATE As Integer = &H1
    	Public Const MIIM_ID As Integer = &H2
    	Public Const MIIM_TYPE As Integer = &H10
    	Public Const MFT_SEPARATOR As Integer = &H800
    	Public Const MFT_STRING As Integer = &H0
    	Public Const MFS_ENABLED As Integer = &H0
    	Public Const MFS_CHECKED As Integer = &H8
    End Module
    form
    Code:
    Option Explicit On
    Option Strict On
    Option Compare Binary
    
    Imports Microsoft.VisualBasic
    
    Imports System
    Imports System.Windows.Forms
    
    Public Class SysMenu : Inherits Form
    
    
    	
            <STAThread()> _
            Shared Sub Main()
                System.Windows.Forms.Application.Run(New SysMenu())
            End Sub
            
            Public Sub New()
            	MyBase.New()
            	
            	Dim hMenu As Integer = GetSystemMenu(Me.Handle.ToInt32, 0)
            	Dim ic As Integer = GetMenuItemCount(hMenu)
            	
            	Dim mii As MENUITEMINFO
            	Dim iRet As Integer = 0
            	
            	With mii
            		.cbsize = Len(mii)
            		.fMask = MIIM_ID Or MIIM_TYPE
            		.fType = MFT_SEPARATOR
            		.wID = 0
            	End With
            	
            	iRet = InsertMenuItem(hMenu, ic, 1, mii)			'Add a seperator
            	
            	With mii
    				.fMask = MIIM_STATE Or MIIM_ID Or MIIM_TYPE
    				.fType = MFT_STRING
    				.fState = MFS_ENABLED
    				.wID = 1
    				.dwTypeData = "&New Menu Item"
    				.cch = Len(.dwTypeData)
            	End With
            	
            	iRet = InsertMenuItem(hMenu, ic + 1, 2, mii)
            	
            	Me.Text = "Click Icon"
            End Sub
    End Class
    Magiaus

    If I helped give me some points.

  7. #7

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    come on somebody

    cander... anybody bill gates... corned bee oh wait wrong forum
    Last edited by Magiaus; Apr 11th, 2002 at 04:31 PM.
    Magiaus

    If I helped give me some points.

  8. #8

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    AHHHHHHHHHHHHHHHHHHHHH

    I fixed it. Now all I have to do is add the MsgProc but AHHHHHHHHHHHHHH I want an inline debugger @#$% notepad

    it wasn't even the Struct it was a error on my part.

    ok so you guys who didn't know what i meant give this a run and click the form icon or its taskbar button

    VB Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Public Module Magiaus
    4.     Public Declare Ansi Function GetSystemMenu Lib "user32.dll" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
    5.     Public Declare Ansi Function GetMenuItemCount Lib "user32.dll" (ByVal hMenu As Integer) As Integer
    6.     Public Declare Ansi Function InsertMenuItem Lib "user32.dll" Alias "InsertMenuItemA" (ByVal hMenu As Integer, ByVal uItem As Integer, ByVal fByPosition As Integer,ByRef lpmii As MENUITEMINFO) As Integer
    7.     Public Declare Ansi Function SetMenuItemInfo Lib "user32.dll" Alias "SetMenuItemInfoA" (ByVal hMenu As Integer, ByVal uItem As Integer, ByVal fByPosition As Integer,ByRef lpmii As MENUITEMINFO) As Integer
    8.    
    9.     < StructLayout( LayoutKind.Sequential, CharSet := CharSet.Ansi )> _
    10.     Public Structure MENUITEMINFO
    11.         Public cbSize As Integer
    12.         Public fMask As Integer
    13.         Public fType As Integer
    14.         Public fState As Integer
    15.         Public wID As Integer
    16.         Public hSubMenu As Integer
    17.         Public hbmpChecked As Integer
    18.         Public hbmpUnchecked As Integer
    19.         Public dwItemData As Integer
    20.         Public dwTypeData As String
    21.         Public cch As Integer
    22.         Public hbmpItem As Integer
    23.     End Structure
    24.  
    25.     Public Const MIIM_STATE As Integer = &H1
    26.     Public Const MIIM_ID As Integer = &H2
    27.     Public Const MIIM_TYPE As Integer = &H10
    28.     Public Const MFT_SEPARATOR As Integer = &H800
    29.     Public Const MFT_STRING As Integer = &H0
    30.     Public Const MFS_ENABLED As Integer = &H0
    31.     Public Const MFS_CHECKED As Integer = &H8
    32. End Module
    VB Code:
    1. Option Explicit On
    2. Option Strict On
    3. Option Compare Binary
    4.  
    5. Imports Microsoft.VisualBasic
    6.  
    7. Imports System
    8. Imports System.Windows.Forms
    9.  
    10. Public Class SysMenu : Inherits Form
    11.  
    12.  
    13.    
    14.         <STAThread()> _
    15.         Shared Sub Main()
    16.             System.Windows.Forms.Application.Run(New SysMenu())
    17.         End Sub
    18.        
    19.         Public Sub New()
    20.             MyBase.New()
    21.            
    22.             Dim hMenu As Integer = GetSystemMenu(Me.Handle.ToInt32, 0)  'should really check this value
    23.             Dim ic As Integer = GetMenuItemCount(hMenu)                 'same here
    24.            
    25.             Dim mii As MENUITEMINFO
    26.             Dim iRet As Integer = 0
    27.            
    28.             With mii
    29.                 .cbsize = Len(mii)
    30.                 .fMask = MIIM_ID Or MIIM_TYPE
    31.                 .fType = MFT_SEPARATOR
    32.                 .wID = 0
    33.             End With
    34.            
    35.             iRet = InsertMenuItem(hMenu, ic + 1, 1, mii)            'Add a seperator
    36.            
    37.            
    38.             With mii
    39.                 .fMask = MIIM_STATE Or MIIM_ID Or MIIM_TYPE
    40.                 .fType = MFT_STRING
    41.                 .fState = MFS_ENABLED
    42.                 .wID = 1
    43.                 .dwTypeData = "&New Menu Item"
    44.                 .cch = Len(.dwTypeData)
    45.             End With
    46.            
    47.             iRet = InsertMenuItem(hMenu, ic + 2, 1, mii)
    48.            
    49.             Me.Text = "Click Icon"
    50.         End Sub
    51. End Class

    if you look close you will see a major change and 2 minor changes
    Magiaus

    If I helped give me some points.

  9. #9

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    by the way

    the code i took from vbapi.com had the error in it to begin with
    Magiaus

    If I helped give me some points.

  10. #10

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Here you go

    The finished product. Complete with WindowProc. say ewww subclassing really weak subclassing
    module:
    VB Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Public Module Magiaus
    4.     Public Declare Ansi Function GetSystemMenu Lib "user32.dll" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
    5.     Public Declare Ansi Function GetMenuItemCount Lib "user32.dll" (ByVal hMenu As Integer) As Integer
    6.     Public Declare Ansi Function InsertMenuItem Lib "user32.dll" Alias "InsertMenuItemA" (ByVal hMenu As Integer, ByVal uItem As Integer, ByVal fByPosition As Integer,ByRef lpmii As MENUITEMINFO) As Integer
    7.     Public Declare Ansi Function SetMenuItemInfo Lib "user32.dll" Alias "SetMenuItemInfoA" (ByVal hMenu As Integer, ByVal uItem As Integer, ByVal fByPosition As Integer,ByRef lpmii As MENUITEMINFO) As Integer
    8.    
    9.     Public Declare Ansi Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Integer, ByVal hWnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    10.     Public Declare Ansi Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As ipWindowProc) As Integer
    11.    
    12.     < StructLayout( LayoutKind.Sequential, CharSet := CharSet.Ansi )> _
    13.     Public Structure MENUITEMINFO
    14.         Public cbSize As Integer
    15.         Public fMask As Integer
    16.         Public fType As Integer
    17.         Public fState As Integer
    18.         Public wID As Integer
    19.         Public hSubMenu As Integer
    20.         Public hbmpChecked As Integer
    21.         Public hbmpUnchecked As Integer
    22.         Public dwItemData As Integer
    23.         Public dwTypeData As String
    24.         Public cch As Integer
    25.         Public hbmpItem As Integer
    26.     End Structure
    27.  
    28.     Public Const MIIM_STATE As Integer = &H1
    29.     Public Const MIIM_ID As Integer = &H2
    30.     Public Const MIIM_TYPE As Integer = &H10
    31.     Public Const MFT_SEPARATOR As Integer = &H800
    32.     Public Const MFT_STRING As Integer = &H0
    33.     Public Const MFS_ENABLED As Integer = &H0
    34.     Public Const MFS_CHECKED As Integer = &H8
    35.    
    36.     Public Const GWL_WNDPROC As Integer = -4
    37.    
    38.     Public Const WM_INITMENU As Integer = &H116
    39.     Public Const WM_SYSCOMMAND As Integer = &H112
    40.    
    41. End Module
    form:
    VB Code:
    1. Option Explicit On
    2. Option Strict On
    3. Option Compare Binary
    4.  
    5. Imports Microsoft.VisualBasic
    6.  
    7. Imports System
    8. Imports System.Windows.Forms
    9.  
    10. Public Delegate Function ipWindowProc(ByVal hwnd As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    11.  
    12. Public Class SysMenu : Inherits Form
    13.  
    14.         Dim ioProc As Integer = 0
    15.    
    16.         <STAThread()> _
    17.         Shared Sub Main()
    18.             System.Windows.Forms.Application.Run(New SysMenu())
    19.         End Sub
    20.        
    21.         Public Sub New()
    22.             MyBase.New()
    23.            
    24.             Dim hMenu As Integer = GetSystemMenu(Me.Handle.ToInt32, 0)  'should really check this value
    25.             Dim ic As Integer = GetMenuItemCount(hMenu)                 'same here
    26.            
    27.             Dim mii As MENUITEMINFO
    28.             Dim iRet As Integer = 0
    29.            
    30.             With mii
    31.                 .cbsize = Len(mii)
    32.                 .fMask = MIIM_ID Or MIIM_TYPE
    33.                 .fType = MFT_SEPARATOR
    34.                 .wID = 0
    35.             End With
    36.            
    37.             iRet = InsertMenuItem(hMenu, ic + 1, 1, mii)            'Add a seperator
    38.            
    39.            
    40.             With mii
    41.                 .fMask = MIIM_STATE Or MIIM_ID Or MIIM_TYPE
    42.                 .fType = MFT_STRING
    43.                 .fState = MFS_ENABLED
    44.                 .wID = 1
    45.                 .dwTypeData = "&Alway On Top"
    46.                 .cch = Len(.dwTypeData)
    47.             End With
    48.            
    49.             iRet = InsertMenuItem(hMenu, ic + 2, 1, mii)
    50.            
    51.             Me.Text = "Click Icon"
    52.             Me.TopMost = True
    53.            
    54.             Dim ip As ipWindowProc = AddressOf Me.WindowProc
    55.             ioProc = SetWindowLong(Me.Handle.ToInt32, GWL_WNDPROC, ip)
    56.         End Sub
    57.        
    58.        
    59.         Public Function WindowProc(ByVal hwnd As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer ) As Integer
    60.             Dim bTopMost As Boolean = Me.TopMost
    61.             Dim hMenu As Integer = 0
    62.             Dim iRet As Integer = 0
    63.             Dim mii As MENUITEMINFO
    64.            
    65.             Select Case uMsg
    66.                 Case WM_INITMENU
    67.                     hMenu = GetSystemMenu(hwnd, 0)
    68.                     mii.cbSize = Len(mii)
    69.                     mii.fMask = MIIM_STATE
    70.                     If bTopMost = True Then
    71.                         mii.fState = MFS_ENABLED Or MFS_CHECKED
    72.                     Else
    73.                         mii.fState = MFS_ENABLED Or 0
    74.                     End If
    75.                     iRet = SetMenuItemInfo(hMenu, 1, 0, mii)
    76.                     WindowProc = 0
    77.                 Case WM_SYSCOMMAND
    78.                     If wParam = 1 Then
    79.                         mii.cbSize = Len(mii)
    80.                         mii.fMask = MIIM_STATE
    81.                         If bTopMost = True
    82.                             mii.fState = MFS_ENABLED Or 0
    83.                             iRet = SetMenuItemInfo(hMenu, 1, 0, mii)
    84.                             Me.TopMost = False
    85.                         Else
    86.                             mii.fState = MFS_ENABLED Or MFS_CHECKED
    87.                             iRet = SetMenuItemInfo(hMenu, 1, 0, mii)
    88.                             Me.TopMost = True
    89.                         End If
    90.                         WindowProc = 0
    91.                     Else
    92.                         WindowProc = CallWindowProc(ioProc, hwnd, uMsg, wParam, lParam)
    93.                     End If
    94.                 Case Else
    95.                     WindowProc = CallWindowProc(ioProc, hwnd, uMsg, wParam, lParam)
    96.             End Select
    97.         End Function
    98.  
    99. End Class

    Ok thats it. Source files and exe attached.

    Please comment.
    Attached Files Attached Files
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width