https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b2f8d62cd1a116fb2cad2…
commit b2f8d62cd1a116fb2cad2af889e9c6651e942e42
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Mon Jan 10 08:50:37 2022 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Mon Jan 10 08:50:37 2022 +0900
[MSPAINT] Prepare for debugging (#4257)
- Add #include <debug.h> and add link to ntdll.dll for debugging.
- Add CopyDIBImage helper function.
CORE-17969
---
base/applications/mspaint/CMakeLists.txt | 2 +-
base/applications/mspaint/dib.h | 5 +++++
base/applications/mspaint/history.cpp | 15 +++++++++------
base/applications/mspaint/precomp.h | 3 +++
base/applications/mspaint/selectionmodel.cpp | 5 ++---
base/applications/mspaint/winproc.cpp | 4 ++--
6 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/base/applications/mspaint/CMakeLists.txt
b/base/applications/mspaint/CMakeLists.txt
index fcf694a08ca..03c71c21359 100644
--- a/base/applications/mspaint/CMakeLists.txt
+++ b/base/applications/mspaint/CMakeLists.txt
@@ -32,6 +32,6 @@ add_executable(mspaint ${SOURCE} rsrc.rc)
set_module_type(mspaint win32gui UNICODE)
target_link_libraries(mspaint uuid cpprt atl_classes)
set_target_cpp_properties(mspaint WITH_EXCEPTIONS)
-add_importlibs(mspaint hhctrl comdlg32 shell32 user32 gdi32 advapi32 comctl32 msvcrt
kernel32 rpcrt4 shlwapi)
+add_importlibs(mspaint hhctrl comdlg32 shell32 user32 gdi32 advapi32 comctl32 msvcrt
kernel32 rpcrt4 shlwapi ntdll)
add_pch(mspaint precomp.h SOURCE)
add_cd_file(TARGET mspaint DESTINATION reactos/system32 FOR all)
diff --git a/base/applications/mspaint/dib.h b/base/applications/mspaint/dib.h
index 6bbb56d9c6d..21c73a7dd13 100644
--- a/base/applications/mspaint/dib.h
+++ b/base/applications/mspaint/dib.h
@@ -11,6 +11,11 @@
HBITMAP CreateDIBWithProperties(int width, int height);
HBITMAP CreateColorDIB(int width, int height, COLORREF rgb);
+static inline HBITMAP CopyDIBImage(HBITMAP hbm, INT cx = 0, INT cy = 0)
+{
+ return (HBITMAP)CopyImage(hbm, IMAGE_BITMAP, cx, cy, LR_COPYRETURNORG |
LR_CREATEDIBSECTION);
+}
+
int GetDIBWidth(HBITMAP hbm);
int GetDIBHeight(HBITMAP hbm);
diff --git a/base/applications/mspaint/history.cpp
b/base/applications/mspaint/history.cpp
index 221dffc52d7..1a5cd8966a8 100644
--- a/base/applications/mspaint/history.cpp
+++ b/base/applications/mspaint/history.cpp
@@ -44,8 +44,9 @@ ImageModel::ImageModel()
void ImageModel::CopyPrevious()
{
+ DPRINT("%s: %d\n", __FUNCTION__, currInd);
DeleteObject(hBms[(currInd + 1) % HISTORYSIZE]);
- hBms[(currInd + 1) % HISTORYSIZE] = (HBITMAP) CopyImage(hBms[currInd], IMAGE_BITMAP,
0, 0, LR_COPYRETURNORG);
+ hBms[(currInd + 1) % HISTORYSIZE] = CopyDIBImage(hBms[currInd]);
currInd = (currInd + 1) % HISTORYSIZE;
if (undoSteps < HISTORYSIZE - 1)
undoSteps++;
@@ -56,6 +57,7 @@ void ImageModel::CopyPrevious()
void ImageModel::Undo()
{
+ DPRINT("%s: %d\n", __FUNCTION__, undoSteps);
if (undoSteps > 0)
{
int oldWidth = GetWidth();
@@ -74,6 +76,7 @@ void ImageModel::Undo()
void ImageModel::Redo()
{
+ DPRINT("%s: %d\n", __FUNCTION__, redoSteps);
if (redoSteps > 0)
{
int oldWidth = GetWidth();
@@ -92,9 +95,9 @@ void ImageModel::Redo()
void ImageModel::ResetToPrevious()
{
+ DPRINT("%s: %d\n", __FUNCTION__, currInd);
DeleteObject(hBms[currInd]);
- hBms[currInd] =
- (HBITMAP) CopyImage(hBms[(currInd + HISTORYSIZE - 1) % HISTORYSIZE],
IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
+ hBms[currInd] = CopyDIBImage(hBms[(currInd + HISTORYSIZE - 1) % HISTORYSIZE]);
SelectObject(hDrawingDC, hBms[currInd]);
NotifyImageChanged();
}
@@ -183,9 +186,9 @@ void ImageModel::StretchSkew(int nStretchPercentX, int
nStretchPercentY, int nSk
{
int oldWidth = GetWidth();
int oldHeight = GetHeight();
- Insert((HBITMAP) CopyImage(hBms[currInd], IMAGE_BITMAP,
- GetWidth() * nStretchPercentX / 100,
- GetHeight() * nStretchPercentY / 100, 0));
+ INT newWidth = oldWidth * nStretchPercentX / 100;
+ INT newHeight = oldHeight * nStretchPercentY / 100;
+ Insert(CopyDIBImage(hBms[currInd], newWidth, newHeight));
if (GetWidth() != oldWidth || GetHeight() != oldHeight)
NotifyDimensionsChanged();
NotifyImageChanged();
diff --git a/base/applications/mspaint/precomp.h b/base/applications/mspaint/precomp.h
index 5e2756b2fa1..1f27501432f 100644
--- a/base/applications/mspaint/precomp.h
+++ b/base/applications/mspaint/precomp.h
@@ -21,6 +21,9 @@
#include <shellapi.h>
#include <htmlhelp.h>
+#define NDEBUG
+#include <debug.h>
+
#define WM_TOOLSMODELTOOLCHANGED (WM_APP + 0)
#define WM_TOOLSMODELSETTINGSCHANGED (WM_APP + 1)
#define WM_TOOLSMODELZOOMCHANGED (WM_APP + 2)
diff --git a/base/applications/mspaint/selectionmodel.cpp
b/base/applications/mspaint/selectionmodel.cpp
index 464b6bdca64..50c6ad4a53f 100644
--- a/base/applications/mspaint/selectionmodel.cpp
+++ b/base/applications/mspaint/selectionmodel.cpp
@@ -170,9 +170,8 @@ void SelectionModel::InsertFromHBITMAP(HBITMAP hBm)
HDC hTempDC;
HBITMAP hTempMask;
- DeleteObject(SelectObject(m_hDC, m_hBm = (HBITMAP) CopyImage(hBm,
- IMAGE_BITMAP, 0, 0,
- LR_COPYRETURNORG)));
+ m_hBm = CopyDIBImage(hBm);
+ DeleteObject(SelectObject(m_hDC, m_hBm));
SetRectEmpty(&m_rcSrc);
m_rcDest.left = m_rcDest.top = 0;
diff --git a/base/applications/mspaint/winproc.cpp
b/base/applications/mspaint/winproc.cpp
index 7a739f76cca..43b0f812c1f 100644
--- a/base/applications/mspaint/winproc.cpp
+++ b/base/applications/mspaint/winproc.cpp
@@ -534,7 +534,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
case IDM_EDITCOPY:
OpenClipboard();
EmptyClipboard();
- SetClipboardData(CF_BITMAP, CopyImage(selectionModel.GetBitmap(),
IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
+ SetClipboardData(CF_BITMAP, CopyDIBImage(selectionModel.GetBitmap()));
CloseClipboard();
break;
case IDM_EDITCUT:
@@ -653,7 +653,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent());
break;
case IDM_IMAGECROP:
- imageModel.Insert((HBITMAP) CopyImage(selectionModel.GetBitmap(),
IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
+ imageModel.Insert(CopyDIBImage(selectionModel.GetBitmap()));
break;
case IDM_VIEWTOOLBOX: