CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old February 1st, 2001, 09:32 AM
    Djibril Djibril is offline
    Member
     
    Join Date: May 1999
    Location: Canada
    Posts: 176
    Djibril is an unknown quantity at this point (<10)
    How to add menu to a Dialog

    Hello

    I use to add menu to a dialog box by adding a menu to the resources and then select the dlg class for the menu.

    This is not working anymore. I wonder if there is something special with Visual 6 or not.
    Or do u just know another way to add menu to a dialog app ?

    Thanks.


    --
    Where there is a WISH, there is a WILL.
    Reply With Quote
      #2    
    Old February 1st, 2001, 09:35 AM
    Weiye Weiye is offline
    Senior Member
     
    Join Date: Jun 1999
    Location: Singapore
    Posts: 1,304
    Weiye is an unknown quantity at this point (<10)
    Re: How to add menu to a Dialog

    You can try using SetMenu(...), but before that you need to load your menu resource into a CMenu object using LoadMenu(...), as the parameter to SetMenu(...) is a pointer to a CMenu object.

    Chen Weiye
    ------------------------------------------------------------------------------
    When pursuing your dream, don't forget to enjoy your life...
    ------------------------------------------------------------------------------
    __________________
    Chen Weiye
    -----------------------------------------------------------------------------
    When pursuing your dream, don't forget to enjoy your life
    -----------------------------------------------------------------------------
    Reply With Quote
      #3    
    Old February 1st, 2001, 09:40 AM
    Emi's Avatar
    Emi Emi is offline
    Elite Member
     
    Join Date: May 2000
    Location: Toronto, ON, Canada
    Posts: 3,573
    Emi is on a distinguished road (10+)
    Re: How to add menu to a Dialog

    Hi,

    See this// in OnInitDialog
    Menu.LoadMenu(IDR_MENU1);
    SetMenu(&Menu);

    Just add as member variable in your class CMenu Menu and insert a menu from resource (let the default ID).

    HTH.

    Regards,

    Emi.
    __________________
    Regards,

    Emanuel Vaduva
    Reply With Quote
      #4    
    Old February 1st, 2001, 09:48 AM
    Djibril Djibril is offline
    Member
     
    Join Date: May 1999
    Location: Canada
    Posts: 176
    Djibril is an unknown quantity at this point (<10)
    Re: How to add menu to a Dialog

    Thanks a lot. It worked!

    --
    Where there is a WISH, there is a WILL.
    Reply With Quote
      #5    
    Old February 1st, 2001, 09:50 AM
    Emi's Avatar
    Emi Emi is offline
    Elite Member
     
    Join Date: May 2000
    Location: Toronto, ON, Canada
    Posts: 3,573
    Emi is on a distinguished road (10+)
    Re: How to add menu to a Dialog

    You are welcome.

    Regards,

    Emi.
    __________________
    Regards,

    Emanuel Vaduva
    Reply With Quote
      #6    
    Old February 1st, 2001, 10:01 AM
    Djibril Djibril is offline
    Member
     
    Join Date: May 1999
    Location: Canada
    Posts: 176
    Djibril is an unknown quantity at this point (<10)
    Re: How to add menu to a Dialog

    thanks a lot.

    --
    Where there is a WISH, there is a WILL.
    Reply With Quote
      #7    
    Old February 1st, 2001, 10:54 AM
    Weiye Weiye is offline
    Senior Member
     
    Join Date: Jun 1999
    Location: Singapore
    Posts: 1,304
    Weiye is an unknown quantity at this point (<10)
    Re: How to add menu to a Dialog

    No problem. You are welcome.

    Chen Weiye
    ------------------------------------------------------------------------------
    When pursuing your dream, don't forget to enjoy your life...
    ------------------------------------------------------------------------------
    __________________
    Chen Weiye
    -----------------------------------------------------------------------------
    When pursuing your dream, don't forget to enjoy your life
    -----------------------------------------------------------------------------
    Reply With Quote
      #8    
    Old May 18th, 2001, 06:41 PM
    Louis Louis is offline
    Junior Member
     
    Join Date: Jul 2001
    Location: Quebec, Canada
    Posts: 4
    Louis is an unknown quantity at this point (<10)
    Re: How to add menu to a Dialog

    Emi,
    I know U are one of the most talented gurus around here. U help us a lot.
    To tell U the truth, I'm learning VC++ by examples.
    This ex is like this (also from this forum)
    Dialog-based draw either line or rectangle. In the header of Dlg.h I added
    #define MODE_LINE 1
    #define MODE_RECT 2

    typedef CArray&lt;POINT,POINT&&gt; CPoly;
    typedef CArray&lt;CPoly*,CPoly*&gt; CPolyArray;
    ///////////////////////////////////////
    In Dlg.h, at constructor I added
    int m_mode;
    BOOL m_draw;
    CPoint m_click,m_move;
    CPolyArray m_objects;

    public:
    CLineDrawDlg(CWnd* pParent = NULL); // standard constructor
    void DeleteObjects();
    In Dlg.cpp I added under
    m_hIcon = AfxGetApp()-&gt;LoadIcon(IDR_MENU2);//LoadIcon(IDR_MAINFRAME);
    the following:
    m_mode = MODE_LINE;
    m_draw = FALSE; and in func.
    void CLinedraw050101Dlg:eleteObjects()
    {
    for(int i=0; i&lt;m_objects.GetSize(); i++)
    delete m_objects[i];
    m_objects.RemoveAll();
    }
    In OnInitDialog(), I added: CMenu Menu; Menu.LoadMenu(IDR_MENU2);SetMenu(&Menu);
    In OnPaint() I added: CPaintDC dc(this); // device context for painting
    // draw all objects
    for(int i=0; i&lt;m_objects.GetSize(); i++)
    dc.Polyline(m_objects[i]-&gt;GetData(),m_objects[i]-&gt;GetSize());

    // CDialog::OnPaint();
    In OnUpdateLine(CCmdUI* pCmdUI) , I added: pCmdUI-&gt;SetCheck(m_mode == MODE_LINE);
    In OnUpdateRect(CCmdUI* pCmdUI) , I added: pCmdUI-&gt;SetCheck(m_mode == MODE_RECT);
    In OnLButtonDown(UINT nFlags, CPoint point) , I added: m_click = m_move = point;
    m_draw = TRUE; SetCapture();
    In OnLButtonUp(UINT nFlags, CPoint point) , I added: if(m_draw)
    {
    ReleaseCapture();
    m_draw = FALSE;
    switch(m_mode)
    {
    case MODE_LINE:
    {
    CPoly *po;
    if(!(po = new CPoly))
    break;
    po-&gt;Add(m_click);
    po-&gt;Add(point);
    m_objects.Add(po);
    InvalidateRect(0,0);
    break;
    }
    case MODE_RECT:
    {
    CPoly *po;
    if(!(po = new CPoly))
    break;
    po-&gt;Add(m_click);
    po-&gt;Add(CPoint(point.x,m_click.y));
    po-&gt;Add(point);
    po-&gt;Add(CPoint(m_click.x,point.y));
    po-&gt;Add(m_click);
    m_objects.Add(po);
    InvalidateRect(0,0);
    break;
    }
    }
    }
    In OnMouseMove(UINT nFlags, CPoint point) , I added: if(m_draw)
    {
    CDC *dc=GetDC();
    CRect re;
    CRect lre(m_click,m_move); // the rectangle of last movement
    CRect cre(m_click,point); // the rectangle of current movement
    lre.NormalizeRect();
    cre.NormalizeRect();
    re.UnionRect(lre,cre); // union rectangle of last + current movement
    re.InflateRect(2,2); // to include the border
    InvalidateRect(re,TRUE);
    UpdateWindow(); // update the modified rectangle
    switch(m_mode)
    {
    case MODE_LINE:
    dc-&gt;MoveTo(m_click);
    dc-&gt;LineTo(point);
    break;

    case MODE_RECT:
    dc-&gt;MoveTo(m_click);
    dc-&gt;LineTo(CPoint(point.x,m_click.y));
    dc-&gt;LineTo(point);
    dc-&gt;LineTo(CPoint(m_click.x,point.y));
    dc-&gt;LineTo(m_click);
    break;
    }
    m_move = point;
    }
    In PostNcDestroy() , I added: CDialog::PostNcDestroy();DeleteObjects();
    In OnClose() , I added: CDialog::OnCancel(); CDialog::OnClose();
    In OnCircle() , I added: m_mode = MODE_LINE; and in OnRectangle() , I added: m_mode = MODE_RECT; ( Plaese bear with me, newbie)
    When run my proj. I don't see "MODE" to select either Circle or Rectangle.
    Please help. L


    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:25 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009