MFC Tutorial-mfc toolbar and status bar (1)

Source: Internet
Author: User
Tags client

Windows Control window

Windows (Windows95 or above) provides a series of common control windows, including a toolbar (ToolBar), a status bar (StatusBar), a ToolTip window (TOOLTIP).

Windows registers the window class for a control window when a DLL is loaded. For example, the window class for the toolbar is ToolbarWindow32, the window class of the status bar is Msctls_statusbar32, and the window class of the ToolTip window is tooltips_class32. To ensure that the DLL is loaded, the function Initcommoncontrol should be called first before using the control "window class". MFC implements this in the window registration function Afxdeferregisterclass. See the registration of Windows 2.2.1 under MFC.

To create a common control window, you can use specialized creation functions, such as the function to create a toolbar:: Createtoolbarex, create a function of the status bar:: Createstatusbarex. You can also call the window to create a function:: CreateWindowEx, but you need to specify a predefined window class, and if necessary, other steps, such as the use of the ToolbarWindow32 window class to create a toolbar, you need to add or insert a button in the toolbar.

Generally, general control can specify control window style (style). For example, a style ccs_top means that the control window is placed at the top of the client area of the parent window, with Ccs_bottom, indicating that the control window is at the bottom of the client area. The specific control window class can have a particular style that suits you, for example, Tts_alwaystip says that whenever the cursor falls on a toolbar button, the ToolTip window is displayed regardless of whether it is active or not.

Each control window class has its own window process to handle its own window messages to implement specific functions. window procedures for controlling window classes are provided by Windows.

Tool bar

The window process of the sidebar handles the necessary messages and provides the functionality of the Standard toolbar, for example, the sidebar provides intrinsic support for the custom features, and users can add, modify, delete, or rearrange the toolbar buttons through a custom dialog box. Whether these features can be used by users or where they can be used is controlled by the program.

The window procedure for the toolbar automatically sets the size and position of the bar, and if the control window style ccs_top or ccs_bottom is specified, the window procedure places the toolbar at the top or bottom of the client area of the parent window. The window process automatically adjusts the size and position of the toolbar whenever you receive a wm_size or tb_autosize message.

When the toolbar button is selected, a command message is generated that sends the message to the window process of the parent window.

The buttons in the sidebar do not appear as child windows, but rather as characters or bitmap buttons, each with the same size and by default 24*22 pixels. Each button has an index, and the index number starts at 0. Each button includes the following properties:

String index of the button, bitmap index, style, status, command ID

Buttons can have two styles Tbstyle_button and Tbstyle_check, the former in response to a user's hit like a standard button, which responds to each keystroke by switching between two states, press and jump. Button responds to the user's action and sends a command message containing the button's corresponding command ID to the parent window. A general command ID for a button corresponds to a menu item.

The sidebar maintains two lists, which are used to hold the string or bitmap used by the toolbar button, the bitmap in the list, or the string from the 0 start number, and the index corresponding to the button.

The tool bar may be dockable (berth) or floatable (floating).

The sidebar can have a tbstyle_tooltips style, if it has this style, then create and manage a ToolTip control, this is a small pop-up window, used to display the text of the description button, usually the window hidden, when the mouse fell to the button above and stay about a second before popping up, displayed near the mouse.

Because the ToolTip window is usually hidden, you cannot receive mouse messages to determine when this window will be displayed. In this way, the window that receives the mouse must give the mouse message to the ToolTip window, which is implemented by sending a message to the Tooptip window ttm_relayevent.

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.