Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add a custom menu item to the windows system menu
Forum Updated to NodeBB v4.3 + New Features

How to add a custom menu item to the windows system menu

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 8.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    laseranichris
    wrote on last edited by
    #1

    Hello,

    I am writing an application without menu bar.

    Is it possible to add a custom menu item (like "About...") to the system menu of the application window?
    On Windows this is usually done by the default MFC implementation.

    Thank you for your help!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      I think this is too much OS-specific and you'll have to use the Win32 API directly.

      See also:

      • http://msdn.microsoft.com/en-us/library/windows/desktop/ms647985(v=vs.85).aspx
      • http://msdn.microsoft.com/en-us/library/windows/desktop/ms647616(v=vs.85).aspx

      Then you'll have to re-implement winEvent() to handle the corresponding messages:
      http://doc.qt.digia.com/qt/qwidget.html#winEvent

      It's probably a message of type WM_COMMAND that you are waiting for...

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        Hi MuldeR,

        you are right, this is the only option you have. It's highly OS specific.
        Just a side note: Take care that the title bar stays, if you have an app without a windows title bar, then also the system menu is away.

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • L Offline
          L Offline
          laseranichris
          wrote on last edited by
          #4

          Hello,

          thank you very much for your answers.
          Knowing the right approach everything becomes quite easy.
          Of cause this is highly OS specific...

          Just for the case that someone else wants to add the "About" menu item into the Windows system menu here is a short code snippet:

          @#include "windows.h"

          MyWidget::MyWidget() : QMainWindow()
          {
          ...

          // IDM_ABOUTBOX must be in the system command range
          // (IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX)
          // and (IDM_ABOUTBOX < 0xF000)
          #define IDM_ABOUTBOX 0x0010

          HMENU hMenu = ::GetSystemMenu(winId(), FALSE);
          if (hMenu != NULL)
          {
          ::AppendMenuA(hMenu, MF_SEPARATOR, 0, 0);
          ::AppendMenuA(hMenu, MF_STRING, IDM_ABOUTBOX, "About MyApp...");
          }

          ...
          }

          bool MyWidget::winEvent(MSG *m, long *result)
          {
          if (m->message == WM_SYSCOMMAND)
          {
          if ((m->wParam & 0xfff0) == IDM_ABOUTBOX)
          {
          *result = 0;

               // open About dialog
               about();
          
               return (true);
            }
          

          }

          return (false);
          }
          @

          1 Reply Last reply
          0
          • A Offline
            A Offline
            astodolski
            wrote on last edited by
            #5

            This example doesn't build:

            @mainwindow.obj:-1: error: LNK2019: unresolved external symbol __imp__AppendMenuW@16 referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)@

            Have you used this?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              laseranichris
              wrote on last edited by
              #6

              You have to add the following line in the project file:

              @LIBS += -lUser32@

              This is required for GetSystemMenu and AppendMenu.

              Hope this helps!

              1 Reply Last reply
              0
              • A Offline
                A Offline
                astodolski
                wrote on last edited by
                #7

                How stupid of me! Of course, it's Win32 - Thanks so much!

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved