CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2003
    Posts
    11

    Add an item to system menu

    How to add an item (i.e. About...) in the system menu in a CFormView derived application?
    Thanks.
    Last edited by Piccinano; December 4th, 2005 at 10:43 AM. Reason: Change title

  2. #2
    Join Date
    Jul 2005
    Location
    Bremen, Germany
    Posts
    33

    Re: CFormView and system menu

    Goto Resource view ..-.
    select Menu->IDR-Mainframe...
    there u can add your menu item ...

    Hope this answers to ur query...

    kings
    kings4u

  3. #3
    Join Date
    Jan 2003
    Posts
    11

    Re: CFormView and system menu

    With this code i can add menu item in the system menu

    CMenu* pMenu = GetSystemMenu(FALSE);
    pMenu->AppendMenu ( MF_SEPARATOR, 50, "");
    pMenu->AppendMenu ( MF_STRING, 50, "About...");


    .... but how handle the message and show the "About.." dialog?

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: CFormView and system menu

    Read MSDN on AppendMenu.
    The second parameter is the menu item command ID. In your case 50.
    So, if you pass X as the command ID in AppendMenu, simply add a ON_COMMAND handler like below:
    Code:
    ON_COMMAND(X,OnX)
    void CYourClass::OnX()
    {
    }
    BTW, you do not need to pass 50 for seperator, second parameter is ignored for seperators, so to avoid confusion, why not simply pass 0.

  5. #5
    Join Date
    Jan 2003
    Posts
    11

    Re: CFormView and system menu

    Quote Originally Posted by kirants
    Read MSDN on AppendMenu.
    The second parameter is the menu item command ID. In your case 50.
    So, if you pass X as the command ID in AppendMenu, simply add a ON_COMMAND handler like below:
    Code:
    ON_COMMAND(X,OnX)
    void CYourClass::OnX()
    {
    }
    BTW, you do not need to pass 50 for seperator, second parameter is ignored for seperators, so to avoid confusion, why not simply pass 0.
    Thanks for reply.

    I add

    pMenu->AppendMenu ( MF_SEPARATOR);
    pMenu->AppendMenu ( MF_STRING, ID_ABOUTBOX, "Information...");

    in CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

    Then add

    ON_COMMAND(ID_ABOUTBOX,OnClickedButtonAbout)

    in MESSAGE_MAP of CMainView

    but it doesn't show the About dialog with

    CAboutDlg aboutDlg;
    aboutDlg.DoModal();
    Last edited by Piccinano; December 5th, 2005 at 06:48 AM.

  6. #6
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: CFormView and system menu

    oops..sorry about that.. menu items in system menu generare WM_SYS_COMMAND and not WM_COMMAND.

    So, you need to add a
    Code:
    ON_WM_SYSCOMMAND()
    to your message map implemented as:
    Code:
    void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam) 
    {
    	// TODO: Add your command handler code here
    	if(ID_APP_ABOUT == nID)
    	{
    		CAboutDlg oDlg;
    		oDlg.DoModal();
    	}
    	else
    	{
    		CFrameWnd::OnSysCommand(nID,lParam);
    	}
    }
    Sorry about the confusion

  7. #7
    Join Date
    Jan 2003
    Posts
    11

    Re: CFormView and system menu

    Thanks.

    Now it works.

  8. #8
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: CFormView and system menu

    You are welcome

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured