VB[2008] Newbie form question - removing standard menu when clicking on form icons

R

Rob W

Greetings,

I have a MDI application and for every form when left single clicking on the
form icon located in the upper left corner a context style menu appears with
options :-
"Restore, Move, Size, Minimize, Maximize and Close".

Then a further option for Child forms (Next) allowing to jump to child
forms.

I've been looking through all the properties of the form and want to know is
it possible to disable these options?

Thanks
Rob
 
R

Rob W

That options also then ignores the icon, minimize, maximize and close
settings.
So I want the icon showing along with the minimize, maximize and close
buttons on the title bar just not the context type menu which is displayed
when you single click on the icon.

Hope that makes sense.

Thanks
 
G

gillardg

' you can try this


Private Const SC_MINIMIZE = &HF020&
Private Const SC_CLOSE = &HF060&
Private Const SC_MAXIMIZE = &HF030&
Private Const SC_RESTORE = &HF120&
Private Const SC_SIZE = &HF000&
Private Const SC_MOVE = &HF010&

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As
Integer, ByVal bRevert As Integer) As Integer
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As
Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.SetBoundsCore(100, 100, 526, 234, BoundsSpecified.Location)
Dim sysmen As Integer
sysmen = GetSystemMenu(Me.Handle, 0)
DeleteMenu(sysmen, SC_MOVE, &H0&)
DeleteMenu(sysmen, SC_CLOSE, &H0&)
DeleteMenu(sysmen, SC_MAXIMIZE, &H0&)
DeleteMenu(sysmen, SC_SIZE, &H0&)
DeleteMenu(sysmen, SC_MINIMIZE, &H0&)
End Sub
 
R

Rob W

Thanks I will try this soon.

I will also read up to get a better understanding of what's going on :)
 
A

Armin Zingler

gillardg said:
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As
Integer, ByVal bRevert As Integer) As Integer
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As
Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As
Integer


Handles have a plattform specific size. The appropriate framework type is
IntPtr. On a 64 bit plattform it wouldn't work. Some values can also be
declared as Boolean:

Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As IntPtr, ByVal bRevert As boolean) As IntPtr

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

(2nd and 3rd arg with DeleteMenu can also be UInteger but it doesn't matter
here)


Armin
 
R

Rob W

Just for aesthetic reasons to be honest.

Oddly enough I never realised that most form applications that display icon
which when clicked contained menu functionality.
 
A

Armin Zingler

Rob said:
Just for aesthetic reasons to be honest.

Oddly enough I never realised that most form applications that
display icon which when clicked contained menu functionality.

I'm used to press Alt+- (minus key) to open the menu (or Alt+Space for the
top level window). I don't understand why you want to disable me from using
this menu. With an MDI child you can do all of "Restore, Move, Size,
Minimize, Maximize and Close" anyway - or one should be able to.


Armin
 
R

Rob W

In the end I decided just to leave it in there, at least I know a method to
remove them.

I did trial the code and it did work as I aren't on a 64bit system though as
using option string had to convert a few things here and there.

It was my own stupidity not realising that all applications function in this
way and have this menu.
 
S

Scott M.

This icon (and resulting menu) has been present on Windows Forms going all
the way back to Windows 1.0.

If you remember, before the days of the minimze, maximize, and close buttons
that we are all so familiar with in the top/right of a Window, back in the
days of Windows 3.1 and Program Manager, this was the way you worked with a
Window.

You would single click the "Control Button" (today it's called the "Control
Box") to activate the drop down menu and choose what you'd like to do. To
close a window, you'd double click the icon itself and that still works
today - none of this behavior has changed.

It's just that since Windows 95 and the advent of the 3 buttons on the
top/right of a Window, people stopped using the Control Box as much.

-Scott
 
R

Rob W

Thanks for the info, I have used windows 3.1 and remarkably since Win95 I
can't ever remember using the control box my behavioural pattern of using
the upper right buttons to close, minimise or maximise has stuck with me
ever since or using a context menu from a right click.

Shocking really that I never even noticed the control box since using
windows regularly for about 10 years.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top