PC Review


Reply
Thread Tools Rate Thread

Add Items to the ControlBox Menu?

 
 
Joe Cool
Guest
Posts: n/a
 
      25th Mar 2007
You know how when you minimize an application, and you then right
click on the application's task bar icon, a popup menu appears that
has by default the items Restore, Move, Size, Minimize, Maximize and
Close? It is also known as the ControlBox menu since this is the same
menu you see if you click in the application's ControlBox (upper left
corner icon).

Using VB2005, how to I add my own custom items to that menu?
 
Reply With Quote
 
 
 
 
Newbie Coder
Guest
Posts: n/a
 
      25th Mar 2007
Joe,

You need to use the GetSystemMenu API, AppendMenu & DeleteMenu then handle
the events in the WndProc sub.

I write this example in 2002 & should change the function declarations to
the DllImport...

This just leaves minimise & close on the system menu:

Declations:

Private Declare Function GetSystemMenu Lib "user32" Alias
"GetSystemMenu" _
(ByVal hwnd As Integer, ByVal bRevert As Integer) As Integer

Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" _
(ByVal hMenu As Integer, ByVal wFlags As Integer, _
ByVal wIDNewItem As Integer, ByVal lpNewItem As String) As Integer

Private Declare Function DeleteMenu Lib "user32" Alias "DeleteMenu" _
(ByVal hMenu As Integer, ByVal nPosition As Integer, _
ByVal wFlags As Integer) As Integer

Private Const MF_BYPOSITION As Integer = &H400&
Private Const MF_SEPARATOR As Integer = &H800&
Private Const MF_STRING As Integer = &H0&
Private Const WM_SYSCOMMAND As Integer = &H112


Form Load:

' Get the system menu
Dim iMenu As Integer = GetSystemMenu(Me.Handle.ToInt32, 0)
' Delete all system menu item except minimize
DeleteMenu(iMenu, 6, MF_BYPOSITION)
DeleteMenu(iMenu, 5, MF_BYPOSITION)
DeleteMenu(iMenu, 4, MF_BYPOSITION)
DeleteMenu(iMenu, 2, MF_BYPOSITION)
DeleteMenu(iMenu, 1, MF_BYPOSITION)
DeleteMenu(iMenu, 0, MF_BYPOSITION)
' Add a seperator
AppendMenu(iMenu, MF_SEPARATOR, 1000, "")
' Add the 'close' menu item
AppendMenu(iMenu, MF_STRING, 1001, "Close")


WndProc:

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND Then
Select Case m.WParam.ToInt32
Case 1001
' User clicked close - show a copyright message
MessageBox.Show("This application is © 2007 Newbie
Coder. All Rights Reserved", _
Me.Text, MessageBoxButtons.OK,
MessageBoxIcon.Information)
' Exit the application
Application.Exit()
End Select
End If
MyBase.WndProc(m)
End Sub

Remember you use the Append or Delete (menu API) & the index (By Position)
or by command...

I hope this helps,

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


 
Reply With Quote
 
Joe Cool
Guest
Posts: n/a
 
      26th Mar 2007
Thanks, I'll look into that. Crap, I hate to use APIs. I wonder why
Microsoft hasn't written .NET classes to handle this stuff?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unwanted Menu Items in Start Menu and Explore Popup Menu Possum Windows XP General 2 25th Oct 2008 06:40 PM
To restore menu items of context menu in IE after adding custom items vicsmith@yandex.ru Windows XP Internet Explorer 0 26th Sep 2005 03:52 AM
To restore menu items of context menu in IE after adding custom items vicsmith@yandex.ru Windows XP Internet Explorer 0 21st Sep 2005 09:58 AM
How to modify the ControlBox(system menu) of a Form? Yuan Ze Microsoft Dot NET Framework Forms 2 5th Jun 2004 04:01 PM
Controlbox menu in custom form Glenn Nilsson Microsoft Dot NET Framework Forms 3 12th Dec 2003 06:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:52 PM.