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

commit a8e06d92e8f3f7605024c28fb16ce37251b09276
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Thu Nov 3 01:00:32 2022 +0100
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Wed Nov 16 21:55:22 2022 +0100

    [SYSDM] Make ResourceMessageBox() support printf-like messages. (#4844)
    
    + Make usage of this new functionality.
    + Cleanup precomp.h.
---
 dll/cpl/sysdm/environment.c | 18 ++++-----------
 dll/cpl/sysdm/general.c     |  1 -
 dll/cpl/sysdm/hardprof.c    | 31 ++++++++++++++-----------
 dll/cpl/sysdm/precomp.h     | 56 ++++++++++++---------------------------------
 dll/cpl/sysdm/smbios.c      |  1 -
 dll/cpl/sysdm/startrec.c    |  8 +++++++
 dll/cpl/sysdm/sysdm.c       | 30 +++++++++++++++---------
 dll/cpl/sysdm/userprofile.c | 15 +++++-------
 dll/cpl/sysdm/virtmem.c     | 23 +++++++++++++++++++
 9 files changed, 93 insertions(+), 90 deletions(-)

diff --git a/dll/cpl/sysdm/environment.c b/dll/cpl/sysdm/environment.c
index cf744ce3319..47461f65a76 100644
--- a/dll/cpl/sysdm/environment.c
+++ b/dll/cpl/sysdm/environment.c
@@ -11,9 +11,6 @@
 #include <commctrl.h>
 #include <commdlg.h>
 #include <string.h>
-#include <strsafe.h>
-
-#define MAX_STR_LENGTH  128
 
 typedef struct _VARIABLE_DATA
 {
@@ -986,16 +983,11 @@ EditVariableDlgProc(HWND hwndDlg,
 
                 case IDC_BUTTON_EDIT_TEXT:
                 {
-                    TCHAR szStr[MAX_STR_LENGTH] = _T("");
-                    TCHAR szStr2[MAX_STR_LENGTH] = _T("");
-
-                    LoadString(hApplet, IDS_ENVIRONMENT_WARNING, szStr, 
_countof(szStr));
-                    LoadString(hApplet, IDS_ENVIRONMENT_WARNING_TITLE, szStr2, 
_countof(szStr2));
-
-                    if (MessageBox(hwndDlg,
-                                   szStr,
-                                   szStr2,
-                                   MB_OKCANCEL | MB_ICONWARNING | 
MB_DEFBUTTON1) == IDOK)
+                    if (ResourceMessageBox(hApplet,
+                                           hwndDlg,
+                                           MB_OKCANCEL | MB_ICONWARNING | 
MB_DEFBUTTON1,
+                                           IDS_ENVIRONMENT_WARNING_TITLE,
+                                           IDS_ENVIRONMENT_WARNING) == IDOK)
                     {
                         EndDialog(hwndDlg, -1);
                     }
diff --git a/dll/cpl/sysdm/general.c b/dll/cpl/sysdm/general.c
index d6d1288786a..9448f6d3415 100644
--- a/dll/cpl/sysdm/general.c
+++ b/dll/cpl/sysdm/general.c
@@ -14,7 +14,6 @@
 #include <winnls.h>
 #include <powrprof.h>
 #include <buildno.h>
-#include <strsafe.h>
 
 #define ANIM_STEP 2
 #define ANIM_TIME 50
diff --git a/dll/cpl/sysdm/hardprof.c b/dll/cpl/sysdm/hardprof.c
index 5b402b90385..50a686c25dd 100644
--- a/dll/cpl/sysdm/hardprof.c
+++ b/dll/cpl/sysdm/hardprof.c
@@ -121,13 +121,17 @@ CopyProfileDlgProc(
                                    pProfileNames->szDestinationName,
                                    PROFILE_NAME_LENGTH);
                     if (IsProfileNameInUse(pProfileNames, FALSE))
+                    {
                         ResourceMessageBox(hApplet,
-                                           NULL,
+                                           hwndDlg,
                                            MB_OK | MB_ICONERROR,
                                            IDS_HWPROFILE_WARNING,
                                            IDS_HWPROFILE_ALREADY_IN_USE);
+                    }
                     else
+                    {
                         EndDialog(hwndDlg, IDOK);
+                    }
                     return TRUE;
 
                 case IDCANCEL:
@@ -238,13 +242,17 @@ RenameProfileDlgProc(
                                    pProfileNames->szDestinationName,
                                    PROFILE_NAME_LENGTH);
                     if (IsProfileNameInUse(pProfileNames, TRUE))
+                    {
                         ResourceMessageBox(hApplet,
-                                           NULL,
+                                           hwndDlg,
                                            MB_OK | MB_ICONERROR,
                                            IDS_HWPROFILE_WARNING,
                                            IDS_HWPROFILE_ALREADY_IN_USE);
+                    }
                     else
+                    {
                         EndDialog(hwndDlg, IDOK);
+                    }
                     return TRUE;
 
                 case IDCANCEL:
@@ -303,23 +311,20 @@ DeleteHardwareProfile(
     HWND hwndDlg,
     PPROFILEDATA pProfileData)
 {
-    WCHAR szMessage[256];
-    WCHAR szBuffer[128];
-    WCHAR szCaption[80];
     PPROFILE pProfiles;
     PPROFILE pProfile;
 
     pProfile = &pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex];
 
-    LoadStringW(hApplet, IDS_HWPROFILE_CONFIRM_DELETE_TITLE, szCaption, 
sizeof(szCaption) / sizeof(WCHAR));
-    LoadStringW(hApplet, IDS_HWPROFILE_CONFIRM_DELETE, szBuffer, 
sizeof(szBuffer) / sizeof(WCHAR));
-    swprintf(szMessage, szBuffer, pProfile->szFriendlyName);
-
-    if (MessageBox(NULL,
-                   szMessage,
-                   szCaption,
-                   MB_YESNO | MB_ICONQUESTION) != IDYES)
+    if (ResourceMessageBox(hApplet,
+                           hwndDlg,
+                           MB_YESNO | MB_ICONQUESTION,
+                           IDS_HWPROFILE_CONFIRM_DELETE_TITLE,
+                           IDS_HWPROFILE_CONFIRM_DELETE,
+                           pProfile->szFriendlyName) != IDYES)
+    {
         return;
+    }
 
     SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_DELETESTRING, 
pProfileData->dwSelectedProfileIndex, 0);
 
diff --git a/dll/cpl/sysdm/precomp.h b/dll/cpl/sysdm/precomp.h
index ba296735c9d..825bfc433a1 100644
--- a/dll/cpl/sysdm/precomp.h
+++ b/dll/cpl/sysdm/precomp.h
@@ -21,16 +21,18 @@
 #include <setupapi.h>
 #include <cpl.h>
 
+#include <strsafe.h>
+
 #include "resource.h"
 
 #define NUM_APPLETS (1)
 
 typedef struct _APPLET
 {
-  int idIcon;
-  int idName;
-  int idDescription;
-  APPLET_PROC AppletProc;
+    int idIcon;
+    int idName;
+    int idDescription;
+    APPLET_PROC AppletProc;
 } APPLET, *PAPPLET;
 
 extern HINSTANCE hApplet;
@@ -53,45 +55,15 @@ INT_PTR CALLBACK LicenceDlgProc(HWND hDlg, UINT message, 
WPARAM wParam, LPARAM l
 /* System information */
 BOOL GetSystemName(PWSTR pBuf, SIZE_T cchBuf);
 
-typedef struct _PAGEFILE
-{
-    TCHAR  szDrive[3];
-    LPTSTR pszVolume;
-    INT    OldMinSize;
-    INT    OldMaxSize;
-    INT    NewMinSize;
-    INT    NewMaxSize;
-    UINT   FreeSize;
-    BOOL   bUsed;
-} PAGEFILE, *PPAGEFILE;
-
-typedef struct _VIRTMEM
-{
-    HWND   hSelf;
-    HWND   hListBox;
-    LPTSTR szPagingFiles;
-    TCHAR  szDrive[10];
-    INT    Count;
-    BOOL   bModified;
-    PAGEFILE  Pagefile[26];
-} VIRTMEM, *PVIRTMEM;
-
-typedef struct _BOOTRECORD
-{
-  DWORD BootType;
-  WCHAR szSectionName[128];
-  WCHAR szBootPath[MAX_PATH];
-  WCHAR szOptions[512];
-
-}BOOTRECORD, *PBOOTRECORD;
+#define MAX_STR_LENGTH  256
 
-INT
+INT __cdecl
 ResourceMessageBox(
-    IN HINSTANCE hInstance,
-    IN HWND hwnd,
-    IN UINT uType,
-    IN UINT uCaption,
-    IN UINT uText);
-
+    _In_opt_ HINSTANCE hInstance,
+    _In_opt_ HWND hwnd,
+    _In_ UINT uType,
+    _In_ UINT uCaption,
+    _In_ UINT uText,
+    ...);
 
 #endif /* __CPL_SYSDM_H */
diff --git a/dll/cpl/sysdm/smbios.c b/dll/cpl/sysdm/smbios.c
index 5bbcb8d883d..08d40fb9ef4 100644
--- a/dll/cpl/sysdm/smbios.c
+++ b/dll/cpl/sysdm/smbios.c
@@ -9,7 +9,6 @@
 
 #include "precomp.h"
 
-#include <strsafe.h>
 #include <udmihelp.h>
 
 typedef struct GENERIC_NAME
diff --git a/dll/cpl/sysdm/startrec.c b/dll/cpl/sysdm/startrec.c
index ab29f89b745..a0bc3a8213c 100644
--- a/dll/cpl/sysdm/startrec.c
+++ b/dll/cpl/sysdm/startrec.c
@@ -12,6 +12,14 @@
 
 #include <shlwapi.h>
 
+typedef struct _BOOTRECORD
+{
+    DWORD BootType;
+    WCHAR szSectionName[128];
+    WCHAR szBootPath[MAX_PATH];
+    WCHAR szOptions[512];
+} BOOTRECORD, *PBOOTRECORD;
+
 typedef struct _STARTINFO
 {
     WCHAR szFreeldrIni[MAX_PATH + 15];
diff --git a/dll/cpl/sysdm/sysdm.c b/dll/cpl/sysdm/sysdm.c
index fbd7651a6f9..881134d7141 100644
--- a/dll/cpl/sysdm/sysdm.c
+++ b/dll/cpl/sysdm/sysdm.c
@@ -23,22 +23,30 @@ APPLET Applets[NUM_APPLETS] =
 #define MAX_SYSTEM_PAGES    32
 
 
-INT
+INT __cdecl
 ResourceMessageBox(
-    IN HINSTANCE hInstance,
-    IN HWND hwnd,
-    IN UINT uType,
-    IN UINT uCaption,
-    IN UINT uText)
+    _In_opt_ HINSTANCE hInstance,
+    _In_opt_ HWND hwnd,
+    _In_ UINT uType,
+    _In_ UINT uCaption,
+    _In_ UINT uText,
+    ...)
 {
-    WCHAR szCaption[256];
-    WCHAR szText[256];
+    va_list args;
+    WCHAR szCaption[MAX_STR_LENGTH];
+    WCHAR szText[MAX_STR_LENGTH];
+    WCHAR szCookedText[2*MAX_STR_LENGTH];
 
-    LoadStringW(hInstance, uCaption, szCaption, 256);
-    LoadStringW(hInstance, uText, szText, 256);
+    LoadStringW(hInstance, uCaption, szCaption, _countof(szCaption));
+    LoadStringW(hInstance, uText, szText, _countof(szText));
+
+    va_start(args, uText);
+    StringCchVPrintfW(szCookedText, _countof(szCookedText),
+                      szText, args);
+    va_end(args);
 
     return MessageBoxW(hwnd,
-                       szText,
+                       szCookedText,
                        szCaption,
                        uType);
 }
diff --git a/dll/cpl/sysdm/userprofile.c b/dll/cpl/sysdm/userprofile.c
index cd926abd1d7..25e0277b2de 100644
--- a/dll/cpl/sysdm/userprofile.c
+++ b/dll/cpl/sysdm/userprofile.c
@@ -150,7 +150,6 @@ BOOL
 DeleteUserProfile(
     _In_ HWND hwndDlg)
 {
-    WCHAR szTitle[64], szRawText[128], szCookedText[256];
     HWND hwndListView;
     LVITEM Item;
     INT iSelected;
@@ -179,14 +178,12 @@ DeleteUserProfile(
     if (pProfileData->dwRefCount != 0)
         return FALSE;
 
-    LoadStringW(hApplet, IDS_USERPROFILE_CONFIRM_DELETE_TITLE, szTitle, 
ARRAYSIZE(szTitle));
-    LoadStringW(hApplet, IDS_USERPROFILE_CONFIRM_DELETE, szRawText, 
ARRAYSIZE(szRawText));
-    swprintf(szCookedText, szRawText, pProfileData->pszFullName);
-
-    if (MessageBoxW(hwndDlg,
-                    szCookedText,
-                    szTitle,
-                    MB_ICONQUESTION | MB_YESNO) == IDYES)
+    if (ResourceMessageBox(hApplet,
+                           hwndDlg,
+                           MB_ICONQUESTION | MB_YESNO,
+                           IDS_USERPROFILE_CONFIRM_DELETE_TITLE,
+                           IDS_USERPROFILE_CONFIRM_DELETE,
+                           pProfileData->pszFullName) == IDYES)
     {
         /* FIXME: Delete the profile here! */
         return TRUE;
diff --git a/dll/cpl/sysdm/virtmem.c b/dll/cpl/sysdm/virtmem.c
index 798223c8453..6c72ca6c4e4 100644
--- a/dll/cpl/sysdm/virtmem.c
+++ b/dll/cpl/sysdm/virtmem.c
@@ -12,6 +12,29 @@
 #define NDEBUG
 #include <debug.h>
 
+typedef struct _PAGEFILE
+{
+    TCHAR  szDrive[3];
+    LPTSTR pszVolume;
+    INT    OldMinSize;
+    INT    OldMaxSize;
+    INT    NewMinSize;
+    INT    NewMaxSize;
+    UINT   FreeSize;
+    BOOL   bUsed;
+} PAGEFILE, *PPAGEFILE;
+
+typedef struct _VIRTMEM
+{
+    HWND   hSelf;
+    HWND   hListBox;
+    LPTSTR szPagingFiles;
+    INT    Count;
+    BOOL   bModified;
+    PAGEFILE  Pagefile[26];
+} VIRTMEM, *PVIRTMEM;
+
+
 static BOOL OnSelChange(HWND hwndDlg, PVIRTMEM pVirtMem);
 static LPCTSTR lpKey = _T("SYSTEM\\CurrentControlSet\\Control\\Session 
Manager\\Memory Management");
 

Reply via email to