Library code snippets
System Menu Items
By Michael H, published on 25 Feb 2003
The following code adds a menu to the form's system menu. It responds to click events by intercepting the WM_SYSCOMMAND message.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.ComponentModel;
using System.Reflection;
class test : Form {
[DllImport("user32.dll")]
private static extern int GetSystemMenu(int hwnd, int bRevert);
[DllImport("user32.dll")]
private static extern int AppendMenu(int hMenu,int Flagsw,int IDNewItem,string lpNewItem);
public static void Main() {
Application.Run(new test());
}
public test() {
this.Text = "Hello";
this.Show();
int Menu1 = GetSystemMenu(this.Handle.ToInt32(), 0); // get handle to system menu
AppendMenu(Menu1,0xA00,0,null); // makes a separator
AppendMenu(Menu1,0,666,"C# Rules!");
}
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
if(m.Msg==0x112) { // WM_SYSCOMMAND is 0x112
if(m.WParam.ToInt32()==666) { // the Menu's ID is 666
//everything in here will run when menu is clicked
MessageBox.Show("Yo!");
}
}
}
}
Related articles
Related discussion
-
Buy cheap Xanax overnight. Cheap Xanax. Overnight delivery of Xanax in US no prescription needed. Cheapest Xanax.
by asleymar (0 replies)
-
Buy Soma online without a prescription. Soma drug no prescription. How to get Soma prescription. Soma cod accepted.
by asleymar (0 replies)
-
Cheap online order Fioricet. Cheap discount Fioricet. Offshore Fioricet online. How to buy Fioricet online without a prescription.
by asleymar (0 replies)
-
Buy Ambien no visa without prescription. Not expensive Ambien prescriptions. Ambien no rx. Cod delivery Ambien.
by asleymar (0 replies)
-
Tramadol without doctor rx. Buy Tramadol over the counter cod overnight. Cheap Tramadol cod delivery. Buy Tramadol from mexico online.
by asleymar (0 replies)
Related podcasts
-
Object-Oriented Programming in Ruby
In this episode, I talk with Scott Bellware about object-oriented programming in Ruby, and Ruby's object model. This is taken from a private conversation, and the audio quality suffers at times. Much thanks to Scott for allowing this to be released.This episode of the Alt.NET Podcast is bro...
nices stuff...excellent tip
This thread is for discussions of System Menu Items.