cxcmfcpropertysheett是属性页的类吗

Posts - 113,
Articles - 0,
Comments - 0
00:48 by sylar_liang, ... 阅读,
1.添加对话框资源,为对话框创建类,继承于CPropertyPage
class CFirstPage : public CPropertyPage
// FirstPage.cpp
CFirstPage::CFirstPage()
: CPropertyPage(CFirstPage::IDD)
m_psp.dwFlags |= PSP_DEFAULT|PSP_HIDEHEADER;
class CSecondPage : public CPropertyPage
// SecondPage.cpp
CSecondPage::CSecondPage()
: CPropertyPage(CSecondPage::IDD)
m_psp.dwFlags |= PSP_DEFAULT|PSP_USEHEADERTITLE|PSP_USEHEADERSUBTITLE;
m_psp.pszHeaderTitle = _T("Title");
m_psp.pszHeaderSubTitle = _T("And subtitle");
建立这类对话框资源模板时有几点要注意
1)保留TitleBar属性。对话框标题就是将来显示在选项卡上的标签
2)对话框风格设为Child,边框设为Thin
3)将对话框设为Disabled
设置对话框属性页属性
在编写时要注意把对话框资源以下属性设置为对应值
属性名     &&值
System Menu&& &FalseStyle&     && ChildTitle Bar   & && FalseBorder    & &&None
// 如果想要去掉&应用&和&帮助&按钮
mms.m_psh.dwFlags |= PSH_NOAPPLYNOW;
mms.m_psh.dwFlags &= ~PSH_HASHELP;
mp1.m_psp.dwFlags &= ~PSP_HASHELP; // mp1 为FirstPage变量
&隐藏属性页默认按钮propsheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;或隐藏掉Cancel取消按钮:CWnd *pWnd = GetDlgItem( IDCANCEL );pWnd-&ShowWindow( FALSE );
2.建立新类,继承于CPropertySheet
class CMySheet: public CPropertySheet
DECLARE_DYNAMIC(CMySheet)
CMySheet(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
CMySheet(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
virtual ~CMySheet();
protected:
DECLARE_MESSAGE_MAP()
CFirstPage m_pgF
CSecondPage m_pgS
void Init(void);
CMySheet::CMySheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
CMySheet::CMySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
// init函数
void CMySheet::Init(void)
//SetWizardMode();
AddPage(&m_pgFirst);
AddPage(&m_pgSecond);
m_psh.dwFlags |= PSH_WIZARD97|PSH_WATERMARK|PSH_HEADER;
m_psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
m_psh.pszbmHeader = MAKEINTRESOURCE(IDB_BANNER_ICON);
// Step 2: Fix the problem to show images
m_psh.hInstance = AfxGetInstanceHandle();
3.主对话框添加按钮,点击弹出属性页
//创建表单类对象
CMySheet pro(L"表单样例");
pro.SetWizardMode(); // 设置向导对话框模式
//显示模态表单对话框
if(ID_WIZFINISH == pro.DoModal())
}// do something
4.向导模式相关函数
CPropertySheet::SetWizardButtons
CPropertySheet::SetWizardMode
CPropertyPage::OnWizardBack
CPropertyPage::OnWizardFinish
CPropertyPage::OnWizardNext
激活时OnSetActive
ID_APPLY_NOWID_WIZBACKID_WIZNEXTID_WIZFINISH
5.其他扩充(转载)
一、为了最大限度的发挥属性页的效用,首先让我们先从 CPropertySheet 继承一个新类,取名为 CMyPropSheet.接着便可以进行下面的各种操作:一、隐藏属性页默认按钮隐藏掉Apply应用按钮:propsheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;或隐藏掉Cancel取消按钮:CWnd *pWnd = GetDlgItem( IDCANCEL );pWnd-&ShowWindow( FALSE );
二、移动属性页按钮首先,要获取按钮的句柄,然后就可以象对待窗体一样处理它们了. 下面代码先隐藏掉Apply和Help铵钮,再把OK和Cancel按移动到右侧。
BOOL CMyPropSheet::OnInitDialog ()
BOOL bResult = CPropertySheet::OnInitDialog();
int ids [] = {IDOK, IDCANCEL};//, ID_APPLY_NOW, IDHELP };
// Hide Apply and Help buttons
CWnd *pWnd = GetDlgItem (ID_APPLY_NOW);
pWnd-&ShowWindow (FALSE);
pWnd = GetDlgItem (IDHELP);
pWnd-&ShowWindow (FALSE);
CRect rectB
int nSpacing = 6;
// space between two buttons...
for( int i =0; i & sizeof(ids)/sizeof(int); i++)
GetDlgItem (ids [i])-&GetWindowRect (rectBtn);
ScreenToClient (&rectBtn);
int btnWidth = rectBtn.Width();
rectBtn.left = rectBtn.left + (btnWidth + nSpacing)* 2;
rectBtn.right = rectBtn.right + (btnWidth + nSpacing)* 2;
GetDlgItem (ids [i])-&MoveWindow(rectBtn);
下面代码移动所有按钮到右侧,并且重新置属性页为合适的大小.
BOOL CMyPropSheet::OnInitDialog ()
BOOL bResult = CPropertySheet::OnInitDialog();
int ids[] = { IDOK, IDCANCEL, ID_APPLY_NOW };
CRect rectW
CRect rectB
GetWindowRect (rectWnd);
GetDlgItem (IDOK)-&GetWindowRect (rectBtn);
int btnWidth = rectBtn.Width();
int btnHeight = rectBtn.Height();
int btnOffset = rectWnd.bottom - rectBtn.
int btnLeft = rectWnd.right - rectWnd.
rectWnd.bottom = rectBtn.
rectWnd.right = rectWnd.right + btnWidth + btnO
MoveWindow(rectWnd);
rectBtn.left = btnL
rectBtn.right = btnLeft + btnW
for (int i = 0; i & sizeof (ids) / sizeof (int); i++)
rectBtn.top = (i + 1) * btnOffset + btnHeight *
rectBtn.bottom = rectBtn.top + btnH
GetDlgItem (ids [i])-&MoveWindow (rectBtn);
三、改变属性页上的标签文字首先修改TC_ITEM结构,然后用 SetItem 来修改标签文字,如下代码:
item.mask = TCIF_TEXT;
item.pszText = "New Label";
//Change the label of the first tab (0 is the index of the first tab)...
GetTabControl ()-&SetItem (0, &item);
四、改变属性页标签文字的字体属性代码如下
m_NewFont.CreateFont (14, 0, 0, 0, 800, TRUE, 0, 0, 1, 0, 0, 0, 0, _T("Arial") );
GetTabControl()-&SetFont (&m_NewFont);
五、在属性页标签上显示位图可以用 CImageList 建立图像. 用 SetItem 来设置,如下代码所示:
BOOL CMyPropSheet::OnInitDialog ()
  BOOL bResult = CPropertySheet::OnInitDialog();
  m_imageList.Create (IDB_MYIMAGES, 13, 1, RGB(255,255,255));
  CTabCtrl *pTabCtrl = GetTabControl ();
  pTabCtrl-&SetImageList (&m_imageList);
  TC_ITEM
  item.mask = TCIF_IMAGE;
  for (int i = 0; i & NUMBER_OF_TABS; i++)
    item.iImage =
    pTabCtrl-&SetItem (i, &item );
  return bR
六、在属性页左下角显示位图如下代码所示:
void CMyPropSheet::OnPaint ()
CPaintDC dc(this); // device context for painting
int nOffset = 6;
// load IDB_BITMAP1 from our resources
if (bmp.LoadBitmap (IDB_BITMAP1))
// Get the size of the bitmap
BITMAP bmpI
bmp.GetBitmap (&bmpInfo);
// Create an in-memory DC compatible with the
// display DC we''re using to paint
dcMemory.CreateCompatibleDC (&dc);
// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject (&bmp);
// Find a bottom-left point for the bitmap in the client area
GetClientRect (&rect);
int nX = rect.left + nO
int nY = rect.top + (rect.Height () - bmpInfo.bmHeight) - nO
// Copy the bits from the in-memory DC into the on-
// screen DC to actually do the painting. Use the centerpoint
// we computed for the target offset.
dc.BitBlt (nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,0, 0, SRCCOPY);
dcMemory.SelectObject (pOldBitmap);
// Do not call CPropertySheet::OnPaint() for painting messages
七、在属性页右下角显示3D文字Logo代码如下:
void CMyPropSheet::OnPaint ()
/////////////////////////////////////////////////////////////////
//在TAB按钮旁边显示3D文字提示,jingzhou xu
Cstring m_LogoName = &属性页&;
if(m_LogoName == "")
GetWindowRect(rect);
ScreenToClient(rect);
LOGFONT logF
ZeroMemory((void*)&logFont,sizeof(logFont));
strcpy(logFont.lfFaceName,"宋体");
logFont.lfHeight = -12;
logFont.lfWeight = 400;
logFont.lfCharSet = GB2312_CHARSET;
logFont.lfOutPrecision = 3;
logFont.lfClipPrecision = 2;
logFont.lfQuality = 1;
logFont.lfPitchAndFamily = 2;
m_font.CreateFontIndirect(&logFont);
SetFont(&m_font);
*pOldFont = pDC-&SelectObject(&m_font);
rect.left += 6;
rect.right -= 6;
rect.bottom -= 1;
rect.top = rect.bottom - ITEMBUTTON_HEIGHT + 1;
CFont m_LogoF
CString sLogoS
m_LogoFont.CreateFont(rect.Height()*4/5, 0, 0, 0, FW_BOLD, 1, FALSE, FALSE,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
FIXED_PITCH | FF_ROMAN, "楷体_GB2312");
sLogoString = m_LogoN
RECT m_rDataB
CopyRect(&m_rDataBox,&rect);
TEXTMETRIC
pDC-&GetTextMetrics(&tm);
CFont* oldFont = pDC-&SelectObject(&m_LogoFont);
CSize sz = pDC-&GetTextExtent(sLogoString, sLogoString.GetLength());
//用GetTextExtent来计算字体logo大小,依靠于设备环境,使用logo位于右下角
m_rDataBox.left = m_rDataBox.right
- sz.cx - tm.tmAveCharWidth/2;
m_rDataBox.top
= m_rDataBox.bottom - sz.cy - tm.tmHeight/5;
pDC-&SetBkMode(TRANSPARENT);
//用3D字体显示,先黑后白,最后再用默认色
COLORREF oldColor = pDC-&SetTextColor(GetSysColor(COLOR_3DDKSHADOW));
pDC-&DrawText(sLogoString, sLogoString.GetLength(), &m_rDataBox, DT_VCENTER | DT_SINGLELINE | DT_CENTER);
m_rDataBox.left -= tm.tmAveCharW
pDC-&SetTextColor(GetSysColor(COLOR_3DHILIGHT));
pDC-&DrawText(sLogoString, sLogoString.GetLength(), &m_rDataBox, DT_VCENTER | DT_SINGLELINE | DT_CENTER);
m_rDataBox.left += 3*tm.tmAveCharWidth/5;
pDC-&SetTextColor(RGB(0,0,255));
pDC-&DrawText(sLogoString, sLogoString.GetLength(), &m_rDataBox, DT_VCENTER | DT_SINGLELINE | DT_CENTER);
//释放资源
pDC-&SelectObject(oldFont);
pDC-&SetTextColor(oldColor);
m_LogoFont.DeleteObject();
//////////////////////////////////////////////////////////////////
八、在属性页中动态加入其它控件下面演示如何在左下角加入一Edit控件:MyPropSheet.h中:
MyPropSheet.cpp中:
BOOL CMyPropSheet::OnInitDialog ()
  BOOL bResult = CPropertySheet::OnInitDialog ();
  int nHeight = 24;
  int nWidth = 120;
  int nOffset = 6;
  GetClientRect (&rect);
  // Find a bottom-left point for the edit control in the client area
  int nX = rect.left + nO
  int nY = rect.top + (rect.Height() - nHeight) - nO
  // finally create the edit control
  m_Edit.CreateEx (WS_EX_CLIENTEDGE, _T("EDIT"), NULL,
  WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
  nX, nY, nWidth, nHeight, m_hWnd, 0, 0 );
  return bR
http://blog.csdn.net/rackyye/article/details/2147172
// 深入浅出CPropertySheet
/index.php/wv/237.html&C/C++(35)
一般有很多配置项时,我们希望就象Windows的很多配置窗体一样,用Tab管理各个相关的属性配置项,但是如果自己用Tab控件实现的话,控制各个显示控件十分麻烦,这时我们就可以用到MFC提供的属性页Property Sheets来实现。
1. 在资源中为每个Property Page(到时对应各个tab项)生成对话框模板,注意要设置Caption,到时作为Tab头,Style设为Child,Titlebar要选中,不要选System menu2. 用类向导为这些对话框生成类,注意以CPropertyPage为父类3. 生成CPropertySheet实例,把那些Property Page加入,然后调用DoModal弹出属性页配置窗体,如下面的程序
&&& //生成实例&&& CPropertySheet dlgPropertySheet("你的属性页窗体的标题",this);//以准备弹出属性页的窗体做父亲,这样在DoModal之后用户只要不选确认或取消,就不能回到父窗体&&& &&& //定义各个子page,也就是属性页上面的各个tab项&&& CDlg1 page1;&&& CDlg2 page2;
&&& //把初始参数传给各个page&&& page1.m_nMember1 = m_nMember1; &&& page1.m_nMember2 = m_nMember2;
&&& page2.m_strMember3 = m_strMember3;&&& page2.m_strMember4 = m_strMember4;
&&& //为属性页窗体添加各个子page,注意最终属性页的大小以最大的子page为准&&& dlgPropertySheet.AddPage(&page1);&&& dlgPropertySheet.AddPage(&page2);
&&& //弹出显示属性页&&& switch(dlgPropertySheet.DoModal())&&& {&&& case IDOK:&&&&&&& {&&&&&&&&&&&& //用户点击确认,把数据交换出来&&&&&&&&&&&& m_nMember1 = pageFirst.m_nMember1;&&&&&&&&&&&& m_nMember2 = pageFirst.m_nMember2;&&&&&&&&&&&& m_strMember3 = pageSecond.m_strMember3;&&&&&&&&&&&& m_strMember4 = pageSecond.m_strMember4; &&&&&&& }&&&&&&&&&& case IDCANCEL:&&&&&&& {&&&&&&&&&&& // 用户取消,说明什么参数都不用改&&&&&&& }&&&&&&&&&& }
Outlook的配置属性页:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:520865次
积分:6616
积分:6616
排名:第2428名
原创:145篇
转载:10篇
评论:97条
(2)(1)(1)(3)(1)(1)(1)(1)(1)(3)(4)(1)(1)(1)(2)(3)(2)(1)(2)(4)(11)(4)(6)(2)(1)(2)(4)(2)(1)(4)(4)(5)(6)(2)(1)(5)(7)(6)(1)(2)(12)(32)君,已阅读到文档的结尾了呢~~
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
第6章 属性单(CPropertySheet) 和属性页(CPropertyPage)
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口关于PropertyPage和PropertySheet的问题?
[问题点数:50分,结帖人lz_0618]
关于PropertyPage和PropertySheet的问题?
[问题点数:50分,结帖人lz_0618]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
本帖子已过去太久远了,不再提供回复功能。1. sheet--属性表单,page---属性页,,,,,,,,,
属性页生长在属性表单上,而属性表单所依附的对话框 &是由系统生成的,,并默认有四个按钮,没有找到方法让属性表单依附的对话框 变成自己设计得对话框ID,而且这四个按钮对应的消息函数也不知在什么地方,,,取消这四个按钮方法--
//应用按钮隐藏
CWnd* pWnd=GetDlgItem(ID_APPLY_NOW);
pWnd-&ShowWindow(FALSE) ;
//确定按钮隐藏
pWnd=GetDlgItem(1);
pWnd-&ShowWindow(FALSE) ;
//取消按钮隐藏
pWnd=GetDlgItem(2);
pWnd-&ShowWindow(FALSE) ;
//帮助按钮隐藏
pWnd=GetDlgItem(9);
pWnd-&ShowWindow(FALSE) ;
2.TABLE CONTROL
在OnitDialog()中调用m_TableCtl.InsertItem(0,_T(&dfsdf&));
会出现运行错误:
File:f:\rtm\vctools\vc7libs\ship\atlmfc\include\afxcmn.inl Line :558 错误
解决方法:
把CDialog::OnInitDialog();调用放在m_TableCtl.InsertItem(0,_T(&dfsdf&));前面 即可 &解决!!!!
What amazinging day !!!!!
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:30521次
积分:1290
积分:1290
排名:千里之外
原创:68篇
转载:198篇
(10)(18)(10)(11)(2)(29)(16)(14)(14)(10)(36)(30)(11)(7)(1)(1)(9)(12)(17)(13)

我要回帖

更多关于 qt propertysheet 的文章

 

随机推荐