MFC toolbar and status bar

Source: Internet
Author: User

 

Windows Control Window

Windows (Windows 95 or later) provides a series of universal control Windows, including ToolBar, Status Bar, and ToolTip ).

Windows registers a "window class" of the control window when a DLL is loaded ". For example, the "window class" of the toolbar is "ToolbarWindow32", the "window class" of the status bar is "msctls_statusbar32", and the "window class" of the toolbar Prompt window is "tooltips_class32 ". To ensure that the DLL is loaded, call the InitCommonControl function before using the "window class. MFC implements this in the window registration function AfxDeferRegisterClass. See section 2.2.1 "register" in the MFC window.

Create a universal control window. You can use a dedicated function to create a toolbar, for example, a function to create a toolbar.: Createmedilbarex, function for creating the status bar: CreateStatusBarEx. You can also call the window creation function: createmediawex, but you need to specify the pre-defined "window class". If necessary, perform other steps, such as using "ToolbarWindow32" and "window class" to create a toolbar, you also need to add or insert buttons in the toolbar.

Generally, the control window style can be specified for general control.(Style ). For example, A CCS_TOP style indicates that the control window is placed at the top of the customer area of the parent window and CCS_BOTTOM indicates that the control window is located at the bottom of the customer area. The specific control window class can have a special style suitable for you. For example, TTS_ALWAYSTIP indicates that the ToolTip window will be displayed whether activated or not as long as the cursor falls on the toolbar button.

Each control window class has its own window process to process its own window messages and implement specific functions. Control the Window ProcessWindows.

Tool bar

The Window Process of the toolbar processes necessary messages and provides the functions of the Standard toolbar. For example, the toolbar provides internal support for custom features, you can add, modify, delete, or reschedule toolbar buttons in a custom dialog box. Whether these features can be used or used by users can be controlled by the program.

The size and position of the toolbar are automatically set during the toolbar window process.CCS_TOP or CCS_BOTTOM, the toolbar is placed at the top or bottom of the client area of the parent window during the window process. The size and position of the toolbar are automatically adjusted as long as the message WM_SIZE or TB_AUTOSIZE is received during the window process.

After the toolbar button is selected, a command message is generated. The Window Process sends the message to the parent window for processing.

The buttons in the toolbar are not displayed as subwindows, but are displayed as characters or Bitmap Buttons. Each button is of the same size. The default value is24*22 pixels. Each button has an index with the index number starting from 0. Each button includes the following attributes:

Button string index, bitmap index, style, status, commandID

Buttons can have two stylesTBSTYLE_BUTTON and TBSTYLE_CHECK. The former responds to the user's press as a standard button, and the latter responds to each press, switching between the press and hop statuses. To send a command message containing the corresponding command ID to the parent window. Generally, the command ID of a button corresponds to a menu item.

The toolbar maintains two lists, which are used to store the strings or bitmaps used by the toolbar buttons.Start from 0. The number corresponds to the index of the button.

Tool bar can beDockable or Floatable.

Tool bar can haveTBSTYLE_TOOLTIPS style. If this style is used, a Tooltip control is created and managed. This is a small pop-up window used to display the text of the Description button, which is usually hidden, when the mouse falls on the button and stays for about one second, it is displayed near the mouse.

BecauseThe Tooltip window is usually hidden, so you cannot receive mouse messages to decide when to display the window. In this way, the window that receives the mouse must send the mouse message to the Tooltip window, which is achieved by sending the message TTM_RELAYEVENT to the Tooptip window.

Status Bar

The status bar is similar to a tool bar. It has its own window process and can be berth or floating. Normally, the status bar is located at the bottom of the screen. Each status bar is divided into several cells (Status bar panes). Each grid starts from 0 and the number is used as the index of the grid. Every cell, like a toolbar button, is not a Windows window.

Tool bar and status bar of MFC

MFC uses the CToolBarCtrl, CStatusBarCtrl, and CToolTipCtrl window classes to encapsulate the toolbar, Status Bar, and Tooltip control windows respectively.

However, it is not convenient to directly use these classes.MFC provides CToolBar and CStatusBar to process the status bar and toolbar. CToolBar and CStatusBar are more powerful and flexible. Both classes are derived from CControlBar.

InIn MFC, it is recommended that the IDs of these control strips be between AFX_IDW_TOOLBARFIRST (0xE800) and AFX_IDW_CONTROLBAR_LAST (0Xe8FF. Among the 256 IDs, the first 32 have their own characteristics and are used in the print preview of MFC.

CControlBar is derived from the CWnd class and is the base class of the control bar window class. It derives from the CToolBar, CStatusBar, CDockBar, CDialogBar, and COleResizeBar classes. CControlBar provides the following functions:

Align with the top or bottom or other sides of the parent window (border window.

It can contain sub-entries.HWND subwindow, or non-HWND-based entries. Allocates an array of entries.

SupportedCBRS_TOP (by default, the control bar is placed on the top), CBRS_BOTTOM (placed on the bottom), CBRS_NOALIGN (the control bar is not placed again when the size of the parent window changes), and other control styles.

Supports the implementation of derived classes. Several Derived classes have certain commonalities, or two of them have certain commonalities.Some functions implemented by CControlBar only apply to a derived class, some apply to two or more Derived classes, and some apply to all derived classes. The so-called applicability means that the derived class directly inherits the implementation of CControlBar, or overwrites its implementation, but is based on the extension of its implementation. Similarly, the member variables of CControlBar are not applicable to all derived classes.

On the one hand, CStatusBar and CControlBar are built on CControlBar, and on the other hand, they are based on Windows's general control status bar and toolbar. They inherit the features of the CControlBar class, but the encapsulated window handle is the handle of the corresponding Windows control window, just as CFormView inherits the class-based features of CSrcollView, however, the window handle is the same as the window handle of the modeless dialog box.

 

Related Article

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.