[MSPAINT][ATL] Encapsulation: mainWindow (#5178)

- Add DoCreate methods to CFullscreenWindow, CMiniatureWindow, and CMainWindow classes.
- Do encapsulation around mainWindow and _tWinMain.
- Add GetOpenFileName, GetSaveFileName, and ChooseColor helper methods to CMainWindow class.
- Move some code in WinMain into CMainWindow::OnCreate.
- Delay creation of CFullscreenWindow and CMiniatureWindow.
- Extend ATL CImage class as CImageDx in newly-created atlimagedx.h of mspaint.
CORE-18867
This commit is contained in:
Katayama Hirofumi MZ 2023-03-28 22:31:26 +09:00 committed by GitHub
parent 0569bbd4a7
commit 29e147beca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 549 additions and 360 deletions

View file

@ -6,13 +6,22 @@
* PROGRAMMERS: Benedikt Freisen
*/
/* INCLUDES *********************************************************/
#include "precomp.h"
#include <math.h>
INT fileSize = 0;
float g_xDpi = 96;
float g_yDpi = 96;
SYSTEMTIME fileTime;
/* FUNCTIONS ********************************************************/
// Convert DPI (dots per inch) into PPM (pixels per meter)
float PpmFromDpi(float dpi)
{
return dpi / 0.0254; // 1 DPI is 0.0254 meter.
}
HBITMAP
CreateDIBWithProperties(int width, int height)
{
@ -68,9 +77,9 @@ GetDIBHeight(HBITMAP hBitmap)
BOOL SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC)
{
CImage img;
CImageDx img;
img.Attach(hBitmap);
img.Save(FileName); // TODO: error handling
img.SaveDx(FileName, GUID_NULL, g_xDpi, g_yDpi); // TODO: error handling
img.Detach();
WIN32_FIND_DATA find;
@ -116,16 +125,12 @@ HBITMAP SetBitmapAndInfo(HBITMAP hBitmap, LPCTSTR name, DWORD dwFileSize, BOOL i
if (hBitmap == NULL)
return FALSE;
fileHPPM = fileVPPM = 2834;
ZeroMemory(&fileTime, sizeof(fileTime));
}
else
{
// update PPMs
HDC hScreenDC = GetDC(NULL);
fileHPPM = (int)(GetDeviceCaps(hScreenDC, LOGPIXELSX) * 1000 / 25.4);
fileVPPM = (int)(GetDeviceCaps(hScreenDC, LOGPIXELSY) * 1000 / 25.4);
g_xDpi = GetDeviceCaps(hScreenDC, LOGPIXELSX);
g_yDpi = GetDeviceCaps(hScreenDC, LOGPIXELSY);
ReleaseDC(NULL, hScreenDC);
ZeroMemory(&fileTime, sizeof(fileTime));
}
// update image
@ -185,8 +190,14 @@ HBITMAP DoLoadImageFile(HWND hwnd, LPCTSTR name, BOOL fIsMainFile)
}
// load the image
CImage img;
img.Load(name);
CImageDx img;
img.LoadDx(name, &g_xDpi, &g_yDpi);
if (g_xDpi <= 0)
g_xDpi = 96;
if (g_yDpi <= 0)
g_yDpi = 96;
HBITMAP hBitmap = img.Detach();
if (hBitmap == NULL)