About tab Control

Source: Internet
Author: User

1. How to establish tag Control
Ctabctrl & tabctrl create the structure of the tag control object
Create creates tag control and binds objects
The call format of tag control ctabctrl: Create is as follows:
Bool create (DWORD dwstyle, const rect & rect, cwnd * pparentwnd, uint NID );
The dwstyle parameter is used to determine the label control style, rect is used to control the label size and position, pparentwnd is used to determine the parent window handle of the label control, and NID is used to determine the label control identifier.
The tag control style can be a combination of the following values:
Tcs_buttons indicates defining the label appearance as a similar button
Tcs_fixedwidth make all labels have the same width
Tcs_focusnever makes the specified tag never receive the input focus
Tcs_focusonbuttondown receives the input focus when the tag is clicked by the mouse. It is only used with tcs_buttons.
Tcs_forceiconleft: forces the icon to be on the left, and centralizes the label in the remaining part.
Tcs_forcelabelleft: Align icons and labels left
Tcs_multiline allows label control to display multiline labels
Tcs_ownerdrawfixed allows the parent window to customize labels
Tcs_rightjustify align labels right
Tcs_shareimagelists when the control is revoked, the image controlled by the tag is not revoked.
Tcs_tooltips allows tag control with tooltip Control
The tcs_tabs label is displayed normally and is in the default status.
Tcs_singleline displays the label on only one row. The default status is
Tcs_raggedright does not enable the label to automatically fill the control area. The default status is
Similarly, some control styles of the window can be used for tag control:
Ws_child creates a subwindow for the label control and can only be used with the ws_popup style.
Ws_visible creates an initial visible tag Control
Ws_disabled creates an initial invisible tag Control
Ws_group: create the first control for the tag control group.
Ws_tabstop
2. Tag-controlled attributes
Attribute classes of tag control include obtaining the image list getimagelist associated with Tag control, setting the image list setimagelist of tag control, obtaining the total number of tags getitemcount in tag control, obtaining tag control, special calibration answer getitem, setitem of some or all attributes of the tag, getcursel of the selected tag, setcursel of the selected tag, setcursel of the current input focus, etc..
3. Operation Method of tag Control
The operation methods of tag control include inserting a tag insertitem, deleting a tag deleteitem, deleting all projects deleteallitems from tag control, deleting an image list from tag control removeimage and drawing A specific item in tag control, such as drawitem.
(3) Data Structure of tag Control
When using tag control, you must use the function to insert tags in tag control. The original form of the insertitem function is as follows:
Bool insertitem (INT nitem, tc_item * ptabctrlitem );
The tc_item in this function is the data structure of the information used when adding tags. The data member definition method and meaning are as follows:
Typedef struct _ tc_item {
Uint mask; // determine the block or set bit of the structure member.
Uint lpreserved1; // reserved unused
Uint lpreserved2; // reserved unused
Lpstr psztext; // Tag Name string
Int cchtextmax; // Tag Name string buffer size
Int iimage; // image index number controlled by tags
Lparam; // 32-bit data defined by the application
} Tc_item;
When you click a tag in the tag control, the tag control will send related notification messages to its parent window. By processing these notification messages, the program can implement various functions.
(4) basic usage of attribute tables and attribute pages
In the tag control process, the Attribute Table dialog box and attribute page are essential. In the MFC class library, the cpropertysheet class of the Attribute Table dialog box is derived from the cwnd class, And the cpropertypage class of the attribute page class is derived from the cdialog class, and their usage is basically the same:
1. Create all property pages. The method for creating a property page is the same as that for creating a general dialog box resource. You can use the dialog box editor to create a dialog box template for each property page. The difference is that, when using the Class Wizard classwizard to generate a class for the property page, you should select the property page class cpropertypage as the base class instead of the general dialog box class cdialog as the base class;
2. Create an Attribute Table dialog box and add the created attribute pages in advance. The order of creation of the two is interchangeable, this step is required to add the property page to the property table dialog box after creation;
3. display the Attribute Table dialog box. Although the Attribute Table dialog box class cpropertysheet is not derived from the dialog box class cdialog, the operations are very similar. When you call the domodal () function, a modal Attribute Table dialog box is displayed, A non-modal Attribute Table dialog box is displayed when you call the CREATE () operation;
4. Data exchange processing. Similar to the dialog box, data exchange between the Attribute Table dialog box and objects is also achieved through data member 2, but the Attribute Table itself does not contain data members, what actually performs data exchange is the data member on the property page;
5. process the wizard dialog box. To display a wizard dialog box, call the setwizardmode () function to handle the wizard dialog box. For the wizard dialog box with buttons, call setwizardbuttons () to customize the button function of the wizard dialog box. At the end of the user's operation, call the setfinishtext () function to set the "complete" button to a valid state.
Top

