VS2010-MFC (Common controls: Static text boxes)

Source: Internet
Author: User

Transferred from: http://www.jizhuomi.com/software/179.html

This concludes with an introduction to the use of dialogs and various common dialogs, starting with this section to explain the usage of various common controls. Common controls include: Static text boxes, edit boxes, radio buttons, check boxes, group boxes, list boxes, combo boxes, picture controls, list controls, tree controls, progress bar controls, and so on. This tutorial first explains the use of static text boxes.

notification message for the control

Before you use a static text box, you'll probably tell the control's notification message.

When an event occurs for a control, it sends a notification message to the parent window. The most common event is a mouse click, when the control sends a BN_CLICKED message to the parent window, which in effect sends a WM_COMMAND message to the parent window, with a notification message code in the WPARAM parameter (the notification message code when the mouse click is Bn_ CLICKED) and the control Id,lparam parameter contains a handle to the control. In the overview of the MFC message mapping mechanism, the message is made up of three parts: the message value, the wparam parameter, and the lparam parameter .

Adding a message-map and message-handling function to a control notification message has been done more than once. Now, for the details, the format of the control's message-map macro is roughly the following:

ON_ notification Message code (NID, Memberfun)

The NID parameter is the Id,memberfun parameter of the control that is the name of the message handler function. For example, on_bn_clicked (Idc_button1, &cdlg::onbnclickedbutton1). This message map macro should be added between Begin_message_map and End_message_map.

The syntax for a message-handling function declaration is:

afx_msg void Memberfun ();

use of static text boxes

In the previous example, you should also be aware of the general role of static text box, is used to display text description. MFC provides a CStatic class that encapsulates all operations on a static text box.

If we want to create static text boxes dynamically in a program instead of dragging directly from Toolbox to the dialog template as before, we need to use the member function of the CStatic class create. The prototype of the CREATE function is as follows:

Virtual BOOL Create (
LPCTSTR LpszText,
DWORD Dwstyle,
Const rect& RECT,
cwnd* pParentWnd,
UINT NID = 0xFFFF
);

Parameter description:

LpszText: Specifies the text to display in the control. If null, no text is displayed.

Dwstyle: Specifies the style of the static control. A static text box is typically a subwindow of a dialog box or other window, and is visible, so it should contain the ws_child and ws_visible styles, and, as illustrated in MSDN, you can also set any combination of styles in static control styles. Here are some of the styles that you might be explaining:

When we add a static text box to a dialog template, we can set its style in the static text box's property page, many of which correspond to the style above, for example, the simple attribute is equivalent to the ss_simple style.

Rect: Specifies the position and size of the static control, which can be a rect struct type or an object of the CRect class.

pParentWnd: Specifies the parent window of a static control, usually a CDialog object, and cannot be null.

NID: Specifies the ID of the static control.

Introduction to member functions of the CStatic class

The following is a brief introduction to the main member functions of the CStatic class, and here is a list of member functions.


In addition to the above member functions, since CStatic is a derived class of CWnd, many member functions of CWnd can also be used, such as GetWindowText, GetWindowRect, SetWindowText, and so on.

VS2010-MFC (Common controls: Static text boxes)

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.