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}
阅读全文
0 0
- CPropertySheet的基本用法
- CPropertySheet 与CPropertyPage 的基本使用
- CPropertySheet
- CPropertySheet
- CPropertySheet的按钮的修改
- CPropertySheet的按钮的修改
- cpropertysheet 的几点知识
- [转] CPropertySheet的按钮的修改
- CPropertySheet去掉“帮助”等按钮的方法
- 去掉CPropertySheet中的帮助按钮的方法
- 修改CPropertySheet类默认的TAB位置
- MFC中CPropertySheet与CTabCtrl的使用
- 更改CPropertySheet中CPropertyPage的文本
- CPropertySheet属性页的一些使用方法
- 如何隐藏CPropertySheet 上的分隔线
- 怎样去掉 CPropertySheet 的帮助,应用按钮
- MFC中CPropertySheet与CTabCtrl的使用
- CPropertySheet里的帮助按钮如何去掉
- CSU1774-慷慨的奖励-链表
- HTML5中的新特性之Ajax篇
- hdu 1400 (插头)
- 手机射频架构解析
- 继承,实现,关联,聚合,组合,依赖几种关系的介绍
- CPropertySheet的基本用法
- Leetcode 207 Course Schedule
- CNTK API文档翻译(4)——MNIST数据加载
- Android——广播初介绍
- 使用Gallery和ImageSwitcher制作图片浏览器
- 服务调用框架DataStrom
- String、StringBuffer与StringBuilder之间区别
- WMS系统开发总结-自定义菜单或者显示的表格名字
- A New Start