cpropertysheet:使用CPropertySheet类的方法来源: 发布时间:星期四, 2009年2月12日 浏览:160次 评论:0
为了最大限度 ![]() ![]() ![]() ![]() ![]() 接着便可以进行下面 ![]() ![]() 隐藏掉Apply应用按钮: propsheet.m_psh.dwFlags ¦= PSH_NOAPPLYNOW; 或隐藏掉Cancel取消按钮:CWnd *pWnd = GetDlgItem( IDCANCEL ); pWnd->ShowWindow( FALSE ); 2、移动属性页按钮 首先 ![]() ![]() ![]() ![]() ![]() ![]() ![]() { BOOL bResult = CPropertySheet::OnInitDialog ![]() ![]() ![]() // Hide Apply and Help buttons CWnd *pWnd = GetDlgItem (ID_APPLY_NOW); pWnd->ShowWindow (FALSE); pWnd = GetDlgItem (IDHELP); pWnd->ShowWindow (FALSE); CRect rectBtn; ![]() for( ![]() ![]() ![]() ![]() ![]() { GetDlgItem (ids [i])->GetWindowRect (rectBtn); ScreenToClient (&rectBtn); ![]() ![]() rectBtn.left = rectBtn.left + (btnWidth + nSpacing)* 2; rectBtn.right = rectBtn.right + (btnWidth + nSpacing)* 2; [Page] GetDlgItem (ids [i])->MoveWindow(rectBtn); } ![]() } 下面代码移动所有按钮到右侧 ![]() ![]() ![]() { BOOL bResult = CPropertySheet::OnInitDialog ![]() ![]() ![]() CRect rectWnd; CRect rectBtn; GetWindowRect (rectWnd); GetDlgItem (IDOK)->GetWindowRect (rectBtn); ![]() ![]() ![]() ![]() ![]() ![]() ![]() rectWnd.bottom = rectBtn.top; rectWnd.right = rectWnd.right + btnWidth + btnOff ![]() MoveWindow(rectWnd); rectBtn.left = btnLeft; rectBtn.right = btnLeft + btnWidth; for ( ![]() ![]() ![]() ![]() ![]() { rectBtn.top = (i + 1) * btnOff ![]() rectBtn.bottom = rectBtn.top + btnHeight; GetDlgItem (ids [i])->MoveWindow (rectBtn); } [Page] ![]() } 3、改变属性页上 ![]() 首先修改TC_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 ![]() 4、改变属性页标签文字 ![]() 代码如下m_NewFont.CreateFont (14, 0, 0, 0, 800, TRUE, 0, 0, 1, 0, 0, 0, 0, _T(\"Arial\") ); GetTabControl ![]() 5、在属性页标签上显示位图 可以用 CImageList 建立图像. 用 SetItem 来设置 ![]() ![]() { 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 ( ![]() ![]() { item.iImage = i; pTabCtrl->SetItem (i, &item ); } ![]() } 6、在属性页左下角显示位图 如下代码所示: void CMyPropSheet::OnPa ![]() ![]() { CPa ![]() ![]() ![]() ![]() // load IDB_BITMAP1 from our resources [Page] CBitmap bmp; ![]() { // 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 pa ![]() CDC dcMemory; dcMemory.CreateCompatibleDC (&dc); // Select the bitmap ![]() CBitmap* pOldBitmap = dcMemory.SelectObject (&bmp); // Find a bottom-left po ![]() CRect rect; GetClientRect (&rect); ![]() ![]() ![]() ![]() ![]() // Copy the bits from the in-memory DC ![]() 代码如下:void CMyPropSheet::OnPa ![]() ![]() { ///////////////////////////////////////////////////////////////////////// //在TAB按钮旁边显示 3D文字提示,jingzhou xu C ![]() // ![]() ![]() // ![]() GetWindowRect(rect); ScreenToClient(rect); LOGFONT logFont; ZeroMemory((void*)&logFont, ![]() strcpy(logFont.lfFaceName,\"宋体\"); logFont.lfHeight = -12; logFont.lfWeight = 400; logFont.lfCharSet = GB2312_CHARSET; logFont.lfOutPrecision = 3; logFont.lfClipPrecision = 2; logFont.lfQuality = 1; [Page] logFont.lfPitchAndFamily = 2; m_font.CreateFontIndirect(&logFont); SetFont(&m_font); CFont *pOldFont = pDC->SelectObject(&m_font); rect.left ![]() rect.right -= 6; rect.bottom -= 1; rect.top = rect.bottom - ITEMBUTTON_HEIGHT + 1; CFont m_LogoFont; CString sLogoString; m_LogoFont.CreateFont(rect.Height ![]() 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); [Page] TEXTMETRIC tm; pDC->GetTextMetrics(&tm); CFont* oldFont = pDC->SelectObject(&m_LogoFont); CSize sz = pDC->GetTextExtent(sLogoString, sLogoString.GetLength ![]() //用GetTextExtent来计算字体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.left -= tm.tmAveCharWidth; pDC->SetTextColor(GetSysColor(COLOR_3DHILIGHT)); pDC->DrawText(sLogoString, sLogoString.GetLength ![]() m_rDataBox.left ![]() pDC->SetTextColor(RGB(0,0,255)); pDC->DrawText(sLogoString, sLogoString.GetLength ![]() [Page] //释放资源 pDC->SelectObject(oldFont); pDC->SetTextColor(oldColor); m_LogoFont.DeleteObject ![]() ///////////////////////////////////////////////////////////////////////// } 8、在属性页中动态加入其它Control控件 下面演示如何在左下角加入 ![]() MyPropSheet.h中:public: CEdit m_edit; MyPropSheet.cpp中:BOOL CMyPropSheet::OnInitDialog ![]() { BOOL bResult = CPropertySheet::OnInitDialog ![]() CRect rect; ![]() ![]() ![]() ![]() GetClientRect (&rect); // Find a bottom-left po ![]() ![]() ![]() ![]() ![]() ![]() // 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 ![]() rc.bottom ![]() MoveWindow (&rc); // resize the CTabCtrl CTabCtrl* pTab = GetTabControl ![]() ASSERT (pTab); pTab->GetWindowRect (&rc); ScreenToClient (&rc); rc.right ![]() rc.bottom ![]() 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 ![]() m_PageRect.bottom ![]() pPage->MoveWindow (&m_PageRect); // move the OK, Cancel, and Apply buttons CWnd* pWnd = GetDlgItem(IDOK); pWnd->GetWindowRect(&rc); rc.bottom ![]() rc.top ![]() ScreenToClient(&rc); pWnd->MoveWindow(&rc); pWnd = GetDlgItem(IDCANCEL); pWnd->GetWindowRect(&rc); rc.bottom ![]() rc.top ![]() ScreenToClient(&rc); pWnd->MoveWindow(&rc); pWnd = GetDlgItem(ID_APPLY_NOW); pWnd->GetWindowRect(&rc); rc.bottom ![]() rc.top ![]() ScreenToClient(&rc); pWnd->MoveWindow(&rc); CenterWindow ![]() ![]() } [Page] 0
相关文章读者评论发表评论 |