How do you access the System menu of a form with .Net

  • Thread starter Thread starter Will Pittenger
  • Start date Start date
W

Will Pittenger

I have written a program that it would be nice to command while it is
minimized. Specifically, it is a timer program that I would like the system
menu to have options to start and stop the timer. I would have no problems
do this with MFC or Win32, but am relatively new to C# and .Net.
 
Will,

There is no managed object representation to add items to the system
menu. In order to do this, you will have to get the handle to the system
menu by making a call to the GetSystemMenu class through the P/Invoke layer.
Once you have the handle, you can call InsertMenuItem through the P/Invoke
layer in order to set the menu items.

Hope this helps.
 
P/Invoke?

----------
Will Pittenger
E-Mail: mailto:[email protected]
All mail filtered by Qurb (www.qurb.com)
Nicholas Paldino said:
Will,

There is no managed object representation to add items to the system
menu. In order to do this, you will have to get the handle to the system
menu by making a call to the GetSystemMenu class through the P/Invoke layer.
Once you have the handle, you can call InsertMenuItem through the P/Invoke
layer in order to set the menu items.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Will Pittenger said:
I have written a program that it would be nice to command while it is
minimized. Specifically, it is a timer program that I would like the system
menu to have options to start and stop the timer. I would have no problems
do this with MFC or Win32, but am relatively new to C# and .Net.
 
Will,

Short for Platform Invoke, it allows you to make calls to functions in
unmanaged DLLs (like windows API calls).

For more information on Platform Invoke, check out the Platform Invoke
tutorial, located at (watch for line wrap):

http://msdn.microsoft.com/library/d...us/csref/html/vcwlkPlatformInvokeTutorial.asp


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Will Pittenger said:
P/Invoke?

----------
Will Pittenger
E-Mail: mailto:[email protected]
All mail filtered by Qurb (www.qurb.com)
message news:[email protected]...
Will,

There is no managed object representation to add items to the system
menu. In order to do this, you will have to get the handle to the system
menu by making a call to the GetSystemMenu class through the P/Invoke layer.
Once you have the handle, you can call InsertMenuItem through the P/Invoke
layer in order to set the menu items.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Will Pittenger said:
I have written a program that it would be nice to command while it is
minimized. Specifically, it is a timer program that I would like the system
menu to have options to start and stop the timer. I would have no problems
do this with MFC or Win32, but am relatively new to C# and .Net.
 
More reading to do it appears. I had worked with this before, but C# is not
100% to my liking. I would rather stay with C++, but it is career
enhancing.

On a related note, to reduced the visual foot print I was thinking dropping
the titlebar. (I would still do the system menu thing, but this just
provides more options.) That would require that I replace my toolbar with
controls as I still need the minimize and close buttons. (I would make
those controls too.) The plan was to move the editable name field and
current time from below and put them where the titlebar currently is (and
all on one line rather than two). The app would be wider, but much shorter.
I would then shorten it further by allowing the stuff that was on the
toolbar (just what is going into the system menu) with a collapse/expand
button on the top row.

Do I need to convert my form to a control? I do not see a "Show Titlebar"
property. Can controls be made top level (children of the desktop)? I have
only C# Personal and can't build components. (Not that they are needed,
but...)

----------
Will Pittenger
E-Mail: mailto:[email protected]
All mail filtered by Qurb (www.qurb.com)
Nicholas Paldino said:
Will,

Short for Platform Invoke, it allows you to make calls to functions in
unmanaged DLLs (like windows API calls).

For more information on Platform Invoke, check out the Platform Invoke
tutorial, located at (watch for line wrap):

http://msdn.microsoft.com/library/d...us/csref/html/vcwlkPlatformInvokeTutorial.asp


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Will Pittenger said:
P/Invoke?

----------
Will Pittenger
E-Mail: mailto:[email protected]
All mail filtered by Qurb (www.qurb.com)
message news:[email protected]...
Will,

There is no managed object representation to add items to the system
menu. In order to do this, you will have to get the handle to the system
menu by making a call to the GetSystemMenu class through the P/Invoke layer.
Once you have the handle, you can call InsertMenuItem through the P/Invoke
layer in order to set the menu items.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have written a program that it would be nice to command while it is
minimized. Specifically, it is a timer program that I would like the
system
menu to have options to start and stop the timer. I would have no
problems
do this with MFC or Win32, but am relatively new to C# and .Net.
 
It took me a while, but I did finally get my system menu changes working.
Any suggestions on how to intercept the WM_MESSAGE? I already have
overridden WndProc and could use that. However, since MFC has specialized
virtual functions for this (OnCmdMsg and OnCommand), I though that .NET
might have something similar. I plan to start with the WndProc. If you
have a better way let me know.

----------
Will Pittenger
E-Mail: mailto:[email protected]
All mail filtered by Qurb (www.qurb.com)
Nicholas Paldino said:
Will,

Short for Platform Invoke, it allows you to make calls to functions in
unmanaged DLLs (like windows API calls).

For more information on Platform Invoke, check out the Platform Invoke
tutorial, located at (watch for line wrap):

http://msdn.microsoft.com/library/d...us/csref/html/vcwlkPlatformInvokeTutorial.asp


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Will Pittenger said:
P/Invoke?

----------
Will Pittenger
E-Mail: mailto:[email protected]
All mail filtered by Qurb (www.qurb.com)
message news:[email protected]...
Will,

There is no managed object representation to add items to the system
menu. In order to do this, you will have to get the handle to the system
menu by making a call to the GetSystemMenu class through the P/Invoke layer.
Once you have the handle, you can call InsertMenuItem through the P/Invoke
layer in order to set the menu items.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have written a program that it would be nice to command while it is
minimized. Specifically, it is a timer program that I would like the
system
menu to have options to start and stop the timer. I would have no
problems
do this with MFC or Win32, but am relatively new to C# and .Net.
 
Back
Top