473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Add Items to the ControlBox Menu?

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?
Mar 25 '07 #1
2 3403
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)
Mar 25 '07 #2
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?
Mar 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Heather | last post by:
I notice the Tag property for menu items. Is there a way to assign say a 1 to the Tag property of certain menu items and then make those menu items not visible programatically? Thanks! Heather
10
by: tmaster | last post by:
When I try to dynamically add a second sub menu item to this ContextMenu item, I get an error 'Specified argument was out of the range of valid values'. Private Sub mnuTopics_Show_Select(ByVal...
13
by: Sylo | last post by:
Hi, I'm french and I don't find the answer at my question. You are my last chance and sorry for my english... I'm in VB .NET 2002 I have a MDI form with the property ControlBox at FALSE. When...
12
by: Flashster | last post by:
I have an exit routine that runs when a users selects 'exit' from a menu or closes the form by clicking on the 'X' in the top right of the form (on the controlbox). One option in the exit...
1
by: Saso Zagoranski | last post by:
Hi, In .NET 2.0 I have a MDI (parent) form with a menu and a toolbar. I also have a MDI child form displayed in the mdi parent form. The problem is, that when I maximize the child form it's...
2
by: MCM | last post by:
I'm working on a plotting control. The plotting control will have a context menu with basic commands for "scaling", "zooming", etc. Is there a way that, from the parent form, I can add more...
1
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Hi, friends, I am using C#.net 2005 to create a windows application. It has menu items, such as File, etc. Under File, there are more menu items, such as New Files, Working Files, etc. Under...
0
by: straightEdge | last post by:
First of all, I'm using C# 2.0 with VSTS 2005 on Windows XP SP2. Now, does anyone know of an API call that can add extra buttons to the ControlBox of a form? I've seen plenty of apps that do it. ...
13
by: PetterL | last post by:
I writing a program where I read menu items from a file. But I have problem when I click an menu item i want it to mark that one as checked but I cant access the menu object of that item to see...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.