https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e9f3790aa4f1a1a211c6dbbfa68c2e955fe7cda6

commit e9f3790aa4f1a1a211c6dbbfa68c2e955fe7cda6
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Sat Mar 18 08:24:19 2023 +0900
Commit:     Katayama Hirofumi MZ <[email protected]>
CommitDate: Sat Mar 18 08:24:19 2023 +0900

    [MSPAINT] Encapsulation: hNontranspIcon and hTranspIcon
    
    CORE-18867
---
 base/applications/mspaint/main.cpp         |  6 ------
 base/applications/mspaint/toolsettings.cpp | 17 +++++++++++++++--
 base/applications/mspaint/toolsettings.h   |  4 ++++
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/base/applications/mspaint/main.cpp 
b/base/applications/mspaint/main.cpp
index bd83e56a04a..2df191af3c8 100644
--- a/base/applications/mspaint/main.cpp
+++ b/base/applications/mspaint/main.cpp
@@ -192,12 +192,6 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE 
hPrevInstance, LPTSTR lpszArgument
     SetMenu(hwnd, menu);
     haccel = LoadAccelerators(hThisInstance, MAKEINTRESOURCE(800));
 
-    /* preloading the draw transparent/nontransparent icons for later use */
-    hNontranspIcon =
-        (HICON) LoadImage(hThisInstance, MAKEINTRESOURCE(IDI_NONTRANSPARENT), 
IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);
-    hTranspIcon =
-        (HICON) LoadImage(hThisInstance, MAKEINTRESOURCE(IDI_TRANSPARENT), 
IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);
-
     RECT toolBoxContainerPos = {2, 2, 2 + 52, 2 + 350};
     toolBoxContainer.Create(hwnd, toolBoxContainerPos, NULL, WS_CHILD | 
WS_VISIBLE);
     /* creating the tool settings child window */
diff --git a/base/applications/mspaint/toolsettings.cpp 
b/base/applications/mspaint/toolsettings.cpp
index 19f826ea825..dc1883bf47e 100644
--- a/base/applications/mspaint/toolsettings.cpp
+++ b/base/applications/mspaint/toolsettings.cpp
@@ -15,6 +15,12 @@
 
 LRESULT CToolSettingsWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, 
WINBOOL& bHandled)
 {
+    /* preloading the draw transparent/nontransparent icons for later use */
+    m_hNontranspIcon = (HICON)LoadImage(hProgInstance, 
MAKEINTRESOURCE(IDI_NONTRANSPARENT),
+                                        IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);
+    m_hTranspIcon = (HICON)LoadImage(hProgInstance, 
MAKEINTRESOURCE(IDI_TRANSPARENT),
+                                     IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);
+
     RECT trackbarZoomPos = {1, 1, 1 + 40, 1 + 64};
     trackbarZoom.Create(TRACKBAR_CLASS, m_hWnd, trackbarZoomPos, NULL, 
WS_CHILD | TBS_VERT | TBS_AUTOTICKS);
     trackbarZoom.SendMessage(TBM_SETRANGE, (WPARAM) TRUE, MAKELPARAM(0, 6));
@@ -22,6 +28,13 @@ LRESULT CToolSettingsWindow::OnCreate(UINT nMsg, WPARAM 
wParam, LPARAM lParam, W
     return 0;
 }
 
+LRESULT CToolSettingsWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM 
lParam, BOOL& bHandled)
+{
+    ::DestroyIcon(m_hNontranspIcon);
+    ::DestroyIcon(m_hTranspIcon);
+    return 0;
+}
+
 LRESULT CToolSettingsWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM 
lParam, BOOL& bHandled)
 {
     if (!zoomTo(125 << trackbarZoom.SendMessage(TBM_GETPOS, 0, 0), 0, 0))
@@ -50,8 +63,8 @@ LRESULT CToolSettingsWindow::OnPaint(UINT nMsg, WPARAM 
wParam, LPARAM lParam, BO
             SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
             Rectangle(hdc, 2, toolsModel.IsBackgroundTransparent() * 31 + 2, 
41, toolsModel.IsBackgroundTransparent() * 31 + 33);
             DeleteObject(SelectObject(hdc, oldPen));
-            DrawIconEx(hdc, 1, 2, hNontranspIcon, 40, 30, 0, NULL, DI_NORMAL);
-            DrawIconEx(hdc, 1, 33, hTranspIcon, 40, 30, 0, NULL, DI_NORMAL);
+            DrawIconEx(hdc, 1, 2, m_hNontranspIcon, 40, 30, 0, NULL, 
DI_NORMAL);
+            DrawIconEx(hdc, 1, 33, m_hTranspIcon, 40, 30, 0, NULL, DI_NORMAL);
             break;
         }
         case TOOL_RUBBER:
diff --git a/base/applications/mspaint/toolsettings.h 
b/base/applications/mspaint/toolsettings.h
index 4b06cb7960b..bd92d61a6ac 100644
--- a/base/applications/mspaint/toolsettings.h
+++ b/base/applications/mspaint/toolsettings.h
@@ -21,11 +21,15 @@ public:
         MESSAGE_HANDLER(WM_TOOLSMODELTOOLCHANGED, OnToolsModelToolChanged)
         MESSAGE_HANDLER(WM_TOOLSMODELSETTINGSCHANGED, 
OnToolsModelSettingsChanged)
         MESSAGE_HANDLER(WM_TOOLSMODELZOOMCHANGED, OnToolsModelZoomChanged)
+        MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
     END_MSG_MAP()
 
     CWindow trackbarZoom;
+    HICON m_hNontranspIcon;
+    HICON m_hTranspIcon;
 
     LRESULT OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& 
bHandled);

Reply via email to