OSDN Git Service

PATCH: [ 1447806 ] Use JPEG splashscreen
authorKimmo Varis <kimmov@gmail.com>
Sat, 11 Mar 2006 20:46:16 +0000 (20:46 +0000)
committerKimmo Varis <kimmov@gmail.com>
Sat, 11 Mar 2006 20:46:16 +0000 (20:46 +0000)
31 files changed:
Src/Changes.txt
Src/Common/Picture.cpp [new file with mode: 0644]
Src/Common/Picture.h [new file with mode: 0644]
Src/Languages/Brazilian/MergeBrazilian.rc
Src/Languages/Bulgarian/MergeBulgarian.rc
Src/Languages/Catalan/MergeCatalan.rc
Src/Languages/ChineseSimplified/MergeChineseSimplified.rc
Src/Languages/ChineseTraditional/MergeChineseTraditional.rc
Src/Languages/Czech/MergeCzech.rc
Src/Languages/Danish/MergeDanish.rc
Src/Languages/Dutch/MergeDutch.rc
Src/Languages/French/MergeFrench.rc
Src/Languages/German/MergeGerman.rc
Src/Languages/Hungarian/MergeHungarian.rc
Src/Languages/Italian/MergeItalian.rc
Src/Languages/Japanese/MergeJapanese.rc
Src/Languages/Korean/MergeKorean.rc
Src/Languages/Norwegian/MergeNorwegian.rc
Src/Languages/Polish/MergePolish.rc
Src/Languages/Russian/MergeRussian.rc
Src/Languages/Slovak/MergeSlovak.rc
Src/Languages/Spanish/MergeSpanish.rc
Src/Languages/Swedish/MergeSwedish.rc
Src/Languages/Turkish/MergeTurkish.rc
Src/Merge.dsp
Src/Merge.rc
Src/Splash.cpp
Src/Splash.h
Src/res/splash.jpg [new file with mode: 0644]
Src/res/splash1.bmp [deleted file]
Src/resource.h

index dcdcfe7..654e852 100644 (file)
@@ -21,6 +21,12 @@ Add new items to top.
   Docs/Users: Contributors.txt
  PATCH: [ 1447348 ] Build language files to Build directory
   Src/Languages: BuildDll.bat
