使用CPropertySheet类

 
使用 CPropertySheet , 在无模式状态下会有三个按钮 ( 确认 / 取消 / 应用 )  
我想改变三个按钮的标题 , 另还想增加按钮 ,  
不知如何实现 ?  
谢谢  
---------------------------------------------------------------  
 
为了最大限度的发挥属性页的效用,首先让我们先从  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  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;  
}  
 
 
 
三、改变属性页上的标签文字  
首先修改 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);  
 
 
四、改变属性页标签文字的字体属性  
代码如下 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;  
       item.mask  =  TCIF_IMAGE;  
       for  (int  i  =  0;  i  <  NUMBER_OF_TABS;  i++)  
       {  
               item.iImage  =  i;  
               pTabCtrl->SetItem  (i,  &item  );  
       }  
 
       return  bResult;  
}  
 
 
 
六、在属性页左下角显示位图  
如下代码所示:  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  
}  
 
 
 
七、在属性页右下角显示 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();  
           /  
}  
 
 
八、在属性页中动态加入其它控件  
下面演示如何在左下角加入一 Edit 控件 :  
MyPropSheet.h
:public:  
       CEdit  m_edit;  
 
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_
 
MSDN say:
BOOL CMySheet::OnInitDialog()
{
     CPropertySheet::OnInitDialog();

     RECT rc;

     // resize the sheet
     GetWindowRect (&rc);
     ScreenToClient (&rc);
     rc.right += 50;
     rc.bottom += 50;
     MoveWindow (&rc);

     // resize the CTabCtrl
     CTabCtrl* pTab = GetTabControl ();
     ASSERT (pTab);
     pTab->GetWindowRect (&rc);
     ScreenToClient (&rc);
     rc.right += 50;
     rc.bottom += 50;
     pTab->MoveWindow (&rc);

     // resize the page
     CPropertyPage* pPage = GetActivePage ();
     ASSERT (pPage);
     // store page size in m_PageRect
     pPage->GetWindowRect (&m_PageRect);
     ScreenToClient (&m_PageRect);
     m_PageRect.right += 50;
     m_PageRect.bottom += 50;
     pPage->MoveWindow (&m_PageRect);

     // move the OK, Cancel, and Apply buttons
     CWnd* pWnd = GetDlgItem(IDOK);
     pWnd->GetWindowRect(&rc);
     rc.bottom += 50;
     rc.top += 50;
     ScreenToClient(&rc);
     pWnd->MoveWindow(&rc);

     pWnd = GetDlgItem(IDCANCEL);
     pWnd->GetWindowRect(&rc);
     rc.bottom += 50;
     rc.top += 50;
     ScreenToClient(&rc);
     pWnd->MoveWindow(&rc);

     pWnd = GetDlgItem(ID_APPLY_NOW);
     pWnd->GetWindowRect(&rc);
     rc.bottom += 50;
     rc.top += 50;
     ScreenToClient(&rc);
     pWnd->MoveWindow(&rc);

     CenterWindow();

     return TRUE;
}
 
 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测(Object Detection)是计算机视觉领域的一个核心问题,其主要任务是找出图像中所有感兴趣的目标(物体),并确定它们的别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问题,即定位出图像中目标的位置并识别出目标的别。由于各物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问题 目标检测涉及以下几个核心问题: 分问题:判断图像中的目标属于哪个别。 定位问题:确定目标在图像中的具体位置。 大小问题:目标可能具有不同的大小。 形状问题:目标可能具有不同的形状。 三、算法分 基于深度学习的目标检测算法主要分为两大: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选框(Region Proposal),再通过卷积神经网络进行样本分。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络中提取特征来预测物体分和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问题,将输入图像一次性划分为多个区域,直接在输出层预测边界框和别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值