CWnd *pWnd = GetDlgItem( IDCANCEL );<span style="font-family: Helvetica, Tahoma, Arial, sans-serif;">//隐藏掉Cancel取消按钮:</span> pWnd->ShowWindow( FALSE );
CWnd *pWnd = GetDlgItem (ID_APPLY_NOW);
if(pWnd && pWnd->GetSafeHwnd())
pWnd->ShowWindow (FALSE);
pWnd = GetDlgItem (IDHELP);
if(pWnd && pWnd->GetSafeHwnd())
pWnd->ShowWindow (FALSE);
pWnd = GetDlgItem (IDOK);
if(pWnd && pWnd->GetSafeHwnd())
pWnd->ShowWindow (FALSE);
pWnd = GetDlgItem (IDCANCEL);
if(pWnd && pWnd->GetSafeHwnd())
pWnd->ShowWindow (FALSE);
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;
}
<span style="white-space:pre"> </span>TC_ITEM item; <span style="white-space:pre"> </span>item.mask = TCIF_TEXT; <span style="white-space:pre"> </span>item.pszText = "New Label"; <span style="white-space:pre"> </span>//Change the label of the first tab (0 is the index of the first tab)... <span style="white-space:pre"> </span>GetTabControl ()->SetItem (0, &item);
<span style="white-space:pre"> </span>m_NewFont.CreateFont (14, 0, 0, 0, 800, TRUE, 0, 0, 1, 0, 0, 0, 0, _T("Arial") );
GetTabControl()->SetFont (&m_NewFont);
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
}
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();
/////////////////////////////////////////////////////////////////////////
}
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;
}
去掉四个按钮后消除界面下方的空白。
//添加在CPropertySheet类的OnInitDialog()函数中,可以消除隐藏按钮后留下的空白。
//去除空白 GetDlgItem(IDOK)->ShowWindow(SW_HIDE); GetDlgItem(IDHELP)->ShowWindow(SW_HIDE); GetDlgItem(IDCANCEL)->ShowWindow(SW_HIDE); GetDlgItem(ID_APPLY_NOW)->ShowWindow(SW_HIDE); //获取窗体尺寸 CRect btnRect; GetDlgItem(IDCANCEL)->GetWindowRect(&btnRect); CRect wdnRect; GetWindowRect(&wdnRect); //调整窗体大小 ::SetWindowPos(this->m_hWnd, HWND_TOP,0,0,0,0,SWP_SHOWWINDOW|SWP_NOSIZE);
原文地址:http://blog.csdn.net/u013147600/article/details/42777729