Adding "About..." to system menu (MSW only) Topic is solved

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
Post Reply
Joel Kolstad
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Apr 11, 2007 7:32 pm

Adding "About..." to system menu (MSW only)

Post by Joel Kolstad »

There are numerous messages regarding how to add extra menu items to the Window's system menu (this is the only menu that a dialog application gets). If you piece enough of them together, you can figure out how to do it, but I've stuck an example here so that others won't have to do this themselves.

So... here's what you do... in your dialog's "Create" method (or some other reasonable location), add the following:

Code: Select all

	// Add about option to system menu
    HMENU hSystemMenu = ::GetSystemMenu((HWND__ *) GetHWND(),FALSE); 
    ::AppendMenu(hSystemMenu,MF_SEPARATOR,0,""); 
    ::AppendMenu(hSystemMenu,MF_STRING,IDM_ABOUT,"About..."); 
    ::DrawMenuBar((HWND__ *) GetHWND());
In your dialog's .h file, you'll have to make up an otherwise unused identifier for IDM_ABOUT. For instance:

Code: Select all

#define IDM_ABOUT 10099 // System menu "About..." ID
Finally, you have to override the windows message loop processing, which is done all the way back in wxWindow that wxDialog derives from. Hence, add this to the class declaraion in your dialog's .h file:

Code: Select all

	
[rest of class definition, MainDlg in this example]
.
.
// Override MSWTranslateMessage to respond to system menu "About..." selection
    bool MSWTranslateMessage(WXMSG* pMsg);
And this to the .cpp file:

Code: Select all

bool MainDlg::MSWTranslateMessage(WXMSG* pMsg)
{
    if ( (pMsg->message == WM_SYSCOMMAND) && (pMsg->wParam == IDM_ABOUT)) 
	{
		wxAboutDialogInfo di;

		di.SetName("My App");
		di.SetVersion("1.00");
		di.SetDescription("This app does cool trix!");
... etc ...
		wxAboutBox(di);
	   return true; // Message processed
   }
	else 
		return wxDialog::MSWTranslateMessage(pMsg); 
}
(Note that you may need need to #include "wx/aboutdlg.h, too.)

That's it! Run you application, and you'll now have a system menu "About..." choice that displays an about box.

The preceding code can also be used on a more tradiational frame-based application -- you just replace "wxDialog" with "wxFrame" above.

QUESTION (for those more experienced than me): Would it be better to send a custom event back to the app rather than calling wxAboutBox in MSWTranslate message?

---Joel
Last edited by Joel Kolstad on Wed Oct 31, 2007 11:14 pm, edited 3 times in total.
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

Very nice, thanks! :-)

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Post Reply