How can I add items to the system menu?
Applies To: C++Builder 1 or higher
Category: Knowledge Base
- When I click on my form's border icon, a popup system menu appears. How can I add items to this menu and handle their OnClick event?
-

-
- Start a new project using File | New Application.
-
- Add a Button. Edit its OnClick event:
-
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- HMENU menu = GetSystemMenu(Handle, false);
- if(menu)
- {
- // Add separator
- AppendMenu(menu, MF_SEPARATOR, NULL, NULL);
- // Add menu item
- AppendMenu(menu, MF_STRING, 555, "Click here...");
- }
- }
-
- Open your header file:
-
- private:
- MESSAGE void __fastcall ClickHere(TMessage &);
- BEGIN_MESSAGE_MAP
- MESSAGE_HANDLER(WM_SYSCOMMAND, TMessage, ClickHere);
- END_MESSAGE_MAP(TForm);
-
- Insert in your source code:
-
- void __fastcall TForm1::ClickHere(TMessage &Message)
- {
- if(Message.WParam == 555)
- {
- ShowMessage("You clicked me!");
- }
- TForm::Dispatch(&Message);
- }
C++Builder Developer's Network
Copyright © Yoto Yotov