[wxWidgets] Add “About…” to the system menu

Posted on Dec 21, 2014

Original post: https://forums.wxwidgets.org/viewtopic.php?f=20&t=13921

MyDialog.h

1
2
3
4
5
6
7
class MyDialog : public wxDialog
{
    ...
 
    // Override MSWTranslateMessage
    bool MSWTranslateMessage(WXMSG* pMsg);
};

MyDialog.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Include aboutdlg.h
#include <wx/aboutdlg.h>
 
MyDialog::MyDialog(wxWindow* parent)
{
    ...
 
    // Add the menu item, "About...", to the system menu
    HMENU hSystemMenu = ::GetSystemMenu((HWND__*)GetHWND(), FALSE);
    ::AppendMenu(hSystemMenu, MF_SEPARATOR, 0, wxT(""));
    ::AppendMenu(hSystemMenu, MF_STRING, wxID_ABOUT, wxT("About..."));
    ::DrawMenuBar((HWND__*)GetHWND());
}
 
// implement the message handler
bool MyDialog::MSWTranslateMessage(WXMSG* pMsg)
{
    if (WM_SYSCOMMAND==pMsg->message && wxID_ABOUT==pMsg->wParam)
    {
        wxAboutDialogInfo di;
        di.SetName(wxT("My App"));
        di.SetVersion(wxT("1.00"));
        di.SetDescription(wxT("This app does cool trix!"));
 
        wxAboutBox(di);
 
        return true; // Message processed
    }
 
    return wxDialog::MSWTranslateMessage(pMsg);
}