https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5ed7db5acbb645f4d0844…
commit 5ed7db5acbb645f4d08449a003ac62a4c5d907d9
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sat Mar 18 17:12:28 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Mar 18 17:12:28 2023 +0900
[MSPAINT] Save paletteWindow visibility (#5167)
According to my registry analysis,
HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\General-Bar4:Visible is the
target value.
- Improve ReadDWORD helper function.
- Add ShowPalette registry setting.
- Simplify RegistrySettings::Load and RegistrySettings::Store.
CORE-18867
---
base/applications/mspaint/main.cpp | 4 +-
base/applications/mspaint/registry.cpp | 85 ++++++++++++++++++++--------------
base/applications/mspaint/registry.h | 1 +
base/applications/mspaint/winproc.cpp | 3 +-
4 files changed, 57 insertions(+), 36 deletions(-)
diff --git a/base/applications/mspaint/main.cpp b/base/applications/mspaint/main.cpp
index 2df191af3c8..75e80757a39 100644
--- a/base/applications/mspaint/main.cpp
+++ b/base/applications/mspaint/main.cpp
@@ -200,7 +200,9 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR
lpszArgument
/* creating the palette child window */
RECT paletteWindowPos = {56, 9, 56 + 255, 9 + 32};
- paletteWindow.Create(hwnd, paletteWindowPos, NULL, WS_CHILD | WS_VISIBLE,
WS_EX_STATICEDGE);
+ paletteWindow.Create(hwnd, paletteWindowPos, NULL, WS_CHILD, WS_EX_STATICEDGE);
+ if (registrySettings.ShowPalette)
+ paletteWindow.ShowWindow(SW_SHOWNOACTIVATE);
// creating the canvas
RECT canvasWindowPos = {0, 0, 0 + 500, 0 + 500};
diff --git a/base/applications/mspaint/registry.cpp
b/base/applications/mspaint/registry.cpp
index 46119989429..f23ce12e8f4 100644
--- a/base/applications/mspaint/registry.cpp
+++ b/base/applications/mspaint/registry.cpp
@@ -15,14 +15,11 @@
#include <shlobj.h>
/* FUNCTIONS ********************************************************/
-static DWORD ReadDWORD(CRegKey &key, LPCTSTR lpName, DWORD &dwValue, BOOL
bCheckForDef)
+static void ReadDWORD(CRegKey &key, LPCTSTR lpName, DWORD &dwValue)
{
- DWORD dwPrev = dwValue;
-
- if (key.QueryDWORDValue(lpName, dwValue) != ERROR_SUCCESS || (bCheckForDef &&
dwValue == 0))
- dwValue = dwPrev;
-
- return dwPrev;
+ DWORD dwTemp;
+ if (key.QueryDWORDValue(lpName, dwTemp) == ERROR_SUCCESS)
+ dwValue = dwTemp;
}
static void ReadString(CRegKey &key, LPCTSTR lpName, CString &strValue, LPCTSTR
lpDefault = TEXT(""))
@@ -75,6 +72,7 @@ void RegistrySettings::LoadPresets(INT nCmdShow)
FontsPositionY = 0;
ShowTextTool = TRUE;
ShowStatusBar = TRUE;
+ ShowPalette = TRUE;
LOGFONT lf;
GetObject(GetStockObject(DEFAULT_GUI_FONT), sizeof(lf), &lf);
@@ -92,28 +90,32 @@ void RegistrySettings::Load(INT nCmdShow)
{
LoadPresets(nCmdShow);
+ CRegKey paint;
+ if (paint.Open(HKEY_CURRENT_USER,
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint"), KEY_READ) !=
ERROR_SUCCESS)
+ return;
+
CRegKey view;
- if (view.Open(HKEY_CURRENT_USER,
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"),
KEY_READ) == ERROR_SUCCESS)
+ if (view.Open(paint, _T("View"), KEY_READ) == ERROR_SUCCESS)
{
- ReadDWORD(view, _T("BMPHeight"), BMPHeight, TRUE);
- ReadDWORD(view, _T("BMPWidth"), BMPWidth, TRUE);
- ReadDWORD(view, _T("GridExtent"), GridExtent, FALSE);
- ReadDWORD(view, _T("NoStretching"), NoStretching, FALSE);
- ReadDWORD(view, _T("ShowThumbnail"), ShowThumbnail, FALSE);
- ReadDWORD(view, _T("SnapToGrid"), SnapToGrid, FALSE);
- ReadDWORD(view, _T("ThumbHeight"), ThumbHeight, TRUE);
- ReadDWORD(view, _T("ThumbWidth"), ThumbWidth, TRUE);
- ReadDWORD(view, _T("ThumbXPos"), ThumbXPos, TRUE);
- ReadDWORD(view, _T("ThumbYPos"), ThumbYPos, TRUE);
- ReadDWORD(view, _T("UnitSetting"), UnitSetting, FALSE);
- ReadDWORD(view, _T("ShowStatusBar"), ShowStatusBar, FALSE);
+ ReadDWORD(view, _T("BMPHeight"), BMPHeight);
+ ReadDWORD(view, _T("BMPWidth"), BMPWidth);
+ ReadDWORD(view, _T("GridExtent"), GridExtent);
+ ReadDWORD(view, _T("NoStretching"), NoStretching);
+ ReadDWORD(view, _T("ShowThumbnail"), ShowThumbnail);
+ ReadDWORD(view, _T("SnapToGrid"), SnapToGrid);
+ ReadDWORD(view, _T("ThumbHeight"), ThumbHeight);
+ ReadDWORD(view, _T("ThumbWidth"), ThumbWidth);
+ ReadDWORD(view, _T("ThumbXPos"), ThumbXPos);
+ ReadDWORD(view, _T("ThumbYPos"), ThumbYPos);
+ ReadDWORD(view, _T("UnitSetting"), UnitSetting);
+ ReadDWORD(view, _T("ShowStatusBar"), ShowStatusBar);
ULONG pnBytes = sizeof(WINDOWPLACEMENT);
view.QueryBinaryValue(_T("WindowPlacement"), &WindowPlacement,
&pnBytes);
}
CRegKey files;
- if (files.Open(HKEY_CURRENT_USER,
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File
List"), KEY_READ) == ERROR_SUCCESS)
+ if (files.Open(paint, _T("Recent File List"), KEY_READ) == ERROR_SUCCESS)
{
TCHAR szName[64];
for (INT i = 0; i < MAX_RECENT_FILES; ++i)
@@ -124,19 +126,25 @@ void RegistrySettings::Load(INT nCmdShow)
}
CRegKey text;
- if (text.Open(HKEY_CURRENT_USER,
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Text"),
KEY_READ) == ERROR_SUCCESS)
+ if (text.Open(paint, _T("Text"), KEY_READ) == ERROR_SUCCESS)
{
- ReadDWORD(text, _T("Bold"), Bold, FALSE);
- ReadDWORD(text, _T("Italic"), Italic, FALSE);
- ReadDWORD(text, _T("Underline"), Underline, FALSE);
- ReadDWORD(text, _T("CharSet"), CharSet, FALSE);
- ReadDWORD(text, _T("PointSize"), PointSize, FALSE);
- ReadDWORD(text, _T("PositionX"), FontsPositionX, FALSE);
- ReadDWORD(text, _T("PositionY"), FontsPositionY, FALSE);
- ReadDWORD(text, _T("ShowTextTool"), ShowTextTool, FALSE);
+ ReadDWORD(text, _T("Bold"), Bold);
+ ReadDWORD(text, _T("Italic"), Italic);
+ ReadDWORD(text, _T("Underline"), Underline);
+ ReadDWORD(text, _T("CharSet"), CharSet);
+ ReadDWORD(text, _T("PointSize"), PointSize);
+ ReadDWORD(text, _T("PositionX"), FontsPositionX);
+ ReadDWORD(text, _T("PositionY"), FontsPositionY);
+ ReadDWORD(text, _T("ShowTextTool"), ShowTextTool);
ReadString(text, _T("TypeFaceName"), strFontName, strFontName);
}
+ CRegKey bar4;
+ if (bar4.Open(paint, _T("General-Bar4"), KEY_READ) == ERROR_SUCCESS)
+ {
+ ReadDWORD(bar4, _T("Visible"), ShowPalette);
+ }
+
// Fix the bitmap size if too large
if (BMPWidth > 5000)
BMPWidth = (GetSystemMetrics(SM_CXSCREEN) * 6) / 10;
@@ -146,9 +154,12 @@ void RegistrySettings::Load(INT nCmdShow)
void RegistrySettings::Store()
{
+ CRegKey paint;
+ if (paint.Create(HKEY_CURRENT_USER,
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint")) !=
ERROR_SUCCESS)
+ return;
+
CRegKey view;
- if (view.Create(HKEY_CURRENT_USER,
-
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View")) ==
ERROR_SUCCESS)
+ if (view.Create(paint, _T("View")) == ERROR_SUCCESS)
{
view.SetDWORDValue(_T("BMPHeight"), BMPHeight);
view.SetDWORDValue(_T("BMPWidth"), BMPWidth);
@@ -167,7 +178,7 @@ void RegistrySettings::Store()
}
CRegKey files;
- if (files.Create(HKEY_CURRENT_USER,
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File
List")) == ERROR_SUCCESS)
+ if (files.Create(paint, _T("Recent File List")) == ERROR_SUCCESS)
{
TCHAR szName[64];
for (INT iFile = 0; iFile < MAX_RECENT_FILES; ++iFile)
@@ -178,7 +189,7 @@ void RegistrySettings::Store()
}
CRegKey text;
- if (text.Create(HKEY_CURRENT_USER,
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Text")) ==
ERROR_SUCCESS)
+ if (text.Create(paint, _T("Text")) == ERROR_SUCCESS)
{
text.SetDWORDValue(_T("Bold"), Bold);
text.SetDWORDValue(_T("Italic"), Italic);
@@ -190,6 +201,12 @@ void RegistrySettings::Store()
text.SetDWORDValue(_T("ShowTextTool"), ShowTextTool);
text.SetStringValue(_T("TypeFaceName"), strFontName);
}
+
+ CRegKey bar4;
+ if (bar4.Create(paint, _T("General-Bar4")) == ERROR_SUCCESS)
+ {
+ bar4.SetDWORDValue(_T("Visible"), ShowPalette);
+ }
}
void RegistrySettings::SetMostRecentFile(LPCTSTR szPathName)
diff --git a/base/applications/mspaint/registry.h b/base/applications/mspaint/registry.h
index b891d523c23..ce932a1c773 100644
--- a/base/applications/mspaint/registry.h
+++ b/base/applications/mspaint/registry.h
@@ -41,6 +41,7 @@ public:
DWORD FontsPositionY;
DWORD ShowTextTool;
DWORD ShowStatusBar;
+ DWORD ShowPalette;
enum WallpaperStyle {
TILED,
diff --git a/base/applications/mspaint/winproc.cpp
b/base/applications/mspaint/winproc.cpp
index 471853bad20..fc99822f5ee 100644
--- a/base/applications/mspaint/winproc.cpp
+++ b/base/applications/mspaint/winproc.cpp
@@ -753,7 +753,8 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
alignChildrenToMainWindow();
break;
case IDM_VIEWCOLORPALETTE:
- paletteWindow.ShowWindow(::IsWindowVisible(paletteWindow) ? SW_HIDE :
SW_SHOW);
+ registrySettings.ShowPalette = !paletteWindow.IsWindowVisible();
+ paletteWindow.ShowWindow(registrySettings.ShowPalette ? SW_SHOWNOACTIVATE :
SW_HIDE);
alignChildrenToMainWindow();
break;
case IDM_VIEWSTATUSBAR: