From af4cbfe074b812035feb9e0fec3549f28384a626 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Sat, 25 Jun 2016 19:18:39 +0900 Subject: [PATCH] Use CClientDC class instead of CDC class --- Src/AboutDlg.cpp | 4 +--- Src/Common/BCMenu.cpp | 13 +++++-------- Src/Common/MDITabBar.cpp | 9 ++++----- Src/EditorFilepathBar.cpp | 9 ++++----- Src/LocationView.cpp | 9 ++++----- Src/Merge.cpp | 4 +--- Src/MergeEditView.cpp | 47 ++++++++++++++++++++--------------------------- 7 files changed, 39 insertions(+), 56 deletions(-) diff --git a/Src/AboutDlg.cpp b/Src/AboutDlg.cpp index 3d8d1a884..9844bc4a3 100644 --- a/Src/AboutDlg.cpp +++ b/Src/AboutDlg.cpp @@ -101,12 +101,10 @@ BOOL CAboutDlg::Impl::OnInitDialog() m_image.Load(IDR_SPLASH); - CDC *pDC = GetDC(); - int fontHeight = -MulDiv(10, pDC->GetDeviceCaps(LOGPIXELSY), 72); + const int fontHeight = -MulDiv(10, CClientDC(this).GetDeviceCaps(LOGPIXELSY), 72); m_font.CreateFont(fontHeight, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, _T("Tahoma")); - ReleaseDC(pDC); SetDlgItemText(IDC_STATIC, m_p->m_info.developers); GetDlgItem(IDC_STATIC)->SetFont(&m_font); diff --git a/Src/Common/BCMenu.cpp b/Src/Common/BCMenu.cpp index 383a377fb..b70ab7035 100644 --- a/Src/Common/BCMenu.cpp +++ b/Src/Common/BCMenu.cpp @@ -701,12 +701,10 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS ) m_fontMenu.CreateFontIndirect (&m_lf); // Obtain the width of the text: - CWnd *pWnd = AfxGetMainWnd(); // Get main window - if (pWnd == NULL) pWnd = CWnd::GetDesktopWindow(); - CDC *pDC = pWnd->GetDC(); // Get device context + CClientDC dc(AfxGetMainWnd() ? AfxGetMainWnd() : CWnd::GetDesktopWindow()); // Get device context CFont* pFont=NULL; // Select menu font in... - pFont = pDC->SelectObject (&m_fontMenu);// Select menu font in... + pFont = dc.SelectObject (&m_fontMenu);// Select menu font in... //Get pointer to text SK const wchar_t *lpstrText = ((BCMenuData*)(lpMIS->itemData))->GetWideString();//SK: we use const to prevent misuse @@ -714,13 +712,13 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS ) SIZE size; size.cx=size.cy=0; - VERIFY(::GetTextExtentPoint32W(pDC->m_hDC,lpstrText, + VERIFY(::GetTextExtentPoint32W(dc.m_hDC,lpstrText, lstrlenW(lpstrText),&size)); //SK should also work on 95 #ifndef UNICODE //can't be UNICODE for Win32s else{//it's Win32suckx RECT rect; rect.left=rect.top=0; - size.cy=DrawText(pDC->m_hDC,(LPCTSTR)lpstrText, + size.cy=DrawText(dc.>m_hDC,(LPCTSTR)lpstrText, wcslen(lpstrText),&rect, DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_CALCRECT); //+3 makes at least three pixels space to the menu border @@ -730,8 +728,7 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS ) #endif CSize t = CSize(size); - pDC->SelectObject (pFont); // Select old font in - pWnd->ReleaseDC(pDC); // Release the DC + dc.SelectObject (pFont); // Select old font in // Set width and height: diff --git a/Src/Common/MDITabBar.cpp b/Src/Common/MDITabBar.cpp index 559959bff..d9d618b40 100644 --- a/Src/Common/MDITabBar.cpp +++ b/Src/Common/MDITabBar.cpp @@ -75,11 +75,10 @@ CSize CMDITabBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz) return CSize(SHRT_MAX, 0); TEXTMETRIC tm; - CDC *pdc = GetDC(); - CFont *pOldFont = pdc->SelectObject(&m_font); - pdc->GetTextMetrics(&tm); - pdc->SelectObject(pOldFont); - ReleaseDC(pdc); + CClientDC dc(this); + CFont *pOldFont = dc.SelectObject(&m_font); + dc.GetTextMetrics(&tm); + dc.SelectObject(pOldFont); return CSize(SHRT_MAX, tm.tmHeight + 10); } diff --git a/Src/EditorFilepathBar.cpp b/Src/EditorFilepathBar.cpp index 15f1627fb..8db56e8dc 100644 --- a/Src/EditorFilepathBar.cpp +++ b/Src/EditorFilepathBar.cpp @@ -86,11 +86,10 @@ BOOL CEditorFilePathBar::Create(CWnd* pParentWnd) CSize CEditorFilePathBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz) { TEXTMETRIC tm; - CDC *pdc = GetDC(); - CFont *pOldFont = pdc->SelectObject(m_pFont.get()); - pdc->GetTextMetrics(&tm); - pdc->SelectObject(pOldFont); - ReleaseDC(pdc); + CClientDC dc(this); + CFont *pOldFont = dc.SelectObject(m_pFont.get()); + dc.GetTextMetrics(&tm); + dc.SelectObject(pOldFont); return CSize(SHRT_MAX, tm.tmHeight + 6); } diff --git a/Src/LocationView.cpp b/Src/LocationView.cpp index 7aec66bec..91e23c5ff 100644 --- a/Src/LocationView.cpp +++ b/Src/LocationView.cpp @@ -1001,16 +1001,15 @@ void CLocationView::UpdateVisiblePos(int nTopLine, int nBottomLine) if (m_visibleTop != nTopCoord || m_visibleBottom != nBottomCoord) { // Visible area was changed - CDC *pDC = GetDC(); if (m_pSavedBackgroundBitmap) { - CMyMemDC dc(pDC); + CClientDC dc(this); + CMyMemDC dcMem(&dc); // Clear previous visible rect - DrawBitmap(&dc, 0, 0, m_pSavedBackgroundBitmap.get()); + DrawBitmap(&dcMem, 0, 0, m_pSavedBackgroundBitmap.get()); - DrawVisibleAreaRect(&dc, nTopLine, nBottomLine); + DrawVisibleAreaRect(&dcMem, nTopLine, nBottomLine); } - ReleaseDC(pDC); } } else diff --git a/Src/Merge.cpp b/Src/Merge.cpp index fb3346b8b..f3449eff8 100644 --- a/Src/Merge.cpp +++ b/Src/Merge.cpp @@ -366,9 +366,7 @@ BOOL CMergeApp::InitInstance() NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS }; if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0)) { - HDC hdc = ::GetDC(NULL); - int lfHeight = -MulDiv(9, GetDeviceCaps(hdc, LOGPIXELSY), 72); - ::ReleaseDC(NULL, hdc); + const int lfHeight = -MulDiv(9, CClientDC(CWnd::GetDesktopWindow()).GetDeviceCaps(LOGPIXELSY), 72); if (abs(ncm.lfMenuFont.lfHeight) > abs(lfHeight)) ncm.lfMenuFont.lfHeight = lfHeight; if (wcscmp(ncm.lfMenuFont.lfFaceName, L"Meiryo") == 0 || wcscmp(ncm.lfMenuFont.lfFaceName, L"\U000030e1\U000030a4\U000030ea\U000030aa"/* "Meiryo" in Japanese */) == 0) diff --git a/Src/MergeEditView.cpp b/Src/MergeEditView.cpp index 1b74fa96c..bfd237233 100644 --- a/Src/MergeEditView.cpp +++ b/Src/MergeEditView.cpp @@ -3887,40 +3887,33 @@ void CMergeEditView::ZoomText(short amount) LOGFONT lf = { 0 }; GetFont(lf); - CDC* pDC = GetDC(); - ASSERT_VALID(pDC); - - if (pDC) - { - const int nLogPixelsY = pDC->GetDeviceCaps(LOGPIXELSY); + const int nLogPixelsY = CClientDC(this).GetDeviceCaps(LOGPIXELSY); + int nPointSize = -MulDiv(lf.lfHeight, 72, nLogPixelsY); - int nPointSize = -MulDiv(lf.lfHeight, 72, nLogPixelsY); - - if ( amount == 0) - { - nPointSize = -MulDiv(GetOptionsMgr()->GetInt(String(OPT_FONT_FILECMP) + OPT_FONT_HEIGHT), 72, nLogPixelsY); - } + if ( amount == 0) + { + nPointSize = -MulDiv(GetOptionsMgr()->GetInt(String(OPT_FONT_FILECMP) + OPT_FONT_HEIGHT), 72, nLogPixelsY); + } - nPointSize += amount; - if (nPointSize < 2) - nPointSize = 2; + nPointSize += amount; + if (nPointSize < 2) + nPointSize = 2; - lf.lfHeight = -MulDiv(nPointSize, nLogPixelsY, 72); + lf.lfHeight = -MulDiv(nPointSize, nLogPixelsY, 72); - CMergeDoc *pDoc = GetDocument(); - ASSERT(pDoc != NULL); + CMergeDoc *pDoc = GetDocument(); + ASSERT(pDoc != NULL); - if (pDoc != NULL ) + if (pDoc != NULL ) + { + for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++) { - for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++) + CMergeEditView *pView = GetGroupView(nPane); + ASSERT(pView != NULL); + + if (pView != NULL) { - CMergeEditView *pView = GetGroupView(nPane); - ASSERT(pView != NULL); - - if (pView != NULL) - { - pView->SetFont(lf); - } + pView->SetFont(lf); } } } -- 2.11.0