1. Create an MFC dialog box framework, add a tab control from the Toolbox on the dialog box resource, modify the properties as needed, and right-click the control, add a variable for this control and bind it with a ctabctrl class variable. Set it to m_tabctrl
2. Create two new dialog box resources and modify their attributes as follows:
Border: NONE // the boundary is empty, so that it does not have the title bar.
Style: Child // This template can be used as a Child Window of another window.
Otherwise, you do not need to change it.
Add some controls or something above. The specific operation is no different from the normal dialog box.
Then, two new dialog box classes are generated from the two dialog box templates.
3. In the main dialog box, add two variables to the newly added classes:
For example, cdialog1 m_mm1;
Cdialog2 m_mm2;
4. Add the following code in the oninitdialog () function of the Main Dialog Box:
Tcitem item;
Item. Mask = tcif_text;
Item. psztext = "Page 1 ";

M_tabctrl.insertitem (0, & item );
Item. psztext = "Page 2 ";
M_tabctrl.insertitem (1, & item );

M_mm1.create (idd_dialog1, & m_tabctrl );
M_mm2.create (idd_dialog2, & m_tabctrl );

M_mm1.setwindowpos (null, 400,100, swp_showwindow );
M_mm2.setwindowpos (null, 400,100, swp_hidewindow );
Explanation:
The two insertitem functions are called to add two tag pages to the tag control. The text is the title.
The setwindowpos () function sets the position of the two dialogs in the Z sequence to display or hide the status ..
5. In the main dialog box, add a tcn_selchange control notification message for the tag control to notify the main dialog box when the tag is selected. On the editing page of the Main Dialog Box, right-click the tag control and select Add an event to complete this operation.
Add the following code to event processing:
Void ctabdialogdlg: ontcnselchangetab1 (nmhdr * pnmhdr, lresult * presult)
{
Crect R;
M_tabctrl.getclientrect (& R );

Switch (m_tabctrl.getcursel ())
{
Case 0:
M_mm1.setwindowpos (null, 10, 30, R. Right-20, R. Bottom-40, swp_showwindow );
M_mm2.setwindowpos (null, 10, 30, R. Right-20, R. Bottom-40, swp_hidewindow );
Break;
Case 1:
M_mm1.setwindowpos (null, 10, 30, R. Right-20, R. Bottom-40, swp_hidewindow );
M_mm2.setwindowpos (null, 10, 30, R. Right-20, R. Bottom-40, swp_showwindow );
Break;
}
* Presult = 0;
}
To know which tab the user selects, use the m_tabctrl.getcursel () function. In order not to overwrite the display of the label control in the subdialog box, you must obtain the size of the label control and set the size of each page.

If it is overwritten by another window, you need to adjust the position. Top

Two problems: first, wc_tabcontrol: class is the name in this province.
The creation style does not have ws_visible
Int cxchar = 10;
Int cychar = 5;
Int id_tabcontrol = 10000;

Hwnd hwndlist = createwindow (wc_tabcontrol, null,
Ws_child | ws_visible | tcs_ownerdrawfixed | tcs_multiline,
Cxchar * 3, cychar * 1,
Cxchar * 47 + getsystemmetrics (sm_cxvscroll ),
Cychar * 23,
M_hwnd, (hmenu) id_tabcontrol,
0, // (lpcreatestruct) lparam)-> hinstance,
Null );

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.