+ PATCH: [ 1447806 ] Use JPEG splashscreen
+  Src: Merge.dsp Merge.rc resource.h Splash.cpp Splash.h
+  Src/Common new files: Picture.cpp Picture.h
+  Src/res new file: splash.jpg
+  Src/res deleted file: splash1.bmp
+  Src/Languages/*: Merge*.rc
 
 2006-03-11 Takashi
  BUG:  [ 1441389 ] Comparing root directory - mysterious
diff --git a/Src/Common/Picture.cpp b/Src/Common/Picture.cpp
new file mode 100644 (file)
index 0000000..95d148b
--- /dev/null
@@ -0,0 +1,143 @@
+////////////////////////////////////////////////////////////////
+// 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 <afxpriv2.h>
+#include "Picture.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+////////////////////////////////////////////////////////////////
+// CPicture implementation
+//
+
+CPicture::CPicture()
+{
+}
+
+CPicture::~CPicture()
+{
+}
+
+//////////////////
+// Load from resource. Looks for "IMAGE" type.
+//
+BOOL CPicture::Load(UINT nIDRes)
+{
+       // find resource in resource file
+       HINSTANCE hInst = AfxGetResourceHandle();
+       HRSRC hRsrc = ::FindResource(hInst,
+               MAKEINTRESOURCE(nIDRes),
+               TEXT("IMAGE")); // type
+       if (!hRsrc)
+               return FALSE;
+
+       // load resource into memory
+       DWORD len = SizeofResource(hInst, hRsrc);
+       BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
+       if (!lpRsrc)
+               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);  
+       return TRUE;
+}
+
+//////////////////
+// Render to device context. Covert to HIMETRIC for IPicture.
+//
+BOOL CPicture::Render(CDC* pDC, CRect rc, LPCRECT prcMFBounds) const
+{
+       ASSERT(pDC);
+
+       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) const
+{
+       if (!m_spIPicture)
+               return CSize(0,0);
+       
+       LONG hmWidth, hmHeight; // HIMETRIC units
+       m_spIPicture->get_Width(&hmWidth);
+       m_spIPicture->get_Height(&hmHeight);
+       CSize sz(hmWidth,hmHeight);
+       if (pDC==NULL) {
+               CWindowDC dc(NULL);
+               dc.HIMETRICtoDP(&sz); // convert to pixels
+       } else {
+               pDC->HIMETRICtoDP(&sz);
+       }
+       return sz;
+}
+
diff --git a/Src/Common/Picture.h b/Src/Common/Picture.h
new file mode 100644 (file)
index 0000000..6a5adba
--- /dev/null
@@ -0,0 +1,53 @@
+////////////////////////////////////////////////////////////////
+// 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=NULL) const;
+
+       CSize GetImageSize(CDC* pDC=NULL) 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 6eed6a5..b3fe2e7 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 33251e5..6adb298 100644 (file)
@@ -1609,6 +1609,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 34f32fc..0d94f7c 100644 (file)
@@ -1609,6 +1609,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 6620055..fe79ebf 100644 (file)
@@ -1593,6 +1593,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 5f13e10..c34b868 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 5026905..229fbd9 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index f6cfb75..dfe3df2 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 8fa1dd6..0c3cf09 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index d974564..35be56d 100644 (file)
@@ -1558,6 +1558,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index e0f499e..a25f253 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 05de261..6506485 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 1101a40..94ea41a 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index f0f2b4a..89a0a94 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index e2874ce..b737c42 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index a757fcf..a4fc890 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index d0129e2..99545c1 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 242b60b..b68d5c0 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 9d6b881..4da1dfb 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 641d9a5..063852c 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 9d74bde..dc431e1 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index d1a6d40..12471a2 100644 (file)
@@ -1591,6 +1591,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "..\\..\\res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
index 5f30ef0..17187d4 100644 (file)
@@ -627,6 +627,10 @@ SOURCE=.\paths.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\Common\Picture.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\PluginManager.cpp
 # End Source File
 # Begin Source File
@@ -704,7 +708,6 @@ SOURCE=.\PropTextColors.cpp
 # End Source File
 # Begin Source File
 
-
 SOURCE=.\PropVss.cpp
 
 !IF  "$(CFG)" == "Merge - Win32 Debug"
@@ -1266,6 +1269,10 @@ SOURCE=.\paths.h
 # End Source File
 # Begin Source File
 
+SOURCE=.\Common\Picture.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\PluginManager.h
 # End Source File
 # Begin Source File
index 53d04b0..9d405ae 100644 (file)
@@ -1591,11 +1591,17 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// Image
+//
+IDR_SPLASH              IMAGE                   "res\\splash.jpg"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // Bitmap
 //
 
 IDR_MAINFRAME           BITMAP                  "res\\Toolbar.bmp"
-IDB_SPLASH              BITMAP                  "res\\splash1.bmp"
 IDB_EDIT_COPY           BITMAP                  "res\\copy.bmp"
 IDB_EDIT_CUT            BITMAP                  "res\\cut.bmp"
 IDB_EDIT_PASTE          BITMAP                  "res\\paste.bmp"
index 44c1d10..0dc4288 100644 (file)
@@ -30,6 +30,7 @@
 #include "stdafx.h"
 #include "resource.h"
 
+#include "Picture.h"
 #include "Splash.h"
 #include "version.h"
 
@@ -69,6 +70,7 @@ CSplashWnd* CSplashWnd::c_pSplashWnd;
  * @brief Default constructor.
  */
 CSplashWnd::CSplashWnd()
+ : m_pPicture(NULL)
 {
 }
 
