Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Handling sysmenu new item event

Handling sysmenu new item event

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 Posts 2 Posters 0 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.
  • E Offline
    E Offline
    eyalle
    wrote on last edited by
    #1

    Hello all, I have a class CChildFrame : public CMDIChildWnd : public CFrameWnd i have declared a new item in sysMenu called "Map Info"

    	CMenu \*pSysMenu = pFrm->GetSystemMenu(FALSE);
    	ASSERT(pSysMenu != NULL);
    	pSysMenu->AppendMenu(MF\_STRING, IDI\_SYS\_MENU\_MAP\_INFO, \_T("&Map Info"));
    

    how do i handle the event of clicking that new item in the sysmenu ?? i have looked for something like it on the web but all i found is talking about CDialog and the WM_ON_SYSCOMMAND which doesn't seem to work for me. anyone ? Thank's Eyal

    _ 1 Reply Last reply
    0
    • E eyalle

      Hello all, I have a class CChildFrame : public CMDIChildWnd : public CFrameWnd i have declared a new item in sysMenu called "Map Info"

      	CMenu \*pSysMenu = pFrm->GetSystemMenu(FALSE);
      	ASSERT(pSysMenu != NULL);
      	pSysMenu->AppendMenu(MF\_STRING, IDI\_SYS\_MENU\_MAP\_INFO, \_T("&Map Info"));
      

      how do i handle the event of clicking that new item in the sysmenu ?? i have looked for something like it on the web but all i found is talking about CDialog and the WM_ON_SYSCOMMAND which doesn't seem to work for me. anyone ? Thank's Eyal

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Create a dialog based application and see how the About menu is added and handled. It is indeed the ON_WM_SYSCOMMAND macro and the OnSysCommand method.

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      E 1 Reply Last reply
      0
      • _ _Superman_

        Create a dialog based application and see how the About menu is added and handled. It is indeed the ON_WM_SYSCOMMAND macro and the OnSysCommand method.

        «_Superman_»
        I love work. It gives me something to do between weekends.

        Microsoft MVP (Visual C++)

        Polymorphism in C

        E Offline
        E Offline
        eyalle
        wrote on last edited by
        #3

        But isn't the OnSysCommand used only for CDialog while im using already a CFrame ?

        _ 1 Reply Last reply
        0
        • E eyalle

          But isn't the OnSysCommand used only for CDialog while im using already a CFrame ?

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          I just tried it and it works perfectly. I added the menu from within my frame class. Added the following in OnCreate -

          CMenu *pSysMenu = GetSystemMenu(FALSE);
          ASSERT(pSysMenu != NULL);
          pSysMenu->AppendMenu(MF_STRING, 10101, _T("&About ..."));

          Added ON_WM_SYSCOMMAND() in between the message map macros. Added the following method -

          void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
          {
          if (nID == 10101)
          MessageBox(L"About me");

          CFrameWnd::OnSysCommand(nID, lParam);
          

          }

          «_Superman_»
          I love work. It gives me something to do between weekends.

          Microsoft MVP (Visual C++)

          Polymorphism in C

          E 1 Reply Last reply
          0
          • _ _Superman_

            I just tried it and it works perfectly. I added the menu from within my frame class. Added the following in OnCreate -

            CMenu *pSysMenu = GetSystemMenu(FALSE);
            ASSERT(pSysMenu != NULL);
            pSysMenu->AppendMenu(MF_STRING, 10101, _T("&About ..."));

            Added ON_WM_SYSCOMMAND() in between the message map macros. Added the following method -

            void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
            {
            if (nID == 10101)
            MessageBox(L"About me");

            CFrameWnd::OnSysCommand(nID, lParam);
            

            }

            «_Superman_»
            I love work. It gives me something to do between weekends.

            Microsoft MVP (Visual C++)

            Polymorphism in C

            E Offline
            E Offline
            eyalle
            wrote on last edited by
            #5

            I've tried to take ur example and plant it in my code. the thing is that for some reason, in my Class Wizard i couldn't find WM_SYSCOMMAND message, so i implemented it manually like you said in between the message map macros. but still, when i click on the "About" item, nothing happen's.. no trigger pumps the event. maybe something im missing ?

            _ 1 Reply Last reply
            0
            • E eyalle

              I've tried to take ur example and plant it in my code. the thing is that for some reason, in my Class Wizard i couldn't find WM_SYSCOMMAND message, so i implemented it manually like you said in between the message map macros. but still, when i click on the "About" item, nothing happen's.. no trigger pumps the event. maybe something im missing ?

              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              This is how I added the WM_SYSCOMMAND handler - Right click on CMainFrame from Class View and select Properties. Click in the Messages icon in the Properties window. Here you will find WM_SYSCOMMAND. Add the handler for this here.

              «_Superman_»
              I love work. It gives me something to do between weekends.

              Microsoft MVP (Visual C++)

              Polymorphism in C

              E 1 Reply Last reply
              0
              • _ _Superman_

                This is how I added the WM_SYSCOMMAND handler - Right click on CMainFrame from Class View and select Properties. Click in the Messages icon in the Properties window. Here you will find WM_SYSCOMMAND. Add the handler for this here.

                «_Superman_»
                I love work. It gives me something to do between weekends.

                Microsoft MVP (Visual C++)

                Polymorphism in C

                E Offline
                E Offline
                eyalle
                wrote on last edited by
                #7

                Im using VC6++ , are you ?

                _ 1 Reply Last reply
                0
                • E eyalle

                  Im using VC6++ , are you ?

                  _ Offline
                  _ Offline
                  _Superman_
                  wrote on last edited by
                  #8

                  No. I tried this in VS2010. But if you add this manually it should work. Did you add the ON_WM_SYSCOMMAND macro?

                  «_Superman_»
                  I love work. It gives me something to do between weekends.

                  Microsoft MVP (Visual C++)

                  Polymorphism in C

                  E 1 Reply Last reply
                  0
                  • _ _Superman_

                    No. I tried this in VS2010. But if you add this manually it should work. Did you add the ON_WM_SYSCOMMAND macro?

                    «_Superman_»
                    I love work. It gives me something to do between weekends.

                    Microsoft MVP (Visual C++)

                    Polymorphism in C

                    E Offline
                    E Offline
                    eyalle
                    wrote on last edited by
                    #9

                    I dont think so, how do i add it ? what i did in my .h file is:

                    protected:
                    //{{AFX_MSG(CChildFrame)
                    afx_msg void OnClose();
                    afx_msg void OnSize(UINT nType, int cx, int cy);
                    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
                    afx_msg void OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd);
                    //This functions were inserted by the class wizard...
                    //}}AFX_MSG
                    DECLARE_MESSAGE_MAP()
                    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
                    };

                    then on the .cpp file:

                    void CChildFrame::OnSysCommand(UINT nID, LPARAM lParam)
                    {
                    //...
                    }

                    _ 1 Reply Last reply
                    0
                    • E eyalle

                      I dont think so, how do i add it ? what i did in my .h file is:

                      protected:
                      //{{AFX_MSG(CChildFrame)
                      afx_msg void OnClose();
                      afx_msg void OnSize(UINT nType, int cx, int cy);
                      afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
                      afx_msg void OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd);
                      //This functions were inserted by the class wizard...
                      //}}AFX_MSG
                      DECLARE_MESSAGE_MAP()
                      afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
                      };

                      then on the .cpp file:

                      void CChildFrame::OnSysCommand(UINT nID, LPARAM lParam)
                      {
                      //...
                      }

                      _ Offline
                      _ Offline
                      _Superman_
                      wrote on last edited by
                      #10

                      You need this in the .cpp file -

                      BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
                      ON_WM_CREATE()
                      ON_WM_CTLCOLOR()
                      ON_WM_SYSCOMMAND()
                      END_MESSAGE_MAP()

                      «_Superman_»
                      I love work. It gives me something to do between weekends.

                      Microsoft MVP (Visual C++)

                      Polymorphism in C

                      E 1 Reply Last reply
                      0
                      • _ _Superman_

                        You need this in the .cpp file -

                        BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
                        ON_WM_CREATE()
                        ON_WM_CTLCOLOR()
                        ON_WM_SYSCOMMAND()
                        END_MESSAGE_MAP()

                        «_Superman_»
                        I love work. It gives me something to do between weekends.

                        Microsoft MVP (Visual C++)

                        Polymorphism in C

                        E Offline
                        E Offline
                        eyalle
                        wrote on last edited by
                        #11

                        Ok man, i've found the solution in VC6++ i've went to the class view of the class Frame im using. right-click -> Add Windows Message Handler.. then on the bottom under: "Filter for messages available for class" i selected "Window" and added the WM_SYSCOMMAND to my class wizard. now it work's i think that the problam was that even if i added it manualy, there was no trigger to the event. now since the message is in the wizard, and known by the compailer it triggers the event. Thank's anyway.. Good day

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups