OSDN Git Service

Display WinMerge logo beautifully on HiDPI screen
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 7 Jul 2019 12:14:21 +0000 (21:14 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 7 Jul 2019 12:14:21 +0000 (21:14 +0900)
12 files changed:
Src/AboutDlg.cpp
Src/Common/Bitmap.cpp
Src/Common/Bitmap.h
Src/Common/Picture.cpp [deleted file]
Src/Common/Picture.h [deleted file]
Src/Merge.vs2017.vcxproj
Src/Merge.vs2017.vcxproj.filters
Src/Merge.vs2019.vcxproj
Src/Merge.vs2019.vcxproj.filters
Src/OpenView.cpp
Src/OpenView.h
Src/StdAfx.h

index 2050542..f43110b 100644 (file)
@@ -24,7 +24,7 @@
 #include "stdafx.h"
 #include "AboutDlg.h"
 #include "TrDialogs.h"
-#include "Picture.h"
+#include "Bitmap.h"
 #include "resource.h" // IDD_ABOUTBOX
 
 /** 
@@ -63,7 +63,7 @@ public:
 
 private:
        CAboutDlg *m_p;
-       CPicture m_image;
+       ATL::CImage m_image;
        CFont m_font;
 };
 
@@ -98,7 +98,7 @@ BOOL CAboutDlg::Impl::OnInitDialog()
 {
        CTrDialog::OnInitDialog();
 
-       m_image.Load(IDR_SPLASH);
+       LoadImageFromResource(m_image, MAKEINTRESOURCE(IDR_SPLASH), _T("IMAGE"));
 
        m_font.CreatePointFont(10 * 10, _T("Tahoma"));
 
@@ -131,7 +131,7 @@ void CAboutDlg::Impl::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
 {
        CRect rc;
        GetDlgItem(nIDCtl)->GetClientRect(&rc);
-       m_image.Render(CDC::FromHandle(lpDrawItemStruct->hDC), rc);
+       m_image.Draw(lpDrawItemStruct->hDC, rc, Gdiplus::InterpolationModeBicubic);
 }
 /**
  * @brief Show contributors list.
index 0ceefe3..9e6c718 100644 (file)
@@ -183,4 +183,26 @@ bool GrayScale(CBitmap *pBitmap)
        else
                return false;
        return pBitmap->SetBitmapBits(nCount, pbuf.get()) != 0;
+}
+
+bool LoadImageFromResource(ATL::CImage& image, const TCHAR *pName, const TCHAR *pType)
+{
+       HRSRC hrsrc = FindResource(nullptr, pName, pType);
+       if (hrsrc == nullptr)
+               return false;
+       DWORD dwResourceSize = SizeofResource(nullptr, hrsrc);
+       HGLOBAL hglbImage = LoadResource(nullptr, hrsrc);
+       if (hglbImage == nullptr)
+               return false;
+       LPVOID pvSourceResourceData = LockResource(hglbImage);
+       if (pvSourceResourceData == nullptr)
+               return false;
+       IStream * pStream = SHCreateMemStream(reinterpret_cast<const BYTE *>(pvSourceResourceData), dwResourceSize);
+       if (!pStream)
+               return false;
+       HRESULT hr = image.Load(pStream);
+       pStream->Release();
+       if (FAILED(hr))
+               return false;
+       return true;
 }
\ No newline at end of file
index cf15caf..ac16fc6 100644 (file)
@@ -9,8 +9,10 @@
 class CBitmap;
 class CDC;
 class CRect;
+namespace ATL { class CImage; }
 
 CBitmap *CopyRectToBitmap(CDC *pDC, const CRect & rect);
 void DrawBitmap(CDC *pDC, int x, int y, CBitmap *pBitmap);
 CBitmap *GetDarkenedBitmap(CDC *pDC, CBitmap *pBitmap);
 bool GrayScale(CBitmap *pBitmap);
+bool LoadImageFromResource(ATL::CImage& image, const TCHAR *pName, const TCHAR *pType);
diff --git a/Src/Common/Picture.cpp b/Src/Common/Picture.cpp
deleted file mode 100644 (file)
index 96026e5..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-////////////////////////////////////////////////////////////////
-// MSDN Magazine -- October 2001
-// If this code works, it was written by Paul DiLascia.
-// If not, I don't know who wrote it.
-// Compiles with Visual C++ 6.0 for Windows 98 and probably Windows 2000 too.
-// Set tabsize = 3 in your editor.
-//
-#include "StdAfx.h"
-#include "Picture.h"
-#include <afxpriv2.h>
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#endif
-
-////////////////////////////////////////////////////////////////
-// CPicture implementation
-//
-
-CPicture::CPicture() : m_hr(S_OK)
-{
-}
-
-CPicture::~CPicture()
-{
-}
-
-//////////////////
-// Load from resource. Looks for "IMAGE" type.
-//
-bool CPicture::Load(UINT nIDRes)
-{
-       // find resource in resource file
-       HINSTANCE hInst = AfxGetInstanceHandle();
-       HRSRC hRsrc = ::FindResource(hInst,
-               MAKEINTRESOURCE(nIDRes),
-               TEXT("IMAGE")); // type
-       if (hRsrc == nullptr)
-               return false;
-
-       // load resource into memory
-       DWORD len = SizeofResource(hInst, hRsrc);
-       BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
-       if (lpRsrc == nullptr)
-               return false;
-
-       // create memory file and load it
-       CMemFile file(lpRsrc, len);
-       bool bRet = Load(file);
-       FreeResource(hRsrc);
-
-       return bRet;
-}
-
-//////////////////
-// Load from path name.
-//
-bool CPicture::Load(LPCTSTR pszPathName)
-{
-       CFile file;
-       if (!file.Open(pszPathName, CFile::modeRead|CFile::shareDenyWrite))
-               return false;
-       bool bRet = Load(file);
-       file.Close();
-       return bRet;
-}
-
-//////////////////
-// Load from CFile
-//
-bool CPicture::Load(CFile& file)
-{
-       CArchive ar(&file, CArchive::load | CArchive::bNoFlushOnDelete);
-       return Load(ar);
-}
-
-//////////////////
-// Load from archive--create stream and load from stream.
-//
-// CArchiveStream Doesn't compile with VS2003.Net
-bool CPicture::Load(CArchive& ar)
-{
-       CArchiveStream arcstream(&ar);
-       return Load((IStream*)&arcstream);
-}
-
-
-//////////////////
-// Load from stream (IStream). This is the one that really does it: call
-// OleLoadPicture to do the work.
-//
-bool CPicture::Load(IStream* pstm)
-{
-       Free();
-       HRESULT hr = OleLoadPicture(pstm, 0, FALSE,
-               IID_IPicture, (void**)&m_spIPicture);
-       ASSERT(SUCCEEDED(hr) && m_spIPicture != nullptr);       
-       return true;
-}
-
-//////////////////
-// Render to device context. Covert to HIMETRIC for IPicture.
-//
-bool CPicture::Render(CDC* pDC, CRect rc /*= CRect(0,0,0,0)*/, LPCRECT prcMFBounds /*= nullptr*/) const
-{
-       ASSERT(pDC != nullptr);
-
-       if (rc.IsRectNull()) {
-               CSize sz = GetImageSize(pDC);
-               rc.right = sz.cx;
-               rc.bottom = sz.cy;
-       }
-       long hmWidth,hmHeight; // HIMETRIC units
-       GetHIMETRICSize(hmWidth, hmHeight);
-       m_spIPicture->Render(*pDC, rc.left, rc.top, rc.Width(), rc.Height(),
-               0, hmHeight, hmWidth, -hmHeight, prcMFBounds);
-
-       return true;
-}
-
-//////////////////
-// Get image size in pixels. Converts from HIMETRIC to device coords.
-//
-CSize CPicture::GetImageSize(CDC* pDC /*= nullptr*/) const
-{
-       if (m_spIPicture == nullptr)
-               return CSize(0,0);
-       
-       LONG hmWidth, hmHeight; // HIMETRIC units
-       if (FAILED(m_spIPicture->get_Width(&hmWidth)) || FAILED(m_spIPicture->get_Height(&hmHeight)))
-               return CSize(0, 0);
-       CSize sz(hmWidth,hmHeight);
-       if (pDC==nullptr) {
-               CWindowDC dc(nullptr);
-               dc.HIMETRICtoDP(&sz); // convert to pixels
-       } else {
-               pDC->HIMETRICtoDP(&sz);
-       }
-       return sz;
-}
-
diff --git a/Src/Common/Picture.h b/Src/Common/Picture.h
deleted file mode 100644 (file)
index 9387a70..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-////////////////////////////////////////////////////////////////
-// MSDN Magazine -- October 2001
-// If this code works, it was written by Paul DiLascia.
-// If not, I don't know who wrote it.
-// Compiles with Visual C++ 6.0 for Windows 98 and probably Windows 2000 too.
-// Set tabsize = 3 in your editor.
-//
-#pragma once
-#include <atlbase.h>
-
-//////////////////
-// Picture object--encapsulates IPicture
-//
-class CPicture {
-public:
-       CPicture();
-       ~CPicture();
-
-       // Load frm various sosurces
-       bool Load(UINT nIDRes);
-       bool Load(LPCTSTR pszPathName);
-       bool Load(CFile& file);
-       bool Load(CArchive& ar);
-       bool Load(IStream* pstm);
-
-       // render to device context
-       bool Render(CDC* pDC, CRect rc=CRect(0,0,0,0),
-               LPCRECT prcMFBounds=nullptr) const;
-
-       CSize GetImageSize(CDC* pDC=nullptr) const;
-
-       operator IPicture*() {
-               return m_spIPicture;
-       }
-
-       void GetHIMETRICSize(OLE_XSIZE_HIMETRIC& cx, OLE_YSIZE_HIMETRIC& cy) const {
-               cx = cy = 0;
-               const_cast<CPicture*>(this)->m_hr = m_spIPicture->get_Width(&cx);
-               ASSERT(SUCCEEDED(m_hr));
-               const_cast<CPicture*>(this)->m_hr = m_spIPicture->get_Height(&cy);
-               ASSERT(SUCCEEDED(m_hr));
-       }
-
-       void Free() {
-               if (m_spIPicture) {
-                       m_spIPicture.Release();
-               }
-       }
-
-protected:
-       CComQIPtr<IPicture>m_spIPicture;                 // ATL smart pointer to IPicture
-       HRESULT m_hr;                                                            // last error code
-};
index 68dc2d5..72377cf 100644 (file)
       <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderOutputFile>$(IntDir)$(TargetName)2.pch</PrecompiledHeaderOutputFile>\r
     </ClCompile>\r
-    <ClCompile Include="Common\Picture.cpp" />\r
     <ClCompile Include="Common\PidlContainer.cpp">\r
       <PrecompiledHeader>Use</PrecompiledHeader>\r
       <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>\r
     <ClInclude Include="PatchTool.h" />\r
     <ClInclude Include="PathContext.h" />\r
     <ClInclude Include="paths.h" />\r
-    <ClInclude Include="Common\Picture.h" />\r
     <ClInclude Include="Common\PidlContainer.h" />\r
     <ClInclude Include="pch.h" />\r
     <ClInclude Include="PluginManager.h" />\r
       <UserProperties RESOURCE_FILE="Merge.rc" />\r
     </VisualStudio>\r
   </ProjectExtensions>\r
-</Project>\r
+</Project>
\ No newline at end of file
index 3050bff..e8338f6 100644 (file)
     <ClCompile Include="Common\MessageBoxDialog.cpp">\r
       <Filter>MFCGui\Common\Source Files</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="Common\Picture.cpp">\r
-      <Filter>MFCGui\Common\Source Files</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="Common\PropertyPageHost.cpp">\r
       <Filter>MFCGui\Common\Source Files</Filter>\r
     </ClCompile>\r
     <ClInclude Include="Common\MessageBoxDialog.h">\r
       <Filter>MFCGui\Common\Header Files</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="Common\Picture.h">\r
