//********************************************************************* void CCxNDArrayDimGrid::SetRowHeight () { if (m_bIsPrinting) { ASSERT_VALID (m_pPrintDC); // map to printer metrics HDC hDCFrom = ::GetDC(NULL); int nYMul = m_pPrintDC->GetDeviceCaps(LOGPIXELSY); // pixels in print dc int nYDiv = ::GetDeviceCaps(hDCFrom, LOGPIXELSY); // pixels in screen dc ::ReleaseDC(NULL, hDCFrom); TEXTMETRIC tm; m_pPrintDC->GetTextMetrics (&tm); m_PrintParams.m_nRowHeight = tm.tmHeight + ::MulDiv (2 * TEXT_VMARGIN, nYMul, nYDiv); m_PrintParams.m_nLargeRowHeight = m_PrintParams.m_nRowHeight; } else { CClientDC dc (this); HFONT hfontOld = SetCurrFont (&dc); TEXTMETRIC tm; dc.GetTextMetrics (&tm); m_nRowHeight = tm.tmHeight + 2 * TEXT_VMARGIN; m_nLargeRowHeight = m_nRowHeight; ::SelectObject (dc.GetSafeHdc (), hfontOld); } }
void CBCGPPlannerViewMulti::OnDrawHeaderResource (CDC* pDC, const CRect& rectHeader) { ASSERT_VALID (pDC); const int nDays = GetViewDuration (); DWORD dwFlags = GetPlanner ()->GetDrawFlags (); BOOL bBold = (dwFlags & BCGP_PLANNER_DRAW_VIEW_CAPTION_DAY_BOLD) == BCGP_PLANNER_DRAW_VIEW_CAPTION_DAY_BOLD; HFONT hOldFont = NULL; if (bBold) { hOldFont = SetCurrFont (pDC, bBold); } for (int nDay = 0; nDay < nDays; nDay ++) { CRect rectCaption (rectHeader); rectCaption.left = m_ViewRects[nDay].left; rectCaption.right = m_ViewRects[nDay].right; DrawHeader (pDC, rectCaption, m_Resources [0].m_Rects[nDay].Width ()); CRect rectResCaption (rectCaption); for (int i = 0; i < m_Resources.GetSize (); i++) { XResource& res = m_Resources[i]; rectResCaption.left = res.m_Rects[nDay].left; rectResCaption.right = res.m_Rects[nDay].right; visualManager->PreparePlannerCaptionBackItem (TRUE); COLORREF clrText = OnFillPlannerCaption ( pDC, rectResCaption, FALSE, FALSE, FALSE); DrawCaptionText (pDC, rectResCaption, res.m_Description, clrText, res.m_bToolTipNeeded ? DT_LEFT : DT_CENTER); } } if (hOldFont != NULL) { ::SelectObject (pDC->GetSafeHdc (), hOldFont); } }
void CToolBoxCtrl::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 // 不为绘图消息调用 CWnd::OnPaint() CMemDC memDC(dc, this); CDC* pDC = &memDC.GetDC(); CRect rectClient; GetClientRect(rectClient); OnFillBackground(pDC, rectClient); HFONT hfontOld = SetCurrFont(pDC); pDC->SetBkMode(TRANSPARENT); OnDrawList(pDC); ::SelectObject(pDC->GetSafeHdc(), hfontOld); }
void CBCGPPlannerViewMonth::OnDrawClient (CDC* pDC, const CRect& rect) { ASSERT_VALID (pDC); CRect rectFill (rect); int nMonth = m_Date.GetMonth (); BOOL bIsWorking = nMonth % 2; const int nRows = GetViewDuration () / 7; COleDateTime day (GetDateStart ()); COleDateTime dayCurrent = COleDateTime::GetCurrentTime (); dayCurrent.SetDateTime (dayCurrent.GetYear (), dayCurrent.GetMonth (), dayCurrent.GetDay (), 0, 0, 0); int iRow = 0; int nStartColumn = 1; if (m_nWeekBarWidth != 0) { nStartColumn = 0; } { CPen penBlack (PS_SOLID, 0, visualManager->GetPlannerSeparatorColor (this)); CPen* pOldPen = pDC->SelectObject (&penBlack); const int nEnd = 7; int nCol = 0; int iColumn = 1; for (iColumn = 1; iColumn < 7; iColumn++) { if (m_ViewRects [iColumn - 1].right == m_ViewRects [iColumn].right) { nCol = iColumn - 1; break; } } for (iColumn = nStartColumn; iColumn < nEnd; iColumn++) { pDC->MoveTo (m_ViewRects [iColumn].left - 1, rect.top); pDC->LineTo (m_ViewRects [iColumn].left - 1, rect.bottom); } for (iRow = 0; iRow < nRows; iRow++) { int nIndex = iRow * 7 + 6; pDC->MoveTo (rect.left , m_ViewRects [nIndex].bottom); pDC->LineTo (rect.right, m_ViewRects [nIndex].bottom); if (m_bCompressWeekend) { nIndex -= (6 - nCol); pDC->MoveTo (m_ViewRects [nIndex].left, m_ViewRects [nIndex].bottom); pDC->LineTo (m_ViewRects [nIndex].right, m_ViewRects [nIndex].bottom); } } pDC->SelectObject (pOldPen); } DWORD dwFlags = GetPlanner ()->GetDrawFlags (); BOOL bBold = (dwFlags & BCGP_PLANNER_DRAW_VIEW_CAPTION_DAY_BOLD) == BCGP_PLANNER_DRAW_VIEW_CAPTION_DAY_BOLD; BOOL bCompact = (dwFlags & BCGP_PLANNER_DRAW_VIEW_CAPTION_DAY_COMPACT) == BCGP_PLANNER_DRAW_VIEW_CAPTION_DAY_COMPACT; HFONT hOldFont = NULL; if (bBold) { hOldFont = SetCurrFont (pDC, bBold); } const BOOL bDateBeforeMonth = CBCGPPlannerView::IsDateBeforeMonth (); for (iRow = 0; iRow < nRows; iRow++) { for (int iDay = 0; iDay < 7; iDay++) { int nDay = iRow * 7 + iDay; CRect rectDayCaption (m_ViewRects [nDay]); BOOL bToday = day == dayCurrent; BOOL bSelected = IsDateInSelection (day); bIsWorking = day.GetMonth () % 2; visualManager->PreparePlannerBackItem (bToday, bSelected); OnFillPlanner (pDC, rectDayCaption, bIsWorking); rectDayCaption.bottom = rectDayCaption.top + m_nRowHeight + 1; CString strFormat (_T("d")); CString strDate; BOOL bNewYear = FALSE; if (!bCompact) { if ((iRow == 0 && iDay == 0) || day.GetDay () == 1) { if (bDateBeforeMonth) { strFormat = _T("d MMMM"); } else { strFormat = _T("MMMM d"); } if (day.GetDay () == 1 && day.GetMonth () == 1) { bNewYear = TRUE; strFormat += _T(" yyyy"); } } if (!strFormat.IsEmpty ()) { strDate.GetBuffer (_MAX_PATH); SYSTEMTIME st; day.GetAsSystemTime (st); ::GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, strFormat, (LPTSTR)(LPCTSTR)strDate, _MAX_PATH); strDate.ReleaseBuffer (); CSize szSize (pDC->GetTextExtent (strDate)); if (rectDayCaption.Width () - 4 < szSize.cx) { if (bDateBeforeMonth) { strFormat = _T("d MMM"); } else { strFormat = _T("MMM d"); } if (bNewYear) { strFormat += _T(" yy"); } strDate.GetBuffer (_MAX_PATH); ::GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, strFormat, (LPTSTR)(LPCTSTR)strDate, _MAX_PATH); strDate.ReleaseBuffer (); } } } else { if ((iRow == 0 && iDay == 0) || day.GetDay () == 1) { if (bDateBeforeMonth) { strFormat = _T("d MMM"); } else { strFormat = _T("MMM d"); } if (day.GetDay () == 1 && day.GetMonth () == 1) { bNewYear = TRUE; strFormat += _T(" yy"); } } if (!strFormat.IsEmpty ()) { strDate.GetBuffer (_MAX_PATH); SYSTEMTIME st; day.GetAsSystemTime (st); ::GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, strFormat, (LPTSTR)(LPCTSTR)strDate, _MAX_PATH); strDate.ReleaseBuffer (); CSize szSize (pDC->GetTextExtent (strDate)); if (rectDayCaption.Width () - 4 < szSize.cx) { strFormat = _T("d"); BOOL bNeedFormat = TRUE; if (bNewYear) { if (bDateBeforeMonth) { strFormat += _T(" MMM"); } else { strFormat = _T("MMM ") + strFormat; } bNeedFormat = FALSE; strDate.GetBuffer (_MAX_PATH); ::GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, strFormat, (LPTSTR)(LPCTSTR)strDate, _MAX_PATH); strDate.ReleaseBuffer (); szSize = pDC->GetTextExtent (strDate); if (rectDayCaption.Width () - 4 < szSize.cx) { strFormat = _T("d"); bNeedFormat = TRUE; } } if (bNeedFormat) { strDate.GetBuffer (_MAX_PATH); ::GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, strFormat, (LPTSTR)(LPCTSTR)strDate, _MAX_PATH); strDate.ReleaseBuffer (); } } } } if (bToday) { rectDayCaption.bottom--; } visualManager->PreparePlannerCaptionBackItem (FALSE); COLORREF clrText = OnFillPlannerCaption ( pDC, rectDayCaption, bToday, bSelected, FALSE); DrawCaptionText (pDC, rectDayCaption, strDate, clrText, bCompact ? DT_LEFT : DT_RIGHT, bToday && bSelected); day += COleDateTimeSpan (1, 0, 0, 0); } } if (hOldFont != NULL) { ::SelectObject (pDC->GetSafeHdc (), hOldFont); } }