为了最大限度的发挥属性页的效用,首先让我们先从 CPropertySheet 继承一个新类,取名为 CMyPropSheet.
接着便可以进行下面的各种操作:
l       隐藏属性页默认按钮
隐藏掉Apply应用按钮:
propsheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
或隐藏掉Cancel取消按钮:
CWnd *pWnd = GetDlgItem( IDCANCEL );
pWnd->ShowWindow( FALSE );
 
l       移动属性页按钮
首先,要获取按钮的句柄,然后就可以象对待窗体一样处理它们了.下面代码先隐藏掉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 rectBtn;
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);
}
return bResult;
}
下面代码移动所有按钮到右侧,并且重新置属性页为合适的大小.
BOOL CMyPropSheet::OnInitDialog ()
{
BOOL bResult = CPropertySheet::OnInitDialog();
int ids[] = { IDOK, IDCANCEL, ID_APPLY_NOW };
CRect rectWnd;
CRect rectBtn;
GetWindowRect (rectWnd);
GetDlgItem (IDOK)->GetWindowRect (rectBtn);
int btnWidth = rectBtn.Width();
int btnHeight = rectBtn.Height();
int btnOffset = rectWnd.bottom - rectBtn.bottom;
int btnLeft = rectWnd.right - rectWnd.left;
rectWnd.bottom = rectBtn.top;
rectWnd.right = rectWnd.right + btnWidth + btnOffset;
MoveWindow(rectWnd);
rectBtn.left = btnLeft;
rectBtn.right = btnLeft + btnWidth;
for (int i = 0; i < sizeof (ids) / sizeof (int); i++)
{
rectBtn.top = (i +1) * btnOffset + btnHeight * i;
rectBtn.bottom = rectBtn.top + btnHeight;
GetDlgItem (ids [i])->MoveWindow (rectBtn);
}
return bResult;
}
l       改变属性页上的标签文字
首先修改TC_ITEM结构,然后用 SetItem 来修改标签文字,如下代码:
TC_ITEM item;
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);
l       改变属性页标签文字的字体属性
如下代码:
m_NewFont.CreateFont (14, 0, 0, 0, 800, TRUE, 0, 0,1, 0, 0, 0, 0, _T("Arial") );
GetTabControl()->SetFont (&m_NewFont);
l       在属性页标签上显示位图
可以用 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;
item.mask = TCIF_IMAGE;
for (int i = 0; i < NUMBER_OF_TABS; i++)
{
item.iImage = i;
pTabCtrl->SetItem (i, &item );
}
return bResult;
}
l       在属性页左下角显示位图
如下代码所示:
void CMyPropSheet::OnPaint ()
{
CPaintDC dc(this); // device context for painting
int nOffset = 6;
// load IDB_BITMAP1 from our resources
CBitmap bmp;
if (bmp.LoadBitmap (IDB_BITMAP1))
{
// Get the size of the bitmap
BITMAP bmpInfo;
bmp.GetBitmap (&bmpInfo);
// Create an in-memory DC compatible with the
// display DC we're using to paint
CDC dcMemory;
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
CRect rect;
GetClientRect (&rect);
int nX = rect.left + nOffset;
int nY = rect.top + (rect.Height () - bmpInfo.bmHeight) - nOffset;
// 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
}
l       在属性页右下角显示3D文字Logo
如下代码:
void CMyPropSheet::OnPaint ()
{
/
//在TAB按钮旁边显示3D文字提示,jingzhou xu
Cstring m_LogoName = “属性页”;
//if(m_LogoName == "")
//return;
GetWindowRect(rect);
ScreenToClient(rect);
LOGFONT logFont;
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);
CFont         *pOldFont = pDC->SelectObject(&m_font);
rect.left += 6;
rect.right -= 6;
rect.bottom -= 1;
rect.top = rect.bottom - ITEMBUTTON_HEIGHT + 1;
CFont m_LogoFont;
CString sLogoString;
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_LogoName;
RECT m_rDataBox;
CopyRect(&m_rDataBox,&rect);
TEXTMETRIC tm;
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.tmAveCharWidth;
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();
/
}
l       在属性页中动态加入其它控件
下面演示如何在左下角加入一Edit控件:
In MyPropSheet.h:
public:
CEdit m_edit;
In MyPropSheet.cpp:
BOOL CMyPropSheet::OnInitDialog ()
{
BOOL bResult = CPropertySheet::OnInitDialog ();
CRect rect;
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 + nOffset;
int nY = rect.top + (rect.Height() - nHeight) - nOffset;
// 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 bResult;
}

转载于:https://blog.51cto.com/whatday/1382641