-      <Filter>MFCGui\Common\Header Files</Filter>\r
-    </ClInclude>\r
     <ClInclude Include="Common\scbarcf.h">\r
       <Filter>MFCGui\Common\Header Files</Filter>\r
     </ClInclude>\r
index 31ff9c5..583d6f4 100644 (file)
       <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderOutputFile>$(IntDir)$(TargetName)2.pch</PrecompiledHeaderOutputFile>\r
     </ClCompile>\r
-    <ClCompile Include="Common\Picture.cpp" />\r
     <ClCompile Include="Common\PidlContainer.cpp">\r
       <PrecompiledHeader>Use</PrecompiledHeader>\r
       <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>\r
     <ClInclude Include="PatchTool.h" />\r
     <ClInclude Include="PathContext.h" />\r
     <ClInclude Include="paths.h" />\r
-    <ClInclude Include="Common\Picture.h" />\r
     <ClInclude Include="Common\PidlContainer.h" />\r
     <ClInclude Include="pch.h" />\r
     <ClInclude Include="PluginManager.h" />\r
index 3050bff..e8338f6 100644 (file)
     <ClCompile Include="Common\MessageBoxDialog.cpp">\r
       <Filter>MFCGui\Common\Source Files</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="Common\Picture.cpp">\r
-      <Filter>MFCGui\Common\Source Files</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="Common\PropertyPageHost.cpp">\r
       <Filter>MFCGui\Common\Source Files</Filter>\r
     </ClCompile>\r
     <ClInclude Include="Common\MessageBoxDialog.h">\r
       <Filter>MFCGui\Common\Header Files</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="Common\Picture.h">\r
