How to implement a property sheet controlled by a list control

Source: Internet
Author: User

Summary: Many MFC programs use the property sheet and property pages to implement the interface of option settings, but MFC itself provides the property sheet page functionality is limited, the interface is very primitive, some new software has achieved its own definition of the more beautiful property page. MFC's original property page is controlled through CTabCtrl, this paper gives a common method for page-switching with CListCtrl, and redraw the list control. CMyPropertySheet is a class derived from CPropertySheet, so you can still effortlessly take advantage of the many features of MFC CPropertySheet, the specific use of the method I will elaborate later.

The implementation of this property sheet is as follows:

Figure I

First, use

The CMyPropertySheet usage is similar to MFC's CPropertySheet, where you first create two property pages in your program, that is, two cpropertypage derived objects. Then add MyPropertySheet.cpp and MyPropertySheet.h to the project, including the CMyPropertySheet header file in the program's view class header file (assumed to be an SDI program)

#include “MyPropertySheet.h”

Set a new menu item in the Resource View "Options" (where you put them) add a response function with ClassWizard, add the following code in the function to create a property sheet object Myps

CMyPropertySheet myPS;

Then add two property pages to the property sheet.

myPS.AddPage(&m_page1);
myPS.AddPage(&m_page2);

Next you want to add an icon for the property page, which appears on the title of the corresponding list item and the property page, and note that the order added here is consistent with the order in which the property pages are added.

myPS.AddIcon(IDI_GLOBAL);
myPS.AddIcon(IDI_ADDITION);

Finally, the property page is created and displayed.

myPS.DoModal();

The rest of the work is exactly the same as the General property sheet.

The CMyPropertySheet class provides the following custom function to set the appearance of the property sheet.

Setsepratorcolor,setcaptioncolor and Setselectedcolor Both accept an argument of type COLORREF, which is used to set the list separator line, the property page title, and the color of the background of the list selection item.

Setlistfont sets the font for the list.

Readers can also expand them according to their own needs.

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.