• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 840
  • Last Modified:

How to add items to title bar menu

Hello.

How do I add  items to the popup menu that appears when you click on an application title bar. (The menu that has Minimize, Maximize, Close etc).

Thanks. js
0
jeremiahscott
Asked:
jeremiahscott
  • 2
  • 2
1 Solution
 
sonicblisCommented:
I assume you're speaking of a windows form, like adding "always on top"?
0
 
jeremiahscottAuthor Commented:
Yes, I have a windows form.

I probably didn't explain this well. If you click on Internet Explorers title bar you will see a popup menu. The items are [Restore, Move...Close]. If you do the same thing on a windows command prompt window they have added 3 more items [Edit, Defaults, Properties]. I want to mimic that.

thx
0
 
Fahad MukhtarDistinguished EngineerCommented:
[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

[DllImport("user32.dll")]
private static extern bool AppendMenu (IntPtr hMenu, Int32 wFlags, Int32
wIDNewItem, string lpNewItem);

public const Int32 WM_SYSCOMMAND = 0x112;
public const Int32 MF_SEPARATOR = 0x800;
public const Int32 MF_STRING = 0x0;
public const Int32 IDM_ABOUT  = 1000;

private void Form1_Load(object sender, System.EventArgs e)
{
IntPtr sysMenuHandle = GetSystemMenu(this.Handle, false);
AppendMenu(sysMenuHandle, MF_SEPARATOR, 0, string.Empty);
AppendMenu(sysMenuHandle, MF_STRING, IDM_ABOUT, "About...");
}

protected override void WndProc(ref Message m)
{
if(m.Msg == WM_SYSCOMMAND)
 switch(m.WParam.ToInt32())
 {
  case IDM_ABOUT :
    MessageBox.Show("This is About dialog");
   return;
  default:
   break;
 } base.WndProc(ref m);
}
0
 
jeremiahscottAuthor Commented:
I got it working. Thanks. I couldn't figure out what that menu was called. "System Menu"
0
 
Fahad MukhtarDistinguished EngineerCommented:
User menu are the menus designed and developed by the programmer himself(like Mainmenu and ContextMenu control). SystemMenu is something common functaionality provided by the Operating system.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now