-      <Filter>MFCGui\Common\Header Files</Filter>\r
-    </ClInclude>\r
     <ClInclude Include="Common\scbarcf.h">\r
       <Filter>MFCGui\Common\Header Files</Filter>\r
     </ClInclude>\r
index ce95200..eff5f54 100644 (file)
@@ -40,7 +40,7 @@
 #include "FileOrFolderSelect.h"
 #include "7zCommon.h"
 #include "Constants.h"
-#include "Picture.h"
+#include "Bitmap.h"
 #include "DropHandler.h"
 #include "FileFilterHelper.h"
 #include "Plugins.h"
@@ -177,7 +177,7 @@ void COpenView::OnInitialUpdate()
 
        theApp.TranslateDialog(m_hWnd);
 
-       if (!m_picture.Load(IDR_LOGO))
+       if (!LoadImageFromResource(m_image, MAKEINTRESOURCE(IDR_LOGO), _T("IMAGE")))
                return;
 
        CFormView::OnInitialUpdate();
@@ -319,9 +319,9 @@ void COpenView::OnPaint()
        GetClientRect(&rc);
 
        // Draw the logo image
-       CSize size = m_picture.GetImageSize(&dc);
+       CSize size{ m_image.GetWidth(), m_image.GetHeight() };
        CRect rcImage(0, 0, size.cx * GetSystemMetrics(SM_CXSMICON) / 16, size.cy * GetSystemMetrics(SM_CYSMICON) / 16);
-       m_picture.Render(&dc, rcImage);
+       m_image.Draw(dc.m_hDC, rcImage, Gdiplus::InterpolationModeBicubic);
        // And extend it to the Right boundary
     dc.PatBlt(rcImage.Width(), 0, rc.Width() - rcImage.Width(), rcImage.Height(), PATCOPY);
 
index be3504a..7a1f5d5 100644 (file)
@@ -31,7 +31,6 @@
 #include "SuperComboBox.h"
 #include "FileTransform.h"
 #include "PathContext.h"
-#include "Picture.h"
 #include "CMoveConstraint.h"
 #include "TrDialogs.h"
 #include <array>
@@ -87,7 +86,7 @@ public:
 private:
        String m_strBrowsePath[3]; /**< Left/middle/right path from browse dialog. */
        CWinThread *m_pUpdateButtonStatusThread;
-       CPicture m_picture; /**< Image loader/viewer for logo image */
+       ATL::CImage m_image; /**< Image loader/viewer for logo image */
        CSize m_sizeOrig;
        prdlg::CMoveConstraint m_constraint;
        CFont m_fontSwapButton;
index c125b13..09fcabc 100644 (file)
@@ -37,6 +37,8 @@
 #include <afxpriv.h>        // MFC private declarations (crystal text needs but doesn't include this)
 #include <afxole.h>         // MFC OLE (COM) support
 
+#include <atlimage.h>
+
 // For CSizingControlBar
 #include "sizecbar.h"
 #include "scbarg.h"