https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2ca3ff5bc63c52c219b1cc...
commit 2ca3ff5bc63c52c219b1ccfadc4a383673b06c5a Author: Katayama Hirofumi MZ katayama.hirofumi.mz@gmail.com AuthorDate: Tue Dec 28 10:44:56 2021 +0900 Commit: GitHub noreply@github.com CommitDate: Tue Dec 28 10:44:56 2021 +0900
[MSPAINT] Refactoring (_countof and resource.h) (#4202)
- Use Microsoft standard _countof macro instead of SIZEOF. - Rename definitions.h as resource.h. - Move some macro definitions to its proper place. CORE-17931 --- base/applications/mspaint/common.h | 22 ++++++++++++---- base/applications/mspaint/dialogs.cpp | 16 ++++++------ base/applications/mspaint/dib.cpp | 4 +-- base/applications/mspaint/history.h | 3 +++ base/applications/mspaint/main.cpp | 14 +++++----- base/applications/mspaint/precomp.h | 11 +++++++- .../mspaint/{definitions.h => resource.h} | 30 ++-------------------- base/applications/mspaint/rsrc.rc | 2 +- base/applications/mspaint/winproc.cpp | 12 ++++----- 9 files changed, 56 insertions(+), 58 deletions(-)
diff --git a/base/applications/mspaint/common.h b/base/applications/mspaint/common.h index 7cdbb22c9bf..288bba64be4 100644 --- a/base/applications/mspaint/common.h +++ b/base/applications/mspaint/common.h @@ -2,7 +2,7 @@ * PROJECT: PAINT for ReactOS * LICENSE: LGPL * FILE: base/applications/mspaint/common.h - * PURPOSE: Commonly used functions + * PURPOSE: Commonly used functions and definitions * PROGRAMMERS: Benedikt Freisen * Stanislav Motylkov * Katayama Hirofumi MZ @@ -10,6 +10,22 @@
#pragma once
+#define GRIP_SIZE 3 +#define MIN_ZOOM 125 +#define MAX_ZOOM 8000 + +/* width of the rectangle defined by a RECT structure */ +#define RECT_WIDTH(a) ((a).right - (a).left) + +/* height of the rectangle defined by a RECT structure */ +#define RECT_HEIGHT(a) ((a).bottom - (a).top) + +/* this simplifies checking and unchecking menu items */ +#define CHECKED_IF(a) ((a) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)) + +/* this simplifies enabling or graying menu items */ +#define ENABLED_IF(a) ((a) ? (MF_ENABLED | MF_BYCOMMAND) : (MF_GRAYED | MF_BYCOMMAND)) + /* FUNCTIONS ********************************************************/
BOOL zoomTo(int newZoom, int mouseX, int mouseY); @@ -24,7 +40,3 @@ static inline int UnZoomed(int xy) { return xy * 1000 / toolsModel.GetZoom(); } - -#define GRIP_SIZE 3 -#define MIN_ZOOM 125 -#define MAX_ZOOM 8000 diff --git a/base/applications/mspaint/dialogs.cpp b/base/applications/mspaint/dialogs.cpp index 144b5ed7350..09a3e5cebfb 100644 --- a/base/applications/mspaint/dialogs.cpp +++ b/base/applications/mspaint/dialogs.cpp @@ -88,8 +88,8 @@ LRESULT CAttributesDialog::OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, { TCHAR date[100]; TCHAR temp[100]; - GetDateFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, date, SIZEOF(date)); - GetTimeFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, temp, SIZEOF(temp)); + GetDateFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, date, _countof(date)); + GetTimeFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, temp, _countof(temp)); _tcscat(date, _T(" ")); _tcscat(date, temp); CString strSize; @@ -166,17 +166,17 @@ LRESULT CAttributesDialog::OnEdit1(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOO TCHAR tempS[100]; if (IsDlgButtonChecked(IDD_ATTRIBUTESRB1)) { - GetDlgItemText(IDD_ATTRIBUTESEDIT1, tempS, SIZEOF(tempS)); + GetDlgItemText(IDD_ATTRIBUTESEDIT1, tempS, _countof(tempS)); newWidth = max(1, (int) (_tcstod(tempS, NULL) * fileHPPM * 0.0254)); } else if (IsDlgButtonChecked(IDD_ATTRIBUTESRB2)) { - GetDlgItemText(IDD_ATTRIBUTESEDIT1, tempS, SIZEOF(tempS)); + GetDlgItemText(IDD_ATTRIBUTESEDIT1, tempS, _countof(tempS)); newWidth = max(1, (int) (_tcstod(tempS, NULL) * fileHPPM / 100)); } else if (IsDlgButtonChecked(IDD_ATTRIBUTESRB3)) { - GetDlgItemText(IDD_ATTRIBUTESEDIT1, tempS, SIZEOF(tempS)); + GetDlgItemText(IDD_ATTRIBUTESEDIT1, tempS, _countof(tempS)); newWidth = max(1, _tstoi(tempS)); } Edit_SetModify(hWndCtl, FALSE); @@ -191,17 +191,17 @@ LRESULT CAttributesDialog::OnEdit2(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOO TCHAR tempS[100]; if (IsDlgButtonChecked(IDD_ATTRIBUTESRB1)) { - GetDlgItemText(IDD_ATTRIBUTESEDIT2, tempS, SIZEOF(tempS)); + GetDlgItemText(IDD_ATTRIBUTESEDIT2, tempS, _countof(tempS)); newHeight = max(1, (int) (_tcstod(tempS, NULL) * fileVPPM * 0.0254)); } else if (IsDlgButtonChecked(IDD_ATTRIBUTESRB2)) { - GetDlgItemText(IDD_ATTRIBUTESEDIT2, tempS, SIZEOF(tempS)); + GetDlgItemText(IDD_ATTRIBUTESEDIT2, tempS, _countof(tempS)); newHeight = max(1, (int) (_tcstod(tempS, NULL) * fileVPPM / 100)); } else if (IsDlgButtonChecked(IDD_ATTRIBUTESRB3)) { - GetDlgItemText(IDD_ATTRIBUTESEDIT2, tempS, SIZEOF(tempS)); + GetDlgItemText(IDD_ATTRIBUTESEDIT2, tempS, _countof(tempS)); newHeight = max(1, _tstoi(tempS)); } Edit_SetModify(hWndCtl, FALSE); diff --git a/base/applications/mspaint/dib.cpp b/base/applications/mspaint/dib.cpp index ecdbf22e339..53a12f71602 100644 --- a/base/applications/mspaint/dib.cpp +++ b/base/applications/mspaint/dib.cpp @@ -137,9 +137,9 @@ HBITMAP SetBitmapAndInfo(HBITMAP hBitmap, LPCTSTR name, DWORD dwFileSize, BOOL i
// update filepathname if (name && name[0]) - GetFullPathName(name, SIZEOF(filepathname), filepathname, NULL); + GetFullPathName(name, _countof(filepathname), filepathname, NULL); else - LoadString(hProgInstance, IDS_DEFAULTFILENAME, filepathname, SIZEOF(filepathname)); + LoadString(hProgInstance, IDS_DEFAULTFILENAME, filepathname, _countof(filepathname));
// set title CString strTitle; diff --git a/base/applications/mspaint/history.h b/base/applications/mspaint/history.h index 587d9c2e7a7..697b65bf128 100644 --- a/base/applications/mspaint/history.h +++ b/base/applications/mspaint/history.h @@ -8,6 +8,9 @@
#pragma once
+/* HISTORYSIZE = number of possible undo-steps + 1 */ +#define HISTORYSIZE 11 + class ImageModel { private: diff --git a/base/applications/mspaint/main.cpp b/base/applications/mspaint/main.cpp index fe77e8ae097..b7e774a23f4 100644 --- a/base/applications/mspaint/main.cpp +++ b/base/applications/mspaint/main.cpp @@ -120,7 +120,7 @@ OFNHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { hParent = GetParent(hwnd); TCHAR Path[MAX_PATH]; - SendMessage(hParent, CDM_GETFILEPATH, SIZEOF(Path), (LPARAM)Path); + SendMessage(hParent, CDM_GETFILEPATH, _countof(Path), (LPARAM)Path); LPTSTR pchTitle = _tcsrchr(Path, _T('\')); if (pchTitle == NULL) pchTitle = _tcsrchr(Path, _T('/')); @@ -173,12 +173,12 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument /* initialize common controls library */ InitCommonControls();
- LoadString(hThisInstance, IDS_DEFAULTFILENAME, filepathname, SIZEOF(filepathname)); + LoadString(hThisInstance, IDS_DEFAULTFILENAME, filepathname, _countof(filepathname)); CPath pathFileName(filepathname); pathFileName.StripPath(); CString strTitle; strTitle.Format(IDS_WINDOWTITLE, (LPCTSTR)pathFileName); - LoadString(hThisInstance, IDS_MINIATURETITLE, miniaturetitle, SIZEOF(miniaturetitle)); + LoadString(hThisInstance, IDS_MINIATURETITLE, miniaturetitle, _countof(miniaturetitle));
/* load settings from registry */ registrySettings.Load(); @@ -279,9 +279,9 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument ofn.hInstance = hThisInstance; ofn.lpstrFilter = strImporters; ofn.lpstrFile = ofnFilename; - ofn.nMaxFile = SIZEOF(ofnFilename); + ofn.nMaxFile = _countof(ofnFilename); ofn.lpstrFileTitle = ofnFiletitle; - ofn.nMaxFileTitle = SIZEOF(ofnFiletitle); + ofn.nMaxFileTitle = _countof(ofnFiletitle); ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY; ofn.lpstrDefExt = L"png";
@@ -295,9 +295,9 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument sfn.hInstance = hThisInstance; sfn.lpstrFilter = strExporters; sfn.lpstrFile = sfnFilename; - sfn.nMaxFile = SIZEOF(sfnFilename); + sfn.nMaxFile = _countof(sfnFilename); sfn.lpstrFileTitle = sfnFiletitle; - sfn.nMaxFileTitle = SIZEOF(sfnFiletitle); + sfn.nMaxFileTitle = _countof(sfnFiletitle); sfn.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_EXPLORER | OFN_ENABLEHOOK; sfn.lpfnHook = OFNHookProc; sfn.lpstrDefExt = L"png"; diff --git a/base/applications/mspaint/precomp.h b/base/applications/mspaint/precomp.h index 6bdbafceb30..d51eafa85e6 100644 --- a/base/applications/mspaint/precomp.h +++ b/base/applications/mspaint/precomp.h @@ -21,7 +21,16 @@ #include <shellapi.h> #include <htmlhelp.h>
-#include "definitions.h" +#define WM_TOOLSMODELTOOLCHANGED (WM_APP + 0) +#define WM_TOOLSMODELSETTINGSCHANGED (WM_APP + 1) +#define WM_TOOLSMODELZOOMCHANGED (WM_APP + 2) +#define WM_PALETTEMODELCOLORCHANGED (WM_APP + 3) +#define WM_PALETTEMODELPALETTECHANGED (WM_APP + 4) +#define WM_IMAGEMODELDIMENSIONSCHANGED (WM_APP + 5) +#define WM_IMAGEMODELIMAGECHANGED (WM_APP + 6) +#define WM_SELECTIONMODELREFRESHNEEDED (WM_APP + 7) + +#include "resource.h" #include "drawing.h" #include "dib.h" #include "fullscreen.h" diff --git a/base/applications/mspaint/definitions.h b/base/applications/mspaint/resource.h similarity index 82% rename from base/applications/mspaint/definitions.h rename to base/applications/mspaint/resource.h index 26ea4f19549..fd3330a776b 100644 --- a/base/applications/mspaint/definitions.h +++ b/base/applications/mspaint/resource.h @@ -1,8 +1,8 @@ /* * PROJECT: PAINT for ReactOS * LICENSE: LGPL - * FILE: base/applications/mspaint/definitions.h - * PURPOSE: Defines the resource ids and other stuff + * FILE: base/applications/mspaint/resource.h + * PURPOSE: Defines the resource IDs * PROGRAMMERS: Benedikt Freisen */
@@ -10,23 +10,6 @@
/* DEFINES **********************************************************/
-#define HISTORYSIZE 11 -/* HISTORYSIZE = number of possible undo-steps + 1 */ - -#define SIZEOF(a) (sizeof(a) / sizeof((a)[0])) -/* sizeof for string constants; equals max. number of characters */ - -#define RECT_WIDTH(a) ((a).right - (a).left) -/* width of the rectangle defined by a RECT structure */ - -#define RECT_HEIGHT(a) ((a).bottom - (a).top) -/* height of the rectangle defined by a RECT structure */ - -#define CHECKED_IF(a) ((a) ? (MF_CHECKED | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND)) -/* simplifies checking and unchecking menu items */ -#define ENABLED_IF(a) ((a) ? (MF_ENABLED | MF_BYCOMMAND) : (MF_GRAYED | MF_BYCOMMAND)) -/* simplifies enabling or graying menu items */ - #define IDI_APPICON 500
#define IDB_TOOLBARICONS 510 @@ -219,12 +202,3 @@
#define IDS_LOADERRORTEXT 933 #define IDS_ENLARGEPROMPTTEXT 934 - -#define WM_TOOLSMODELTOOLCHANGED WM_APP -#define WM_TOOLSMODELSETTINGSCHANGED (WM_APP + 1) -#define WM_TOOLSMODELZOOMCHANGED (WM_APP + 2) -#define WM_PALETTEMODELCOLORCHANGED (WM_APP + 3) -#define WM_PALETTEMODELPALETTECHANGED (WM_APP + 4) -#define WM_IMAGEMODELDIMENSIONSCHANGED (WM_APP + 5) -#define WM_IMAGEMODELIMAGECHANGED (WM_APP + 6) -#define WM_SELECTIONMODELREFRESHNEEDED (WM_APP + 7) diff --git a/base/applications/mspaint/rsrc.rc b/base/applications/mspaint/rsrc.rc index 99c6941e91d..ccfc605fbd9 100644 --- a/base/applications/mspaint/rsrc.rc +++ b/base/applications/mspaint/rsrc.rc @@ -11,7 +11,7 @@ #include <windef.h> #include <winuser.h>
-#include "definitions.h" +#include "resource.h"
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Paint" #define REACTOS_STR_INTERNAL_NAME "mspaint" diff --git a/base/applications/mspaint/winproc.cpp b/base/applications/mspaint/winproc.cpp index 1f251449669..026d5536def 100644 --- a/base/applications/mspaint/winproc.cpp +++ b/base/applications/mspaint/winproc.cpp @@ -94,7 +94,7 @@ void CMainWindow::saveImage(BOOL overwrite) else if (GetSaveFileName(&sfn) != 0) { imageModel.SaveImage(sfn.lpstrFile); - _tcsncpy(filepathname, sfn.lpstrFile, SIZEOF(filepathname)); + _tcsncpy(filepathname, sfn.lpstrFile, _countof(filepathname)); CString strTitle; strTitle.Format(IDS_WINDOWTITLE, (LPCTSTR)sfn.lpstrFileTitle); SetWindowText(strTitle); @@ -118,8 +118,8 @@ void CMainWindow::InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window) TCHAR programname[20]; TCHAR shouldEnlargePromptText[100];
- LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname)); - LoadString(hProgInstance, IDS_ENLARGEPROMPTTEXT, shouldEnlargePromptText, SIZEOF(shouldEnlargePromptText)); + LoadString(hProgInstance, IDS_PROGRAMNAME, programname, _countof(programname)); + LoadString(hProgInstance, IDS_ENLARGEPROMPTTEXT, shouldEnlargePromptText, _countof(shouldEnlargePromptText));
switch (MessageBox(shouldEnlargePromptText, programname, MB_YESNOCANCEL | MB_ICONQUESTION)) { @@ -212,7 +212,7 @@ LRESULT CMainWindow::OnDropFiles(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& TCHAR droppedfile[MAX_PATH];
HDROP hDrop = (HDROP)wParam; - DragQueryFile(hDrop, 0, droppedfile, SIZEOF(droppedfile)); + DragQueryFile(hDrop, 0, droppedfile, _countof(droppedfile)); DragFinish(hDrop);
ConfirmSave() && DoLoadImageFile(m_hWnd, droppedfile, TRUE); @@ -430,8 +430,8 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH HICON paintIcon = LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON)); TCHAR infotitle[100]; TCHAR infotext[200]; - LoadString(hProgInstance, IDS_INFOTITLE, infotitle, SIZEOF(infotitle)); - LoadString(hProgInstance, IDS_INFOTEXT, infotext, SIZEOF(infotext)); + LoadString(hProgInstance, IDS_INFOTITLE, infotitle, _countof(infotitle)); + LoadString(hProgInstance, IDS_INFOTEXT, infotext, _countof(infotext)); ShellAbout(m_hWnd, infotitle, infotext, paintIcon); DeleteObject(paintIcon); break;