深入浅出 CPropertySheet相关推荐

  1. Python --深入浅出Apriori关联分析算法(二) Apriori关联规则实战

    上一篇我们讲了关联分析的几个概念,支持度,置信度,提升度.以及如何利用Apriori算法高效地根据物品的支持度找出所有物品的频繁项集. Python --深入浅出Apriori关联分析算法(一) 这次 ...

  2. MSDN Webcast“深入浅出ASP.NET AJAX系列”

    课程: ASP.NET AJAX深入浅出系列课程(1):ASP.NET AJAX 概述(3月13日):对于ASP.NET AJAX的大致功能进行概述和演示,通过简单的演示让听众了解到ASP.NET A ...

  3. 5.3Role和Claims授权「深入浅出ASP.NET Core系列」

    5.3Role和Claims授权「深入浅出ASP.NET Core系列」 原文:5.3Role和Claims授权「深入浅出ASP.NET Core系列」 希望给你3-5分钟的碎片化学习,可能是坐地铁. ...

  4. 深入浅出开源性能测试工具 Locust (使用篇 1)

    在<[LocustPlus序]漫谈服务端性能测试>中,我对服务端性能测试的基础概念和性能测试工具的基本原理进行了介绍,并且重点推荐了Locust这一款开源性能测试工具.然而,当前在网络上针 ...

  5. 《深入浅出iPhone/iPad开发(第2版)》——在Xcode中建立你的界面

    本节书摘来自异步社区<深入浅出iPhone/iPad开发(第2版)>一书中的在Xcode中建立你的界面,作者 [美]Dan Pilone , Tracey Pilone,更多章节内容可以访 ...

  6. 【组队学习】【35期】深入浅出Pytorch

    深入浅出Pytorch 航路开辟者:李嘉骐.牛志康.刘洋.陈安东 领航员:朱松青 航海士:管柯琴.宋泽山.林旭升 基本信息 开源内容:https://github.com/datawhalechina ...

  7. 深入浅出Pytorch:02 PyTorch基础知识

    深入浅出Pytorch 02 PyTorch基础知识 内容属性:深度学习(实践)专题 航路开辟者:李嘉骐.牛志康.刘洋.陈安东 领航员:叶志雄 航海士:李嘉骐.牛志康.刘洋.陈安东 开源内容:http ...

  8. 深入浅出Pytorch:01 课程大纲与PyTorch简介

    深入浅出Pytorch 01 课程大纲与PyTorch简介 内容属性:深度学习(实践)专题 航路开辟者:李嘉骐.牛志康.刘洋.陈安东 领航员:叶志雄 航海士:李嘉骐.牛志康.刘洋.陈安东 开源内容:h ...

  9. 今晚8点直播 | 深入浅出理解A3C强化学习

    强化学习是一种比较传统的人工智能手段,在近年来随着深度学习的发展,强化学习和深度学习逐渐结合在了一起.这种结合使得很多原来无法想象的工作有了可能,最令我们瞩目的莫过于AlphaGo战胜李世石,以及Op ...

最新文章

  1. python运行软件-Python中四种运行其他程序的方式
  2. python安装第三方库-python第三方库的四种安装方法
  3. PIC单片机入门_框架与存储器
  4. Qt for Android调用android原生控件安装apk
  5. ERDAS软件应用(三)遥感图像的拼接
  6. ubuntu20.04中安装划词翻译_教你轻松玩转免安装的网页翻译插件“有道网页翻译2.0”...
  7. 使用ANTLR4,用于代码镜像和基于Web的DSL的Primefaces扩展
  8. 【报告分享】2022十大科技趋势-达摩院.pdf(附下载链接)
  9. 7z命令行参数详解--python暴破压缩文件命令必备
  10. ansible不配置ssh免密钥,使用密码登录
  11. python零基础能学吗-终于知道深圳Python零基础能学吗
  12. xshell登陆腾讯云服务器
  13. C++ 标准模板库STL
  14. android的自定义字体,Android中使用自定义字体的方法
  15. python网络爬虫实战解析
  16. MAC 青花瓷(Charles)爪机HTTPS 抓包
  17. 质因数分解-P1069 [NOIP2009 普及组] 细胞分裂
  18. 【数据科学】迄今最全面的数据科学应用总结:16个分析学科及落地应用
  19. linux 文件夹复权,大趋势6x无盘系统安装配置说明.doc
  20. 八月未央,梦落泸沽。

热门文章

  1. 代码体积减少80%!Taro H5转换与优化升级
  2. 做App还是微信公众号,你该如何抉择?
  3. js中各种跨域问题实战小结
  4. mysql备份恢复实验
  5. VB 输入超出文件尾(错误62)(转)
  6. 英特尔将进行重大业务重组
  7. SSL方式获取邮箱收件箱
  8. 祭旗篇---关于提高技术团队技术氛围的一些尝试
  9. iOS ASIHTTPRequest用https协议加密请求
  10. PAT, PMT in MPEG2 Stream :筆記