CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Location
    France
    Posts
    14

    Insert a ToolBar in a Dialog based app

    Hi..
    I was wondering how I could add a ToolBar to one of my Dialog Based MFC App...I could easily add a Menu bar, but I can't find the way to add a ToolBar...Could someone help me ?


  2. #2
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Insert a ToolBar in a Dialog based app

    If you embed a CToolBar object as a member of the dialogue class, then add a handler for the WM_CREATE message, then in the OnCreate() method it generates add these lines (stolen from CMainFrame as generated by AppWizard):

    --- if (!m_wndToolBar.Create(this) ||
    !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
    TRACE0("Failed to create toolbar\n");
    return -1; // fail to create
    }





    ---

    (where IDR_MAINFRAME is a toolbar resource).

    This should work. Does it help?



    --
    Jason Teagle
    [email protected]

  3. #3
    Join Date
    Apr 1999
    Posts
    44

    Re: Insert a ToolBar in a Dialog based app

    You should also add the following code after you have loaded the toolbar

    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);

    There is one problem , if you are calling your dialog from some other dialog/view then the second time you call it the toolbar does not load ... any solutions


  4. #4
    Join Date
    May 1999
    Location
    France
    Posts
    14

    Re: Insert a ToolBar in a Dialog based app

    Hi..thank you for your help..but well, I can't make it work...the toolbar doesn't appear in the dialog box..Maybe by adding the line talal tayyab just said, then it works...I'll try as soon I'm at home..I hope it'll work then..
    Thanks again 4 ur help both u jason and talal tayyab..


  5. #5
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Insert a ToolBar in a Dialog based app

    You'll be pleased to know that with Talal's added comment, it WILL work - but you will have to shift all controls on the dialogue box DOWN by the height of the toolbar.

    Normally, a frame window has the toolbar attached to one side and then places a client window (the view) inside the area left after the toolbar and status bar have been positioned; because the dialogue box puts controls directly onto its surface rather than on a client window placed inside the frame, the controls overlap the toolbar. It is, however, a simple thing to move them all down {:v).



    --
    Jason Teagle
    [email protected]

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