@@ -140,26 +142,35 @@ BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
 }
 
 /** 
- * @brief Loads splashscreen bitmap
+ * @brief Loads splashscreen image.
+ * Loads splashscreen image from resource and creates window with same size.
  */
 BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
 {
-       if (!m_bitmap.LoadBitmap(IDB_SPLASH))
+       if (m_pPicture == NULL)
+               m_pPicture = new CPicture();
+
+       if (m_pPicture == NULL)
+               return FALSE;
+
+       if (!m_pPicture->Load(IDR_SPLASH))
                return FALSE;
 
-       BITMAP bm;
-       m_bitmap.GetBitmap(&bm);
+       CSize imgSize = m_pPicture->GetImageSize();
 
        return CreateEx(0,
                AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
-               NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL);
+               NULL, WS_POPUP | WS_VISIBLE, 0, 0, imgSize.cx, imgSize.cy, pParentWnd->GetSafeHwnd(), NULL);
 }
 
 /** 
- * @brief Destroy the window, and update the mainframe.
+ * @brief Destroy the window and splash image then update the mainframe.
  */
 void CSplashWnd::HideSplashScreen()
 {
+       m_pPicture->Free();
+       delete m_pPicture;
+       m_pPicture = NULL;
        DestroyWindow();
        AfxGetMainWnd()->UpdateWindow();
 }
@@ -190,23 +201,14 @@ int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
 }
 
 /** 
- * @brief Add version text to bitmap.
+ * @brief Paint splashscreen.
+ * Draws image to window size (which is already set to image size).
+ * Then adds texts over image.
  */
 void CSplashWnd::OnPaint()
 {
        CPaintDC dc(this);
-
-       CDC dcImage;
-       if (!dcImage.CreateCompatibleDC(&dc))
-               return;
-
-       BITMAP bm;
-       m_bitmap.GetBitmap(&bm);
-
-       // Paint the image.
-       CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
-       dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
-       dcImage.SelectObject(pOldBitmap);
+       m_pPicture->Render(&dc);
 
        CVersionInfo version;
        CString s;
index 35461c0..8e03a9e 100644 (file)
@@ -18,7 +18,7 @@
 //
 /////////////////////////////////////////////////////////////////////////////
 /**
- * @file  Splash.h
+ * @file  Src/Splash.h
  *
  * @brief Declaration file for CSplashWnd
  *
 #ifndef _SPLASH_SCRN_
 #define _SPLASH_SCRN_
 
-/////////////////////////////////////////////////////////////////////////////
-//   Splash Screen class
+class CPicture;
 
+/**
+ * @brief Splash screen class.
+ * Loads image from resource and shows it as a splash screen
+ * at program startup.
+ */
 class CSplashWnd : public CWnd
 {
 // Construction
@@ -39,8 +43,8 @@ protected:
        CSplashWnd();
 
 // Attributes:
-public:
-       CBitmap m_bitmap;
+private:
+       CPicture * m_pPicture; /**< Image loader/viewer for splash image */
 
 // Operations
 public:
diff --git a/Src/res/splash.jpg b/Src/res/splash.jpg
new file mode 100644 (file)
index 0000000..b566208
Binary files /dev/null and b/Src/res/splash.jpg differ
diff --git a/Src/res/splash1.bmp b/Src/res/splash1.bmp
deleted file mode 100644 (file)
index 6362945..0000000
Binary files a/Src/res/splash1.bmp and /dev/null differ
index 49d84be..9133b55 100644 (file)
@@ -49,7 +49,7 @@
 #define IDD_LOAD_SAVE_CODEPAGE          230
 #define IDD_TEST_FILTER                 231
 #define IDD_PROPPAGE_COLORS_TEXT        232
-#define IDB_SPLASH                      308
+#define IDR_SPLASH                      308
 #define IDB_WINMERGE                    309
 #define IDB_OLDSPLASH                   310
 #define IDB_EDIT_COPY                   316