MFC Programmer WTL Guide (4) tool bar and status bar

Source: Internet
Author: User

Introduction to the third part

The tool bar and status bar have become commonplace since the advent of a common control as Windows 95. MFC supports floating toolbars to make them more popular. With the update of a generic control, rebars (originally known as Coollbar) makes the sidebar a different way of showing. In the third part, I'll introduce WTL support for these control bars and how to use them in your program.

Toolbar and Status bar for main window

Cframewindowimpl There are three HWND type member variables initialized when the window was created, we've seen M_hwndclient, which is the handle to the view window that fills the client area of the main window, and now we've encountered another two:

    • M_hwndtoolbar: Tool bar or rebar window handle
    • M_hwndstatusbar: Window Handle of status bar

Cframewindowimpl only supports a toolbar, there is no more than MFC as a dockable toolbar, if you want to use multiple toolbars and do not want to modify the Cframewindowimpl of the internal code, you need to use the rebar. I'll introduce them both and show you how to add toolbars and rebar using the Application wizard.

The cframewindowimpl::onsize () message response function calls Updatelayout (), and Updatelayout () does two things: reposition all the control bars and change the size of the view window to fill the entire customer area. The actual work was done by Updatebarsposition (), and Updatelayout () just called the function. The implemented code is fairly simple, sending wm_size messages to the sidebar and status bar, which are positioned at the top or bottom of the main window by the default window process of the control bars.

When you tell the Application Wizard to add toolbars and status bars to your window, the wizard adds the code to create them in CMainFrame::OnCreate (). Now let's take a look at the code, of course, to write another clock program.

The wizard generates code for the toolbar and status bar

We'll start a new project and have the Wizards create toolbars and status bars for the main window. First create a new project called WTLClock2, and on the first page of the wizard, select SDI and make the Generate CPP file check box selected:

On the second page, cancel rebar so that the wizard simply creates a common toolbar:

Copy the corresponding code from the second part of the program, and the new program looks like this:

Cmainfracmainframe How to create a tool bar and a status bar

In this example, the wizard adds more code to the CMainFrame::OnCreate () function, which is to create the control bar and notify the Cupdateui to update the buttons on the toolbar.

LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/,
               LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
   CreateSimpleToolBar();
   CreateSimpleStatusBar();
   m_hWndClient = m_view.Create(...);
// ...
   // register object for message filtering and idle updates
   CMessageLoop* pLoop = _Module.GetMessageLoop();
   ATLASSERT(pLoop != NULL);
   pLoop->AddMessageFilter(this);
   pLoop->AddIdleHandler(this);
   return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.