WEB开发网
开发学院软件开发VC 深入浅出 CPropertySheet 阅读

深入浅出 CPropertySheet

 2006-07-23 11:21:02 来源:WEB开发网   
核心提示: 代码如下:void CMyPropSheet::OnPaint (){///在TAB按钮旁边显示3D文字提示,jingzhou xuCstring m_LogoName = “属性页”;//if(m_LogoName == "")//return

代码如下:

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_hWnd, 0, 0 );
  return bResult;
}

上一页  1 2 3 4 

Tags:深入浅出 CPropertySheet

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接