void CaImMenu::MeasureItem (LPMEASUREITEMSTRUCT lpMeasureItemStruct) { MENUITEMINFO iInfo; GetMenuItemInfo (lpMeasureItemStruct->CtlID, &iInfo); CaImMenuItem* pItem = (CaImMenuItem*)lpMeasureItemStruct->itemData; CFont fntDef; LOGFONT lfDef; CClientDC dc (0); CFont* pFont = (CFont *)dc.SelectStockObject (ANSI_VAR_FONT); if (pItem->CheckStyle (AMIS_DEFAULT)) { CFont* pFnt = dc.GetCurrentFont (); pFnt->GetLogFont (&lfDef); lfDef.lfWeight = FW_BOLD; fntDef.CreateFontIndirect (&lfDef); dc.SelectObject (&fntDef); } if (pItem->CheckStyle (AMIS_BAR)) lpMeasureItemStruct->itemHeight = 4; else lpMeasureItemStruct->itemHeight = m_dwHeight; lpMeasureItemStruct->itemWidth = 25 + 8 + 8 + 2 + dc.GetTextExtent (pItem->GetText ()).cx; dc.SelectObject (pFont); if (pItem->CheckStyle (AMIS_DEFAULT)) fntDef.DeleteObject (); }
void CComputer::eraseDataText(CClientDC &dc) { dc.SetTextColor(white); originalFont = dc.SelectObject(&dataFont); drawDataText(dc); dc.SelectObject(&originalFont); }
void CMainFrame::DrawCell (UINT col,UINT row,BOOL alive) { CBrush* pBrush; CClientDC clientDC (this); CDC memDC; memDC.CreateCompatibleDC (&clientDC); memDC.SelectObject (m_pBitmap); if(alive) pBrush=new CBrush(RGB(255, 0, 0)); else { if (m_showdead) pBrush=new CBrush(RGB(200, 200, 200)); else pBrush=new CBrush(RGB(255, 255, 255)); } CBrush* pOldBrush1=memDC.SelectObject (pBrush); CBrush* pOldBrush2=clientDC.SelectObject (pBrush); UINT drawCol= col * SQUARESIZE + HOROFFSET; UINT drawRow= row * SQUARESIZE + VEROFFSET; memDC.Rectangle (drawCol,drawRow,drawCol+SQUARESIZE+1, drawRow+SQUARESIZE+1); clientDC.Rectangle (drawCol,drawRow,drawCol+SQUARESIZE+1, drawRow+SQUARESIZE+1); memDC.SelectObject (pOldBrush1); clientDC.SelectObject (pOldBrush2); delete pBrush; }
//***************************************************************************************** void CIconCombo::OnMeasureItem(int /*nIDCtl*/, LPMEASUREITEMSTRUCT lpMeasureItemStruct) { int nTextWidth = 0; int nTextHeight = 0; if (!m_lstIconNames.IsEmpty ()) { nTextHeight = globalData.GetTextHeight (); CClientDC dc (this); CFont* pOldFont = dc.SelectObject (&globalData.fontRegular); for (POSITION pos = m_lstIconNames.GetHeadPosition (); pos != NULL;) { CString str = m_lstIconNames.GetNext (pos); nTextWidth = max (nTextWidth, dc.GetTextExtent (str).cx + nIconMargin); } dc.SelectObject (pOldFont); } lpMeasureItemStruct->itemWidth = m_imageListIcons.GetImageSize ().cx + nTextWidth + 3 * nIconMargin; lpMeasureItemStruct->itemHeight = max (nTextHeight, m_imageListIcons.GetImageSize ().cy + 2 * nIconMargin); }
CSize CBCGPPopupDlg::GetOptimalTextSize (CString str) { if (str.IsEmpty ()) { return CSize (0, 0); } CRect rectScreen; CRect rectDlg; GetWindowRect (rectDlg); MONITORINFO mi; mi.cbSize = sizeof (MONITORINFO); if (GetMonitorInfo (MonitorFromPoint (rectDlg.TopLeft (), MONITOR_DEFAULTTONEAREST), &mi)) { rectScreen = mi.rcWork; } else { ::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0); } CClientDC dc (this); CFont* pOldFont = dc.SelectObject (&globalData.fontRegular); ASSERT_VALID (pOldFont); int nStepY = globalData.GetTextHeight (); int nStepX = nStepY * 3; CRect rectText (0, 0, nStepX, nStepY); for (;;) { CRect rectTextSaved = rectText; int nHeight = dc.DrawText (str, rectText, DT_CALCRECT | DT_WORDBREAK | DT_NOPREFIX); int nWidth = rectText.Width (); rectText = rectTextSaved; if (nHeight <= rectText.Height () || rectText.Width () > rectScreen.Width () || rectText.Height () > rectScreen.Height ()) { rectText.bottom = rectText.top + nHeight + 5; rectText.right = rectText.left + nWidth + 5; break; } rectText.right += nStepX; rectText.bottom += nStepY; } dc.SelectObject (pOldFont); return rectText.Size (); }
void CPacket::erase(CClientDC &dc) { originalPen = dc.SelectObject(&whitePen); dc.Rectangle(x1,y1,x2,y2); dc.MoveTo(x1,y1); dc.LineTo(x2,y2); dc.MoveTo(x1,y2); dc.LineTo(x2,y1); dc.SelectObject(&originalPen); }
void CDlgCalcDlg::UpdateDisplay(LPCTSTR pszDisplay) { CClientDC dc (this); CFont* pOldFont = dc.SelectObject (GetFont ()); CSize size = dc.GetTextExtent (pszDisplay); CRect rect = m_rect; rect.InflateRect (-2, -2); int x = rect.right - size.cx - m_cxChar; int y = rect.top + ((rect.Height () - m_cyChar) / 2); dc.ExtTextOut (x, y, ETO_OPAQUE, rect, pszDisplay, NULL); dc.SelectObject (pOldFont); }
void CPacket::draw(CClientDC &dc) { if (visible||active){ originalPen = dc.SelectObject(&blackPen); }else{ originalPen = dc.SelectObject(&whitePen); } dc.Rectangle(x1,y1,x2,y2); dc.MoveTo(x1+1,y1+1); dc.LineTo(x2-1,y2-1); dc.MoveTo(x1+1,y2-1); dc.LineTo(x2-1,y1+1); dc.SelectObject(&originalPen); }
void CRibbonListButton::OnShowPopupMenu () { ASSERT_VALID (this); CBCGPBaseRibbonElement::OnShowPopupMenu (); if (m_sizeMaxText == CSize (0, 0)) { CBCGPRibbonBar* pRibbonBar = GetTopLevelRibbonBar (); ASSERT_VALID (pRibbonBar); CClientDC dc (pRibbonBar); CFont* pOldFont = dc.SelectObject (pRibbonBar->GetFont ()); ASSERT (pOldFont != NULL); int i = 0; for (i = 0; i < m_arLabels.GetSize (); i++) { CSize szText = dc.GetTextExtent (m_arLabels [i]); m_sizeMaxText.cx = max (m_sizeMaxText.cx, szText.cx); m_sizeMaxText.cy = max (m_sizeMaxText.cy, szText.cy); } const int cxImage = m_listImages.GetImageSize ().cx; for (i = 0; i < m_arSubItems.GetSize (); i++) { CBCGPBaseRibbonElement* pButton = m_arSubItems [i]; ASSERT_VALID (pButton); CString strText = pButton->GetText (); CSize szText = dc.GetTextExtent (strText); m_sizeMaxText.cx = max (m_sizeMaxText.cx, szText.cx - cxImage); } dc.SelectObject (pOldFont); } CBCGPRibbonPaletteButton::OnShowPopupMenu (); }
void CRibbonListFontButton::OnShowPopupMenu () { ASSERT_VALID (this); CBCGPBaseRibbonElement::OnShowPopupMenu (); if (m_sizeMaxText == CSize (0, 0)) { CBCGPRibbonBar* pRibbonBar = GetTopLevelRibbonBar (); ASSERT_VALID (pRibbonBar); CClientDC dc (pRibbonBar); CFont* pOldFont = dc.SelectObject (&globalData.fontBold); for (int i = 0; i < m_arItems.GetSize (); i++) { CSize szText = dc.GetTextExtent (m_arItems [i].m_Caption); for (int j = 0; j < 2; j++) { LOGFONT& lf = m_arItems [i].m_Font[j]; CFont font; font.CreateFontIndirect (&lf); dc.SelectObject (&font); CSize szText2 = dc.GetTextExtent (lf.lfFaceName); szText.cx = max (szText.cx, szText2.cx); szText.cy += szText2.cy; } m_arItems [i].m_Height = szText.cy; m_sizeMaxText.cx = max (m_sizeMaxText.cx, szText.cx); m_sizeMaxText.cy = max (m_sizeMaxText.cy, szText.cy); } dc.SelectObject (pOldFont); } CBCGPRibbonPaletteButton::OnShowPopupMenu (); }
void CMyStatusBar::OnPaint() { Default(); CClientDC cDC (this); CPen pen(PS_SOLID, 1, ::GetSysColor (COLOR_3DSHADOW)); HPEN oldPen = (HPEN)cDC.SelectObject(pen); CRect rcItem; cDC.SelectObject (::GetStockObject (NULL_BRUSH)); for ( int i = 0; i < m_nCount; i++ ) { GetItemRect (i, rcItem); cDC.Rectangle (rcItem); } cDC.SelectObject (oldPen); }
////////////////// // text changed: resize window to fit // LRESULT CPopupText::OnSetText(WPARAM wp, LPARAM lp) { UNREFERENCED_PARAMETER (wp); CClientDC dc = this; CFont* pOldFont = dc.SelectObject(&m_font); CRect rc; GetWindowRect(&rc); int x = (m_nStyle & JUSTIFYRIGHT) ? rc.right : rc.left; int y = rc.top; dc.DrawText(CString((LPCTSTR)lp), &rc, DT_CALCRECT); rc.InflateRect(m_szMargins); if (m_nStyle & JUSTIFYRIGHT) x -= rc.Width(); SetWindowPos(NULL,x,y,rc.Width(),rc.Height(), SWP_NOZORDER|SWP_NOACTIVATE); dc.SelectObject (pOldFont); return Default(); }
//************************************************************************************* void CBCGPKeyMapDlg::SetColumnsWidth () { CRect rectList; m_KeymapList.GetClientRect (rectList); CClientDC dc (this); CFont* pOldFont = dc.SelectObject (m_KeymapList.GetFont ()); ASSERT_VALID (pOldFont); int nKeyColumWidth = dc.GetTextExtent (CString (_T("Ctrl+Shift+W"))).cx + 10; dc.SelectObject (pOldFont); int nRestOfWidth = rectList.Width () - nKeyColumWidth - ::GetSystemMetrics (SM_CXHSCROLL); m_KeymapList.SetColumnWidth (iColumnCommand, nRestOfWidth / 3); m_KeymapList.SetColumnWidth (iColumnKeys, nKeyColumWidth); m_KeymapList.SetColumnWidth (iColumnDescr, nRestOfWidth * 2 / 3); }
void CComputer::draw(CClientDC &dc) { if (visible){ if ((isAttacker)||(underAttack)){ originalPen = dc.SelectObject(&redPen); dc.SetTextColor(red); }else{ originalPen = dc.SelectObject(&bluePen); dc.SetTextColor(black); } }else{ originalPen = dc.SelectObject(&whitePen); dc.SetTextColor(white); } originalFont = dc.SelectObject(&captionFont); dc.SetBkMode(TRANSPARENT); dc.Rectangle(x1,y1,x2,y2); if (textPosition == 0){//oben dc.TextOut(x1-4*borderWidth,y1-(borderWidth+captionTextSize),name); }else{//rechts unten dc.TextOut(x2+3*borderWidth,y2+borderWidth-captionTextSize,name); } drawDataText(dc); dc.SelectObject(&originalFont); dc.SelectObject(&originalPen); }
int CUndoBar::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CBCGPPopupMenuBar::OnCreate(lpCreateStruct) == -1) return -1; CFont* pMenuFont = (CFont*) &CBCGPMenuBar::GetMenuFont (); //------------------ // Set label height: //------------------ CClientDC dc (this); CFont* pOldFont = dc.SelectObject (pMenuFont); TEXTMETRIC tm; dc.GetTextMetrics (&tm); m_nLabelHeight = tm.tmHeight + 2; dc.SelectObject (pOldFont); CRect rectDummy (0, 0, 0, 0); m_wndList.Create (WS_VISIBLE | WS_CHILD | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY | WS_VSCROLL | LBS_MULTIPLESEL, rectDummy, this, ID_LIST); m_wndList.ModifyStyleEx (0, WS_EX_CLIENTEDGE); m_wndList.SetFont (pMenuFont); CUndoButton* pUndoButton = GetParentButton (); ASSERT_VALID (pUndoButton); for (POSITION pos = pUndoButton->m_lstActions.GetHeadPosition (); pos != NULL;) { m_wndList.AddString (pUndoButton->m_lstActions.GetNext (pos)); } return 0; }
//****************************************************************************** void CBCGPRibbonCommandsListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMIS) { ASSERT (lpMIS != NULL); CClientDC dc (this); CFont* pOldFont = (CFont*) dc.SelectStockObject (DEFAULT_GUI_FONT); ASSERT_VALID (pOldFont); TEXTMETRIC tm; dc.GetTextMetrics (&tm); lpMIS->itemHeight = tm.tmHeight + 6; dc.SelectObject (pOldFont); }
void CStatusBarXP::OnPaint () { Default(); CClientDC cDC (this); CPenDC pen (cDC, ::GetSysColor (COLOR_3DSHADOW)); CRect rcItem; cDC.SelectObject (::GetStockObject (NULL_BRUSH)); for ( int i = 0; i < m_nCount; i++ ) { GetItemRect (i, rcItem); cDC.Rectangle (rcItem); } }
void CComputer::drawDataText(CClientDC &dc) { dc.SelectObject(&dataFont); int x,y; x=1;//nicht auf 0 setzen, sonst Crash y=1;//nicht auf 0 setzen, sonst Crash for(int i=0; i<data.getNumberOfLines(); i++){ if (dataPosition == 1){ //rechts x=x2+2*borderWidth; y=y1+i*dataTextSize; }else if (dataPosition == 2){ //unten x=x1-borderWidth; y=y2+2*borderWidth+i*dataTextSize; } dc.TextOut(x,y,data.getLine(i,isAttacker)); } }
//****************************************************************** void CBCGPKeyboardPage::OnSelchangeCategory() { UpdateData (); int iIndex = m_wndCategoryList.GetCurSel (); if (iIndex == LB_ERR) { ASSERT (FALSE); return; } m_wndCommandsList.ResetContent (); m_wndCurrentKeysList.ResetContent (); CObList* pCategoryButtonsList = (CObList*) m_wndCategoryList.GetItemData (iIndex); ASSERT_VALID (pCategoryButtonsList); CString strCategory; m_wndCategoryList.GetLBText (iIndex, strCategory); BOOL bAllCommands = (strCategory == m_strAllCategory); CClientDC dcCommands (&m_wndCommandsList); CFont* pOldFont = dcCommands.SelectObject (m_wndCommandsList.GetFont ()); ASSERT (pOldFont != NULL); CBCGPToolbarCustomize* pWndParent = DYNAMIC_DOWNCAST (CBCGPToolbarCustomize, GetParent ()); ASSERT (pWndParent != NULL); int cxCommandsExtentMax = 0; for (POSITION pos = pCategoryButtonsList->GetHeadPosition (); pos != NULL;) { CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) pCategoryButtonsList->GetNext (pos); ASSERT (pButton != NULL); if (pButton->m_nID > 0 && pButton->m_nID != (UINT) -1) { CString strText = pButton->m_strText; if (!pButton->m_strTextCustom.IsEmpty () && (bAllCommands || pWndParent->GetCountInCategory (strText, *pCategoryButtonsList) > 1)) { strText = pButton->m_strTextCustom; } int iIndex = m_wndCommandsList.AddString (strText); m_wndCommandsList.SetItemData (iIndex, (DWORD_PTR) pButton); cxCommandsExtentMax = max (cxCommandsExtentMax, dcCommands.GetTextExtent (strText).cx); } } m_wndCommandsList.SetHorizontalExtent (cxCommandsExtentMax + ::GetSystemMetrics (SM_CXHSCROLL)); dcCommands.SelectObject (pOldFont); m_wndNewKey.EnableWindow (FALSE); m_wndCommandsList.SetCurSel (0); OnSelchangeCommandsList (); }
//************************************************************************************************ void CBCGPDateTimeCtrl::AdjustControl (CRect rectClient) { if (GetSafeHwnd () == NULL) { return; } CClientDC dc (this); CFont* pPrevFont = m_hFont == NULL ? (CFont*) dc.SelectStockObject (DEFAULT_GUI_FONT) : dc.SelectObject (CFont::FromHandle (m_hFont)); if (m_WidestDate == COleDateTime ()) { BuidWidestDate (&dc); } SetPartsOrder (); m_iPartNum = m_bCheckBoxIsAvailable ? 1 : 0; m_CurrPartType = m_arPartsOrder [m_iPartNum]; m_rectText = rectClient; m_rectText.InflateRect (0, -2); if (m_bAutoResize) { // Calculate text size: TEXTMETRIC tm; dc.GetTextMetrics (&tm); m_iControlHeight = tm.tmHeight + 6; } else { m_iControlHeight = rectClient.Height (); } if (m_bCheckBoxIsAvailable) { m_rectCheck = CRect (rectClient.left + 1, rectClient.top + 1, rectClient.left + m_iControlHeight - 1, rectClient.bottom - 1); m_rectText.left = m_rectCheck.right + 2; } m_rectText.top = rectClient.top; m_rectText.bottom = rectClient.top + m_iControlHeight; // Calculate parts: CalcPartRects (&dc); // Adjust control size: m_rectText.right = m_arPartRects [m_iPartsNumber - 1].right + 2; m_iControlWidth = m_rectText.right; if (m_spinButton) { m_iControlWidth += iSpinWidth; } if (!m_bAutoResize) { m_iControlWidth = rectClient.Width (); m_iControlHeight = rectClient.Height (); } if (m_dropCalendar && m_showDate) { if (m_bAutoResize) { m_iControlWidth += iDropButtonWidth; } int iDropStart = rectClient.left + m_iControlWidth - iDropButtonWidth - 1; if (m_spinButton) { iDropStart -= iSpinWidth + 1; } m_rectDropButton = CRect ( iDropStart, rectClient.top, iDropStart + iDropButtonWidth, rectClient.top + m_iControlHeight - 2); } if (m_bAutoResize) { SetWindowPos (NULL, -1, -1, m_iControlWidth + 2, m_iControlHeight + 2, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE); } // Adjust spin button: if (m_spinButton) { if (m_wndSpin.GetSafeHwnd () == NULL) { m_wndSpin.Create (WS_CHILD | WS_VISIBLE | UDS_ALIGNRIGHT | UDS_AUTOBUDDY, CRect (0, 0, 0, 0), this, iSpinID); } m_wndSpin.SetWindowPos (NULL, rectClient.left + m_iControlWidth - iSpinWidth - 2, rectClient.top, iSpinWidth, m_iControlHeight - 2, SWP_NOZORDER); m_wndSpin.ShowWindow (SW_SHOW); m_wndSpin.EnableWindow (IsWindowEnabled () && m_bIsChecked); } else if (m_wndSpin.GetSafeHwnd () != NULL) { m_wndSpin.SetWindowPos (NULL, 0, 0, 0, 0, SWP_NOZORDER); m_wndSpin.ShowWindow (SW_HIDE); } if (pPrevFont != NULL) { dc.SelectObject (pPrevFont); } //----------------------------- // Adjust min./max date values: //----------------------------- COleDateTime minAllowedDate (iFirstAllowedYear, 1, 1, 0, 0, 0); COleDateTime maxAllowedDate (iLastAllowedYear, 12, 31, 23, 59, 59); COleDateTime emptyDate; m_MinDate = max (m_MinDate, minAllowedDate); if (m_MaxDate != emptyDate) { m_MaxDate = min (m_MaxDate, maxAllowedDate); } else { m_MaxDate = maxAllowedDate; } }
// Refresh windows list void CBCGPWindowsManagerDlg::FillWindowList(void) { m_wndList.SetRedraw(FALSE); m_wndList.ResetContent(); int cxExtent = 0; CClientDC dcList (&m_wndList); CFont* pOldFont = dcList.SelectObject (GetFont ()); ASSERT_VALID (pOldFont); m_bMDIActions = TRUE; m_lstCloseDisabled.RemoveAll (); m_lstSaveDisabled.RemoveAll (); HWND hwndT = ::GetWindow(m_pMDIFrame->m_hWndMDIClient, GW_CHILD); while (hwndT != NULL) { CBCGPMDIChildWnd* pFrame = DYNAMIC_DOWNCAST (CBCGPMDIChildWnd, CWnd::FromHandle (hwndT)); if (pFrame == NULL) { hwndT = ::GetWindow(hwndT,GW_HWNDNEXT); continue; } if (!pFrame->CanShowOnWindowsList ()) { hwndT = ::GetWindow(hwndT,GW_HWNDNEXT); continue; } TCHAR szWndTitle[256]; ::GetWindowText(hwndT,szWndTitle,sizeof(szWndTitle)/sizeof(szWndTitle[0])); int index = m_wndList.AddString(szWndTitle); int cxCurr = dcList.GetTextExtent (szWndTitle).cx; cxExtent = max (cxExtent, cxCurr); m_wndList.SetItemData(index,(DWORD_PTR) hwndT); if (pFrame != NULL && pFrame->IsReadOnly ()) { m_lstSaveDisabled.AddTail (hwndT); } DWORD dwStyle = ::GetWindowLong (hwndT, GWL_STYLE); if ((dwStyle & WS_SYSMENU) == 0) { m_bMDIActions = FALSE; } else { HMENU hSysMenu = ::GetSystemMenu (hwndT, FALSE); if (hSysMenu == NULL) { m_bMDIActions = FALSE; } else { MENUITEMINFO menuInfo; ZeroMemory(&menuInfo,sizeof(MENUITEMINFO)); menuInfo.cbSize = sizeof(MENUITEMINFO); menuInfo.fMask = MIIM_STATE; if (!::GetMenuItemInfo(hSysMenu, SC_CLOSE, FALSE, &menuInfo) || (menuInfo.fState & MFS_GRAYED) || (menuInfo.fState & MFS_DISABLED)) { m_lstCloseDisabled.AddTail (hwndT); } } } hwndT = ::GetWindow(hwndT,GW_HWNDNEXT); } m_wndList.SetHorizontalExtent (cxExtent + ::GetSystemMetrics (SM_CXHSCROLL) + 30); dcList.SelectObject (pOldFont); m_Icons.DeleteImageList(); m_Icons.Create(globalData.m_sizeSmallIcon.cx, globalData.m_sizeSmallIcon.cy, ILC_COLOR32 | ILC_MASK, 0, 10); for (int i = 0; i < m_wndList.GetCount(); i++) { HWND hwnd = (HWND)m_wndList.GetItemData(i); HICON hIcon = NULL; if ((hIcon = (HICON)::SendMessage(hwnd, WM_GETICON, FALSE, 0)) == NULL) { hIcon = (HICON)(LONG_PTR)GetClassLongPtr(hwnd, GCLP_HICONSM); } if (hIcon != NULL) { m_Icons.Add(hIcon); m_wndList.SetItemImage(i, m_Icons.GetImageCount() - 1); } } m_wndList.SetImageList(m_Icons.GetSafeHandle()); m_wndList.SetRedraw(TRUE); }
void CGameView::OnTimer(UINT_PTR nIDEvent) { // 심장소리 음악 if (!gv_min && gv_sec < 10 && !gv_timeDV){ // 분이 0이고 초가 10초 미만일 때 시간제한 음악 켬 StopSounds (gv_bgDV) ; PlaySounds (gv_timeDV) ; } CClientDC dc (this) ; CRect rect ; GetClientRect (&rect) ; CFont myFont, *pOldFont ; CString str; // Text 설정 Part myFont.CreateFont (25, 0, 0, 0, FW_BOLD, true, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, gv_font) ; pOldFont =dc.SelectObject (&myFont) ; dc.SetBkColor (gv_bgColor) ; // 글자의 배경은 바탕과 같이 dc.SetTextColor (0x00FFFFFF & ~gv_bgColor) ; // 글자 색을 바탕화면의 반대 색으로 // 시간에 따른 출력부 if (!gv_scoreTF) { if (gv_min < 10 && gv_min) gv_minStr.Format (_T(" 0%d"), gv_min) ; else if (!gv_min) gv_minStr.Format (_T (" 00")) ; else gv_minStr.Format (_T (" %d"), gv_min) ; if (gv_sec < 10 && gv_sec) gv_secStr.Format (_T("0%d"), gv_sec) ; else if (!gv_sec) gv_secStr.Format (_T ("00")) ; else gv_secStr.Format (_T ("%d"), gv_sec) ; if (gv_csec < 10 && gv_csec) gv_csecStr.Format (_T("0%d"), gv_csec) ; else if (!gv_csec) gv_csecStr.Format (_T ("00")) ; else gv_csecStr.Format (_T ("%d"), gv_csec) ; str.Format (_T (" %s : %s : %s "), gv_minStr, gv_secStr, gv_csecStr) ; dc.SetTextAlign (TA_RIGHT) ; dc.TextOutW (rect.Width () -20, rect.top +45, str) ; // 초계산 if (--gv_csec < 0) { if (!gv_min && !gv_sec) OnSuccess () ; gv_csec =99 ; gv_sec-- ; pTimeDlg ->timeCtrl.StepIt () ; // 초가 줄때마다 실행 } if (gv_sec < 0 && gv_min) { gv_sec =59 ; gv_min-- ; } // 카운트 출력 str.Format (_T (" CLICK COUNT : %u "), gv_cnt) ; dc.TextOutW (rect.Width () -20, rect.top +20, str) ; // 점수 출력 dc.SetTextAlign (TA_CENTER) ; str.Format (_T (" Score : %u "), gv_point) ; dc.TextOutW (rect.Width () /2, rect.top +25, str) ; } else { while (gv_tempMin-- > 0) gv_tempSec +=60 ; // 분이 남아 있다면 초로 옮김 // 시간 감소 및 포인트 증가 if (gv_tempSec > 0) { // 초가 0보다 클때까지 gv_point+=3 ; gv_tempSec-- ; // 점수는 3증가 초는 1증감 pTimeDlg ->timeCtrl.StepIt () ; dc.SetTextAlign (TA_CENTER) ; str.Format (_T (" Score :%u "), gv_point) ; dc.TextOutW (rect.Width () /2 , rect.top +25, str) ; } } dc.SelectObject (myFont) ; myFont.DeleteObject () ; CView::OnTimer(nIDEvent); }
// determine size of a given cell based on actual font settings CSize CMiniCalendarCtrl::ComputeSize() { const int iXDaysSpaceFromBorder = 15; const int iHeaderSpaceForBorder = 15; const int iHeaderYSpaceForBorder = 3; const int iDaysXSpacing = 5; const int iDaysYSpacing = 2; CSize szReturn(0, 0); int iWidthByDays = 0; int iWidthByDaysOfWeekIndividual = 0; int iWidthByHeader = 0; int iHeaderHeight = 0; int iDaysHeight = 0; int iX; // allocate a DC to use when testing sizes, etc CClientDC* pDC = NULL; if (::IsWindow(GetSafeHwnd())) pDC = new CClientDC(this); else pDC = new CClientDC(AfxGetMainWnd()); ASSERT(pDC); if (!pDC) throw (new CMemoryException()); // get current font and save for later restoration CFont* pOldFont = pDC->GetCurrentFont(); // first, use days to determine width // NOTE: typically, most fonts use the same pixel sizes for all numbers, // but this is not mandatory and many "fancy" fonts change this. To deal // with this, I am calculating the width of all possible dates the control will display pDC->SelectObject(m_pFont); for (iX = 1; iX <= 31; iX++) { CString strTemp = "00"; strTemp += CCalendarUtils::LongToString(iX); strTemp = strTemp.Right(2); CSize szTemp = pDC->GetTextExtent(strTemp); if (szTemp.cx > iWidthByDays) iWidthByDays = szTemp.cx; if (szTemp.cy > iDaysHeight) iDaysHeight = szTemp.cy; } // make sure we also try it with the special days font pDC->SelectObject(m_pFontBold); for (iX = 1; iX <= 31; iX++) { CString strTemp = "00"; strTemp += CCalendarUtils::LongToString(iX); strTemp = strTemp.Right(2); CSize szTemp = pDC->GetTextExtent(strTemp); if (szTemp.cx > iWidthByDays) iWidthByDays = szTemp.cx; if (szTemp.cy > iDaysHeight) iDaysHeight = szTemp.cy; } // finish computation m_iDaysHeight = iDaysHeight; m_iIndividualDayWidth = iWidthByDays; iWidthByDays = (iWidthByDays * 7) + (iDaysXSpacing*6) + (iXDaysSpaceFromBorder*2); iDaysHeight = (iDaysHeight * 6) + (iDaysYSpacing*6); // next use days of week to determine width and height. here again, we test each variant pDC->SelectObject(m_pFont); int iWidthByDaysOfWeek = pDC->GetTextExtent("S").cx; if (pDC->GetTextExtent("M").cx > iWidthByDaysOfWeek) iWidthByDaysOfWeek = pDC->GetTextExtent("M").cx; if (pDC->GetTextExtent("T").cx > iWidthByDaysOfWeek) iWidthByDaysOfWeek = pDC->GetTextExtent("T").cx; if (pDC->GetTextExtent("W").cx > iWidthByDaysOfWeek) iWidthByDaysOfWeek = pDC->GetTextExtent("W").cx; if (pDC->GetTextExtent("F").cx > iWidthByDaysOfWeek) iWidthByDaysOfWeek = pDC->GetTextExtent("F").cx; int iDaysOfWeekHeight = pDC->GetTextExtent("S").cy; if (pDC->GetTextExtent("M").cy > iDaysOfWeekHeight) iDaysOfWeekHeight = pDC->GetTextExtent("M").cy; if (pDC->GetTextExtent("T").cy > iDaysOfWeekHeight) iDaysOfWeekHeight = pDC->GetTextExtent("T").cy; if (pDC->GetTextExtent("W").cy > iDaysOfWeekHeight) iDaysOfWeekHeight = pDC->GetTextExtent("W").cy; if (pDC->GetTextExtent("F").cy > iDaysOfWeekHeight) iDaysOfWeekHeight = pDC->GetTextExtent("F").cy; // finish computation iWidthByDaysOfWeekIndividual = iWidthByDaysOfWeek; iWidthByDaysOfWeek = (iWidthByDaysOfWeek * 7) + (iDaysXSpacing*6) + (iXDaysSpaceFromBorder*2); if (iWidthByDaysOfWeekIndividual > m_iIndividualDayWidth) m_iIndividualDayWidth = iWidthByDaysOfWeekIndividual; m_iDaysOfWeekHeight = iDaysOfWeekHeight; // next compute width and height of header (month name and year) // again, because of font variations we will use a 20 year window and // attempt the calculation with every month name pDC->SelectObject(m_pFontBold); for (int iYear = m_iCurrentYear-10; iYear <= m_iCurrentYear+10; iYear++) { for (int iMonth = 1; iMonth <= 12; iMonth++) { CString strTest = GetMonthName(iMonth); strTest += " "; strTest += CCalendarUtils::LongToString(iYear); if (pDC->GetTextExtent(strTest).cx > iWidthByHeader) iWidthByHeader = pDC->GetTextExtent(strTest).cx; if (pDC->GetTextExtent(strTest).cy > iHeaderHeight) iHeaderHeight = pDC->GetTextExtent(strTest).cy; } } // finish computation iWidthByHeader += (iHeaderSpaceForBorder*2); iHeaderHeight += (iHeaderYSpaceForBorder*2); m_iHeaderHeight = iHeaderHeight; // cleanup DC pDC->SelectObject(pOldFont); // destroy DC delete pDC; // NOW, adjust return size if needed // start with widths (these are easy at this point) int iTotalWidth = iWidthByHeader; if (iWidthByDaysOfWeek > iTotalWidth) iTotalWidth = iWidthByDaysOfWeek; if (iWidthByDays > iTotalWidth) iTotalWidth = iWidthByDays; if (iTotalWidth > szReturn.cx) szReturn.cx = iTotalWidth; // adjust heights int iTotalHeight = iHeaderHeight + iDaysOfWeekHeight + iDaysHeight + 12; if (iTotalHeight > szReturn.cy) szReturn.cy = iTotalHeight; m_szMonthSize = szReturn; m_bSizeComputed = TRUE; return szReturn; }
int CMainWindow::OnCreate (LPCREATESTRUCT lpcs) { if (CWnd::OnCreate (lpcs) == -1) return -1; // // Create an 8-point MS Sans Serif font to use in the controls. // m_fontMain.CreatePointFont (80, _T ("MS Sans Serif")); // // Compute the average width and height of a character in the font. // CClientDC dc (this); CFont* pOldFont = dc.SelectObject (&m_fontMain); TEXTMETRIC tm; dc.GetTextMetrics (&tm); m_cxChar = tm.tmAveCharWidth; m_cyChar = tm.tmHeight + tm.tmExternalLeading; dc.SelectObject (pOldFont); // // Create the controls that will appear in the FontView window. // CRect rect (m_cxChar * 2, m_cyChar, m_cxChar * 48, m_cyChar * 2); m_wndLBTitle.Create (_T ("Typefaces"), WS_CHILD | WS_VISIBLE | SS_LEFT, rect, this); rect.SetRect (m_cxChar * 2, m_cyChar * 2, m_cxChar * 48, m_cyChar * 18); m_wndListBox.CreateEx (WS_EX_CLIENTEDGE, _T ("listbox"), NULL, WS_CHILD | WS_VISIBLE | LBS_STANDARD, rect, this, IDC_LISTBOX); rect.SetRect (m_cxChar * 2, m_cyChar * 19, m_cxChar * 48, m_cyChar * 20); m_wndCheckBox.Create (_T ("Show TrueType fonts only"), WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, rect, this, IDC_CHECKBOX); rect.SetRect (m_cxChar * 2, m_cyChar * 21, m_cxChar * 66, m_cyChar * 25); m_wndGroupBox.Create (_T ("Sample"), WS_CHILD | WS_VISIBLE | BS_GROUPBOX, rect, this, (UINT) -1); rect.SetRect (m_cxChar * 4, m_cyChar * 22, m_cxChar * 64, (m_cyChar * 99) / 4); m_wndSampleText.Create (_T (""), WS_CHILD | WS_VISIBLE | SS_CENTER, rect, this, IDC_SAMPLE); rect.SetRect (m_cxChar * 50, m_cyChar * 2, m_cxChar * 66, m_cyChar * 4); m_wndPushButton.Create (_T ("Print Sample"), WS_CHILD | WS_VISIBLE | WS_DISABLED | BS_PUSHBUTTON, rect, this, IDC_PRINT); // // Set each control's font to 8-point MS Sans Serif. // m_wndLBTitle.SetFont (&m_fontMain, FALSE); m_wndListBox.SetFont (&m_fontMain, FALSE); m_wndCheckBox.SetFont (&m_fontMain, FALSE); m_wndGroupBox.SetFont (&m_fontMain, FALSE); m_wndPushButton.SetFont (&m_fontMain, FALSE); // // Fill the list box with typeface names and return. // FillListBox (); return 0; }
//*************************************************************************** BOOL CBCGPRibbonKeyTip::Show (BOOL bRepos) { ASSERT_VALID (this); ASSERT_VALID (m_pElement); if (GetSafeHwnd () != NULL && !bRepos) { ShowWindow (SW_SHOWNOACTIVATE); return TRUE; } CWnd* pWndParent = m_pElement->GetParentWnd (); if (pWndParent->GetSafeHwnd () == NULL) { return FALSE; } CClientDC dc (NULL); CFont* pOldFont = dc.SelectObject (&globalData.fontRegular); ASSERT (pOldFont != NULL); CRect rect = m_pElement->GetKeyTipRect (&dc, m_bIsMenu); dc.SelectObject (pOldFont); if (rect.IsRectEmpty ()) { return FALSE; } pWndParent->ClientToScreen (&rect); //------------------------- // Normalize inside screen: //------------------------- CRect rectScreen; MONITORINFO mi; mi.cbSize = sizeof (MONITORINFO); if (GetMonitorInfo (MonitorFromPoint (rect.TopLeft (), MONITOR_DEFAULTTONEAREST), &mi)) { rectScreen = mi.rcWork; } else { ::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0); } if (rect.right > rectScreen.right) { rect.OffsetRect (rectScreen.right - rect.right, 0); } else if (rect.left < rectScreen.left) { rect.OffsetRect (rectScreen.left - rect.left, 0); } if (rect.bottom > rectScreen.bottom) { rect.OffsetRect (0, rectScreen.bottom - rect.bottom); } else if (rect.top < rectScreen.top) { rect.OffsetRect (rectScreen.top - rect.top, 0); } if (m_pElement->IsScrolledOut ()) { if (GetSafeHwnd () != NULL) { ShowWindow (SW_HIDE); UpdateMenuShadow (); } return TRUE; } if (GetSafeHwnd () == NULL) { if (m_strClassName.IsEmpty ()) { m_strClassName = ::AfxRegisterWndClass ( CS_SAVEBITS, ::LoadCursor(NULL, IDC_ARROW), (HBRUSH)(COLOR_BTNFACE + 1), NULL); } DWORD dwStyleEx = WS_EX_TOOLWINDOW | WS_EX_TOPMOST; if (m_pElement->IsDisabled () && CBCGPVisualManager::GetInstance ()->IsLayeredRibbonKeyTip ()) { dwStyleEx |= WS_EX_LAYERED; } if (!CreateEx (dwStyleEx, m_strClassName, _T(""), WS_POPUP, rect, NULL, 0)) { return FALSE; } m_rectScreen = rect; if (dwStyleEx & WS_EX_LAYERED) { globalData.SetLayeredAttrib (GetSafeHwnd (), 0, 128, LWA_ALPHA); } } else { SetWindowPos (NULL, rect.left, rect.top, -1, -1, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE); } ShowWindow (SW_SHOWNOACTIVATE); return TRUE; }
STDMETHODIMP CMyCom1::DrawOffset(unsigned long m_pDC, unsigned long m_pOffset, double m_Scale, unsigned long m_pGraphInfo, BOOL scale_flag, BOOL m_active_flag) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here CClientDC * pDC = (CClientDC*) m_pDC; GraphInfo * pGraphInfo; //设置 if ( m_pGraphInfo != NULL ) { pGraphInfo = (GraphInfo*)m_pGraphInfo; m_GraphInfo.SetGraphInfo(*pGraphInfo); } else pGraphInfo = &m_GraphInfo; //计算偏移量 if ( m_pOffset != NULL ) { CPoint * offset = (CPoint *)m_pOffset; OffsetRgn((unsigned long)offset); } //设置激活标志 isActive = m_active_flag; double scale = 0; m_scale_flag = scale_flag; if ( m_scale_flag ) scale = m_Scale; else scale = 1; CFont * sysFont = pDC->SelectObject(&(pGraphInfo->font)); CPen * pen = new CPen( pGraphInfo->normal_penStyle, pGraphInfo->normal_linewidth, pGraphInfo->normal_linecolor ); //构造画笔 CPen * sysPen = pDC->SelectObject(pen); CBrush * normalBrush = new CBrush( pGraphInfo->normal_regioncolor ); //普通显示的画刷 CBrush * activeBrush = new CBrush( pGraphInfo->active_regioncolor ); //激活后的画刷 CBrush * blackBrush = new CBrush( BLACKBRUSHCOLOR ); CRgn outRgn; outRgn.CreateRectRgn(0, 0, 5, 5); CRect smallRect; //判断是否激活了,如果激活,添加outRect if ( isActive ) //激活 { if ( m_scale_flag ) //如果是在modelview区域 { //选中后,在外边画一个方框 outRgn.CombineRgn(&upRgn, &downRgn, RGN_OR); outRgn.GetRgnBox(&outRect); outRect.InflateRect(5, 5); pDC->MoveTo(outRect.left, outRect.top); pDC->LineTo(outRect.right, outRect.top); pDC->LineTo(outRect.right, outRect.bottom); pDC->LineTo(outRect.left, outRect.bottom); pDC->LineTo(outRect.left, outRect.top); //画出upRgn, downRgn, 和连线 //pDC->FillRgn(&upRgn, normalBrush); CRect upRect; upRgn.GetRgnBox(upRect); pDC->Rectangle(upRect); pDC->MoveTo(upPoints[2]); pDC->LineTo(upPoints[5]); pDC->MoveTo(topPoint); pDC->LineTo(bottomPoint); pDC->MoveTo(leftPoint); pDC->LineTo(rightPoint); pDC->FillRgn(&downRgn, normalBrush); inRect.SetRect(upPoints[0].x, upPoints[0].y, upPoints[2].x, upPoints[2].y); pDC->SetTextColor(pGraphInfo->textcolor); pDC->DrawText(m_name, inRect, TEXTOUTFOMAT); //|DT_END_ELLIPSIS); //在矩形的角上,画四个小矩形,5*5象素 smallRect.SetRect(outRect.left, outRect.top, outRect.left+5, outRect.top+5); pDC->FillRect(smallRect, blackBrush); smallRect.SetRect(outRect.right-5, outRect.top, outRect.right, outRect.top+5); pDC->FillRect(smallRect, blackBrush); smallRect.SetRect(outRect.right-5, outRect.bottom-5, outRect.right, outRect.bottom); pDC->FillRect(smallRect, blackBrush); smallRect.SetRect(outRect.left, outRect.bottom-5, outRect.left+5, outRect.bottom); pDC->FillRect(smallRect, blackBrush); } else //如果是在comview区域 { //选中后,在外边画一个方框 downRgn.GetRgnBox(&outRect); outRect.InflateRect(5, 5); pDC->MoveTo(outRect.left, outRect.top); pDC->LineTo(outRect.right, outRect.top); pDC->LineTo(outRect.right, outRect.bottom); pDC->LineTo(outRect.left, outRect.bottom); pDC->LineTo(outRect.left, outRect.top); //画出downRgn pDC->FillRgn(&downRgn, normalBrush); //在矩形的角上,画四个小矩形,5*5象素 smallRect.SetRect(outRect.left, outRect.top, outRect.left+5, outRect.top+5); pDC->FillRect(smallRect, blackBrush); smallRect.SetRect(outRect.right-5, outRect.top, outRect.right, outRect.top+5); pDC->FillRect(smallRect, blackBrush); smallRect.SetRect(outRect.right-5, outRect.bottom-5, outRect.right, outRect.bottom); pDC->FillRect(smallRect, blackBrush); smallRect.SetRect(outRect.left, outRect.bottom-5, outRect.left+5, outRect.bottom); pDC->FillRect(smallRect, blackBrush); } } else //未激活 { if ( m_scale_flag ) //如果是在modelview区域 { //画出upRgn, downRgn, 和连线 //pDC->FillRgn(&upRgn, normalBrush); CRect upRect; upRgn.GetRgnBox(upRect); pDC->Rectangle(upRect); pDC->MoveTo(upPoints[2]); pDC->LineTo(upPoints[5]); pDC->MoveTo(topPoint); pDC->LineTo(bottomPoint); pDC->MoveTo(leftPoint); pDC->LineTo(rightPoint); pDC->FillRgn(&downRgn, normalBrush); inRect.SetRect(upPoints[0].x, upPoints[0].y, upPoints[2].x, upPoints[2].y); pDC->SetTextColor(pGraphInfo->textcolor); pDC->DrawText(m_name, inRect, TEXTOUTFOMAT); //|DT_END_ELLIPSIS); } else //如果是在comview区域 { //画出downRgn pDC->FillRgn(&downRgn, normalBrush); } } //释放 pDC->SelectObject(sysFont); pDC->SelectObject(sysPen); delete(pen); delete(normalBrush); delete(activeBrush); delete(blackBrush); return S_OK; }
//******************************************************************************************* void CLoginBarToolTipCtrl::Track (CRect rect, const CString& strText) { if (GetSafeHwnd () == NULL) { return; } if (m_rectLast == rect && m_strText == strText) { return; } ASSERT_VALID (m_pWndParent); m_rectLast = rect; m_strText = strText; CClientDC dc (this); //ASSERT_VALID(m_pFont); CFont* pPrevFont = m_pFont == NULL ? (CFont*) dc.SelectStockObject (DEFAULT_GUI_FONT) : dc.SelectObject (&theApp.m_font); ASSERT (pPrevFont != NULL); int nTextHeight = rect.Height () ; int nTextWidth = rect.Width (); if (m_strText.FindOneOf (_T("\n")) != -1) // multi-line tooltip { const int nDefaultHeight = globalData.GetTextHeight () ; const int nDefaultWidth = 200; CRect rectText (0, 0, nDefaultWidth, nDefaultHeight); nTextHeight = dc.DrawText (m_strText, rectText, DT_LEFT | /*DT_WORDBREAK | */DT_CALCRECT | DT_NOPREFIX); nTextWidth = rectText.Width (); nTextHeight += 2 * m_nTextMargin ; nTextWidth += 2 * m_nTextMargin; nTextHeight += (GetLineCount(m_strText) - 1) * m_nTextMargin; //加上行间距 } else { nTextWidth = dc.GetTextExtent (m_strText).cx + 2 * m_nTextMargin; } dc.SelectObject (pPrevFont); if (m_pWndParent->GetExStyle () & WS_EX_LAYOUTRTL) { rect.left = rect.right - nTextWidth; } else { rect.right = rect.left + nTextWidth; } rect.bottom = rect.top + nTextHeight; if (rect.Height () < m_rectLast.Height ()) { rect.top = m_rectLast.top; rect.bottom = m_rectLast.bottom; } MONITORINFO mi; mi.cbSize = sizeof (MONITORINFO); CRect rectScreen; if (GetMonitorInfo (MonitorFromPoint (rect.TopLeft (), MONITOR_DEFAULTTONEAREST), &mi)) { rectScreen = mi.rcWork; } else { ::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0); } if (rect.Width () > rectScreen.Width ()) { rect.left = rectScreen.left; rect.right = rectScreen.right; } else if (rect.right > rectScreen.right) { rect.OffsetRect( rectScreen.right - rect.right, 0 ); //rect.right = rectScreen.right; //rect.left = rect.right - nTextWidth; } else if (rect.left < rectScreen.left) { rect.OffsetRect( rectScreen.left - rect.left, 0 ); //rect.left = rectScreen.left; //rect.right = rect.left + nTextWidth; } if (rect.Height () > rectScreen.Height ()) { rect.top = rectScreen.top; rect.bottom = rectScreen.bottom; } else if (rect.bottom > rectScreen.bottom) { rect.OffsetRect(0, rectScreen.bottom - rect.bottom); //rect.bottom = rectScreen.bottom; //rect.top = rect.bottom - nTextHeight; } else if (rect.top < rectScreen.top) { rect.OffsetRect(0, rectScreen.top - rect.top); //rect.top = rectScreen.top; //rect.bottom = rect.bottom + nTextHeight; } rect.bottom += 3; SetWindowPos (&wndTop, rect.left, rect.top, rect.Width (), rect.Height (), SWP_NOACTIVATE | SWP_NOOWNERZORDER); ShowWindow (SW_SHOWNOACTIVATE); Invalidate (); UpdateWindow (); SetCursor (AfxGetApp ()->LoadStandardCursor (IDC_ARROW)); }
// The code fragment shows how to create a font object, // select the font object into a DC (device context) for text // drawing, and finally delete the font object. CClientDC dc(this); CFont font; VERIFY(font.CreatePointFont(120, _T("Arial"), &dc)); // Do something with the font just created... CFont* def_font = dc.SelectObject(&font); dc.TextOut(5, 5, _T("Hello"), 5); dc.SelectObject(def_font); // Done with the font. Delete the font object. font.DeleteObject();
//***************************************************************************** void CBCGPCaptionBar::RecalcLayout () { CClientDC dc (NULL); CFont* pOldFont = dc.SelectObject ( m_hFont == NULL ? &globalData.fontRegular : CFont::FromHandle (m_hFont)); ASSERT (pOldFont != NULL); TEXTMETRIC tm; dc.GetTextMetrics (&tm); int nTextHeight = tm.tmHeight + 2; CSize sizeImage = GetImageSize (); const int nButtonVertMargin = CBCGPVisualManager::GetInstance()->GetMessageBarMargin(); const int nBorderSize = m_bIsMessageBarMode ? 0 : m_nBorderSize; //------------------------------------------------------------------- // the height is set to the default (provided by the user in Create) // or calculated if it is -1 //------------------------------------------------------------------- if (m_nDefaultHeight != -1) { m_nCurrentHeight = m_nDefaultHeight; } else { if (!m_strBtnText.IsEmpty () && m_bIsMessageBarMode) { nTextHeight += 2 * nButtonVertMargin; } m_nCurrentHeight = max (nTextHeight, sizeImage.cy) + m_nMargin * 2 + nBorderSize; } if (m_bIsMessageBarMode) { m_nCurrentHeight += CBCGPVisualManager::GetInstance()->GetMessageBarMargin() * 2; } // for left and center alignment: icon, button, text // for right alignment: text, button, icon CRect rectClient; GetClientRect (rectClient); if (rectClient.IsRectEmpty ()) { return; } if (m_bIsMessageBarMode) { CSize sizeImage = CBCGPMenuImages::Size (); const int nCloseButtonMargin = 4; sizeImage.cx += 2 * nCloseButtonMargin; sizeImage.cy += 2 * nCloseButtonMargin; m_rectClose = CRect ( CPoint (rectClient.right - sizeImage.cx, rectClient.top + nCloseButtonMargin), sizeImage); m_rectClose.right--; rectClient.DeflateRect (nCloseButtonMargin, nCloseButtonMargin); rectClient.right -= m_rectClose.Width (); } else { m_rectClose.SetRectEmpty(); } BOOL bButtonLeftOfIcon = FALSE; BOOL bTextLeftOfButton = FALSE; BOOL bTextLeftOfIcon = FALSE; BOOL bIconCenter = FALSE; BOOL bButtonCenter = FALSE; BOOL bButtonAfterText = FALSE; BOOL bTextCenter = FALSE; // differs from the current height, because the border size is non-client area int nBaseLine = rectClient.CenterPoint ().y; int nCenterOffset = rectClient.CenterPoint ().x; int nNextXOffsetLeft = rectClient.left + m_nMargin; int nNextXOffsetRight = rectClient.right - m_nMargin; int nNextXOffsetCenter = nCenterOffset; if (IsImageSet ()) { if (sizeImage.cy < rectClient.Height () || m_bIsMessageBarMode) { // center the icon if its height lesser than client area height m_rectImage.top = nBaseLine - sizeImage.cy / 2; } else { // otherwise, clip it from the buttom m_rectImage.top = rectClient.top + m_nMargin; } if (!m_bStretchImage) { m_rectImage.bottom = m_rectImage.top + sizeImage.cy; } else { m_rectImage.bottom = rectClient.bottom - m_nMargin; } switch (m_iconAlignment) { case ALIGN_LEFT: m_rectImage.left = nNextXOffsetLeft; m_rectImage.right = m_rectImage.left + sizeImage.cx; nNextXOffsetLeft = m_rectImage.right + m_nHorzElementOffset; break; case ALIGN_RIGHT: m_rectImage.left = nNextXOffsetRight - sizeImage.cx; m_rectImage.right = m_rectImage.left + sizeImage.cx; nNextXOffsetRight = m_rectImage.left - m_nHorzElementOffset; // only in this case button and text is at the left side of the icon bButtonLeftOfIcon = TRUE; bTextLeftOfIcon = TRUE; break; case ALIGN_CENTER: bIconCenter = TRUE; nNextXOffsetCenter -= sizeImage.cx / 2; if (m_btnAlignnment == ALIGN_LEFT) { bButtonLeftOfIcon = TRUE; } if (m_textAlignment == ALIGN_LEFT) { bTextLeftOfIcon = TRUE; } break; default: ASSERT (FALSE); } } else { m_rectImage.SetRectEmpty(); } int nButtonWidth = 0; if (!m_strBtnText.IsEmpty ()) { nButtonWidth = dc.GetTextExtent (m_strBtnText).cx + 2 * m_nHorzElementOffset; if (m_bIsMessageBarMode) { nButtonWidth += 2 * nButtonHorzMargin; } if (m_uiBtnID != 0 && m_bBtnEnabled && m_bBtnHasDropDownArrow) { nButtonWidth += nMenuArrowWidth; } // the button always has a height equivalent to the bar's height m_rectButton.top = rectClient.top; m_rectButton.bottom = rectClient.bottom; if (m_bIsMessageBarMode) { m_rectButton.DeflateRect (0, nButtonVertMargin); } switch (m_btnAlignnment) { case ALIGN_LEFT: if (!m_bIsMessageBarMode || m_textAlignment != ALIGN_LEFT) { m_rectButton.left = nNextXOffsetLeft; if (nNextXOffsetLeft == rectClient.left + m_nMargin) { m_rectButton.left = rectClient.left + m_nMargin; } m_rectButton.right = m_rectButton.left + nButtonWidth; nNextXOffsetLeft = m_rectButton.right + m_nHorzElementOffset; } else { bButtonAfterText = TRUE; } break; case ALIGN_RIGHT: m_rectButton.left = nNextXOffsetRight - nButtonWidth; if (nNextXOffsetRight == rectClient.right - m_nMargin) { m_rectButton.left = rectClient.right - nButtonWidth - m_nMargin; } m_rectButton.right = m_rectButton.left + nButtonWidth; nNextXOffsetRight = m_rectButton.left - m_nHorzElementOffset; // only in this case text at the left side of the button bTextLeftOfButton = TRUE; break; case ALIGN_CENTER: bButtonCenter = TRUE; nNextXOffsetCenter -= nButtonWidth / 2; if (m_textAlignment == ALIGN_LEFT) { bTextLeftOfButton = TRUE; } break; default: ASSERT (FALSE); return; } } else { m_rectButton.SetRectEmpty(); } CSize sizeText (0, 0); if (!m_strText.IsEmpty ()) { sizeText = GetTextSize (&dc, m_strText); m_rectText.top = nBaseLine - sizeText.cy / 2; m_rectText.bottom = m_rectText.top + sizeText.cy; switch (m_textAlignment) { case ALIGN_LEFT: m_rectText.left = nNextXOffsetLeft; nNextXOffsetLeft += sizeText.cx + 2 * m_nMargin; break; case ALIGN_RIGHT: m_rectText.left = nNextXOffsetRight - sizeText.cx; break; case ALIGN_CENTER: bTextCenter = TRUE; nNextXOffsetCenter -= sizeText.cx / 2; break; default: ASSERT (FALSE); return; } m_rectText.right = m_rectText.left + sizeText.cx; AdjustRectToMargin (m_rectText, rectClient, m_nMargin); m_rectDrawText = m_rectText; } if (bIconCenter) { m_rectImage.left = nNextXOffsetCenter; m_rectImage.right = m_rectImage.left + sizeImage.cx; nNextXOffsetCenter = m_rectImage.right + m_nHorzElementOffset; } if (bButtonAfterText) { m_rectButton.left = nNextXOffsetLeft; m_rectButton.right = m_rectButton.left + nButtonWidth; if (m_rectButton.right + m_nMargin > rectClient.right) { m_rectButton.right = rectClient.right - m_nMargin; m_rectButton.left = m_rectButton.right - nButtonWidth; } } else if (bButtonCenter) { m_rectButton.left = nNextXOffsetCenter; m_rectButton.right = m_rectButton.left + nButtonWidth; nNextXOffsetCenter = m_rectButton.right + m_nHorzElementOffset; } if (bTextCenter) { m_rectText.left = nNextXOffsetCenter; m_rectText.right = m_rectText.left + sizeText.cx; AdjustRectToMargin (m_rectText, rectClient, m_nMargin); m_rectDrawText = m_rectText; } if (IsImageSet ()) { // do not retain image size if it should be stretched AdjustRectToMargin (m_rectImage, rectClient, m_nMargin, !m_bStretchImage); if (m_rectImage.left < rectClient.left || m_rectImage.right > rectClient.right) { m_rectImage.SetRectEmpty (); } } CRect rectButtonTemp = m_rectButton; if (!m_strBtnText.IsEmpty () && IsImageSet ()) { CheckRectangle (rectButtonTemp, m_rectImage, bButtonLeftOfIcon); } if (!m_strBtnText.IsEmpty ()) { AdjustRectToMargin (rectButtonTemp, rectClient, m_nMargin); if (m_rectButton.Width () + m_rectImage.Width () + 2 * m_nMargin > rectClient.Width ()) { m_rectButton.SetRectEmpty (); } } if (!m_strText.IsEmpty ()) { CheckRectangle (m_rectDrawText, m_rectImage, bTextLeftOfIcon); CheckRectangle (m_rectDrawText, rectButtonTemp, bTextLeftOfButton || bButtonAfterText); } dc.SelectObject (pOldFont); m_bTextIsTruncated = m_rectDrawText.Width () < sizeText.cx; UpdateTooltips (); }