CPropertySheet的基本用法

来源:互联网 发布:女神很少网络 编辑:程序博客网 时间:2024/06/13 10:17

和别人讨论问题,要实现一个MFCDialog内的内嵌属性页,实现Tab的效果.
以前玩过,现在不记得怎么做,去查了msdn, 写个demo记录一下。

demo下载点

srcTestTabDlg.zip
编译环境:vs2010 on win10x64

效果

这里写图片描述

代码预览

代码是从msdn上找的,建立动态的属性表,属性表中加属性页。

// testTabDlgDlg.h : header file//#pragma once#include "Page1.h"#include "Page2.h"// CtestTabDlgDlg dialogclass CtestTabDlgDlg : public CDialogEx{// Constructionpublic:    CtestTabDlgDlg(CWnd* pParent = NULL);   // standard constructor// Dialog Data    enum { IDD = IDD_TESTTABDLG_DIALOG };    protected:    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support// Implementationprotected:    HICON m_hIcon;    // Generated message map functions    virtual BOOL OnInitDialog();    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);    afx_msg void OnPaint();    afx_msg HCURSOR OnQueryDragIcon();    DECLARE_MESSAGE_MAP()public:    afx_msg void OnBnClickedOk();private:    CPropertySheet* m_pSheet;    CPage1 m_Page1;    CPage2 m_Page2;public:    afx_msg void OnDestroy();    afx_msg void OnSize(UINT nType, int cx, int cy);};
// testTabDlgDlg.cpp : implementation file//#include "stdafx.h"#include "testTabDlg.h"#include "testTabDlgDlg.h"#include "afxdialogex.h"#ifdef _DEBUG#define new DEBUG_NEW#endif// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogEx{public:    CAboutDlg();// Dialog Data    enum { IDD = IDD_ABOUTBOX };    protected:    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support// Implementationprotected:    DECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD){}void CAboutDlg::DoDataExchange(CDataExchange* pDX){    CDialogEx::DoDataExchange(pDX);}BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)END_MESSAGE_MAP()// CtestTabDlgDlg dialogCtestTabDlgDlg::CtestTabDlgDlg(CWnd* pParent /*=NULL*/)    : CDialogEx(CtestTabDlgDlg::IDD, pParent){    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);    m_pSheet = NULL;}void CtestTabDlgDlg::DoDataExchange(CDataExchange* pDX){    CDialogEx::DoDataExchange(pDX);}BEGIN_MESSAGE_MAP(CtestTabDlgDlg, CDialogEx)    ON_WM_SYSCOMMAND()    ON_WM_PAINT()    ON_WM_QUERYDRAGICON()    ON_BN_CLICKED(IDOK, &CtestTabDlgDlg::OnBnClickedOk)    ON_WM_DESTROY()    ON_WM_SIZE()END_MESSAGE_MAP()// CtestTabDlgDlg message handlersBOOL CtestTabDlgDlg::OnInitDialog(){    CDialogEx::OnInitDialog();    // Add "About..." menu item to system menu.    // IDM_ABOUTBOX must be in the system command range.    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);    ASSERT(IDM_ABOUTBOX < 0xF000);    CMenu* pSysMenu = GetSystemMenu(FALSE);    if (pSysMenu != NULL)    {        BOOL bNameValid;        CString strAboutMenu;        bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);        ASSERT(bNameValid);        if (!strAboutMenu.IsEmpty())        {            pSysMenu->AppendMenu(MF_SEPARATOR);            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);        }    }    // Set the icon for this dialog.  The framework does this automatically    //  when the application's main window is not a dialog    SetIcon(m_hIcon, TRUE);         // Set big icon    SetIcon(m_hIcon, FALSE);        // Set small icon    // TODO: Add extra initialization here    m_pSheet = new CPropertySheet();    m_Page2.m_psp.dwFlags |= PSP_USETITLE;    m_Page2.m_psp.pszTitle = _T("Page2");    m_pSheet->AddPage(&m_Page2);    m_Page1.m_psp.dwFlags |= PSP_USETITLE;    m_Page1.m_psp.pszTitle = _T("Page1");    m_pSheet->AddPage(&m_Page1);    m_pSheet->Create(this, WS_CHILD);    m_pSheet->SetActivePage(0);    m_pSheet->ShowWindow(SW_SHOW);    HWND hWndSheet = ::GetDlgItem(m_hWnd, IDC_STATIC_SHEET);    RECT rt;    ::GetWindowRect(hWndSheet, &rt);    m_pSheet->MoveWindow(0, 0, rt.right - rt.left, rt.bottom - rt.top, TRUE);    return TRUE;  // return TRUE  unless you set the focus to a control}void CtestTabDlgDlg::OnSysCommand(UINT nID, LPARAM lParam){    if ((nID & 0xFFF0) == IDM_ABOUTBOX)    {        CAboutDlg dlgAbout;        dlgAbout.DoModal();    }    else    {        CDialogEx::OnSysCommand(nID, lParam);    }}// If you add a minimize button to your dialog, you will need the code below//  to draw the icon.  For MFC applications using the document/view model,//  this is automatically done for you by the framework.void CtestTabDlgDlg::OnPaint(){    if (IsIconic())    {        CPaintDC dc(this); // device context for painting        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);        // Center icon in client rectangle        int cxIcon = GetSystemMetrics(SM_CXICON);        int cyIcon = GetSystemMetrics(SM_CYICON);        CRect rect;        GetClientRect(&rect);        int x = (rect.Width() - cxIcon + 1) / 2;        int y = (rect.Height() - cyIcon + 1) / 2;        // Draw the icon        dc.DrawIcon(x, y, m_hIcon);    }    else    {        CDialogEx::OnPaint();    }}// The system calls this function to obtain the cursor to display while the user drags//  the minimized window.HCURSOR CtestTabDlgDlg::OnQueryDragIcon(){    return static_cast<HCURSOR>(m_hIcon);}void CtestTabDlgDlg::OnBnClickedOk(){    // TODO: Add your control notification handler code here    CDialogEx::OnOK();}void CtestTabDlgDlg::OnDestroy(){    CDialogEx::OnDestroy();    // TODO: Add your message handler code here    if (NULL != m_pSheet) {        delete m_pSheet;        m_pSheet = NULL;    }}void CtestTabDlgDlg::OnSize(UINT nType, int cx, int cy){    CDialogEx::OnSize(nType, cx, cy);    // TODO: Add your message handler code here}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 11个月婴儿厌食怎么办 7个月的婴儿厌食怎么办 小孩记忆不好读书记不住怎么办 9岁儿童不爱睡觉怎么办 6岁儿童不爱吃饭怎么办 2岁半宝宝不吃饭怎么办 一年级的孩子不爱学习怎么办 小孩不爱写作业怎么办啊 孩子不爱看书怎么办如何教育 2岁宝宝不爱看书怎么办 儿媳妇比儿子年龄大我不喜欢怎么办 不喜欢儿子却生了儿子怎么办 静不下心来看书怎么办 孩子爱玩不爱学怎么办 孩子爱玩不爱学习怎么办 孩子爱玩手机不爱学习怎么办 照四维宝宝太活泼了怎么办 胎宝宝太活泼了怎么办 7个月宝宝太活泼怎么办 我是个初中生不想上学怎么办 3岁宝宝不肯说话怎么办 两周宝宝不爱吃饭怎么办 小孩不喜欢吃水果蔬菜怎么办 孩子对学习不感兴趣怎么办 幼儿园老师不喜欢我孩子怎么办 孩子数学不主动思考问题怎么办 孩子做事慢磨蹭家长应该怎么办 孩子不写作业怎么办啊 对孩子在校被欺怎么办 二年级的孩子不爱学习怎么办 孩子不爱学习怎么办二年级 二年级孩子不爱写作业怎么办 孩子喜欢的朋友家长不喜欢怎么办? 孩子不喜欢上幼儿园家长怎么办 孩子不喜欢家长学佛怎么办呢? 学生家长讨厌老师老师该怎么办 孩子不爱去幼儿园总是哭怎么办 孩子学习一点都不主动怎么办 孩子怕老师不想上学怎么办 幼儿园孩子怕老师不想上学怎么办 孩子在幼儿园怕老师怎么办