[ROSTESTS] Add an interactive test for the user32.dll API SoftModalMessageBox().
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 16 Aug 2018 20:01:52 +0000 (22:01 +0200)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Fri, 17 Aug 2018 15:12:23 +0000 (17:12 +0200)
modules/rostests/win32/user32/CMakeLists.txt
modules/rostests/win32/user32/softmodalmsgbox/CMakeLists.txt [new file with mode: 0644]
modules/rostests/win32/user32/softmodalmsgbox/resource.h [new file with mode: 0644]
modules/rostests/win32/user32/softmodalmsgbox/softmodalmsgbox.c [new file with mode: 0644]
modules/rostests/win32/user32/softmodalmsgbox/softmodalmsgbox.rc [new file with mode: 0644]

index d1d8397..205afbc 100644 (file)
@@ -1,4 +1,5 @@
 add_subdirectory(biditext)
 add_subdirectory(paintdesktop)
+add_subdirectory(softmodalmsgbox)
 add_subdirectory(sysicon)
 add_subdirectory(winstation)
diff --git a/modules/rostests/win32/user32/softmodalmsgbox/CMakeLists.txt b/modules/rostests/win32/user32/softmodalmsgbox/CMakeLists.txt
new file mode 100644 (file)
index 0000000..310a01e
--- /dev/null
@@ -0,0 +1,5 @@
+
+add_executable(softmodalmsgbox softmodalmsgbox.c softmodalmsgbox.rc)
+set_module_type(softmodalmsgbox win32cui UNICODE)
+add_importlibs(softmodalmsgbox user32 msvcrt kernel32)
+add_rostests_file(TARGET softmodalmsgbox SUBDIR suppl)
diff --git a/modules/rostests/win32/user32/softmodalmsgbox/resource.h b/modules/rostests/win32/user32/softmodalmsgbox/resource.h
new file mode 100644 (file)
index 0000000..6e6ee36
--- /dev/null
@@ -0,0 +1,2 @@
+#define IDS_RES_CAPTION                 101
+#define IDS_RES_MESSAGE                 102
diff --git a/modules/rostests/win32/user32/softmodalmsgbox/softmodalmsgbox.c b/modules/rostests/win32/user32/softmodalmsgbox/softmodalmsgbox.c
new file mode 100644 (file)
index 0000000..40913e6
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * PROJECT:     ReactOS Tests
+ * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE:     Tests the undocumented user32.dll API SoftModalMessageBox().
+ * COPYRIGHT:   Copyright 2018 Hermes Belusca-Maito
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <conio.h>
+
+#include <windef.h>
+#include <winbase.h>
+#include <winuser.h>
+
+#include "resource.h"
+
+/* Adjust according to your platform! -- ReactOS is currently compatible with Windows Server 2003 */
+#undef _WIN32_WINNT
+#define _WIN32_WINNT _WIN32_WINNT_WS03 // _WIN32_WINNT_WIN2K // _WIN32_WINNT_WS03 // _WIN32_WINNT_WIN7
+
+typedef struct _MSGBOXDATA
+{
+    MSGBOXPARAMSW mbp;          // Size: 0x28 (x86), 0x50 (x64)
+    HWND     hwndOwner;         // Will be converted to PWND
+#if defined(_WIN32) && (_WIN32_WINNT >= _WIN32_WINNT_WIN7) /* (NTDDI_VERSION >= NTDDI_WIN7) */
+    DWORD    dwPadding;
+#endif
+    WORD     wLanguageId;
+    INT*     pidButton;         // Array of button IDs
+    LPCWSTR* ppszButtonText;    // Array of button text strings
+    DWORD    dwButtons;         // Number of buttons
+    UINT     uDefButton;        // Default button ID
+    UINT     uCancelId;         // Button ID corresponding to Cancel action
+#if (_WIN32_WINNT >= _WIN32_WINNT_WINXP) /* (NTDDI_VERSION >= NTDDI_WINXP) */
+    DWORD    dwTimeout;         // Message box timeout
+#endif
+    DWORD    dwReserved0;
+#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7) /* (NTDDI_VERSION >= NTDDI_WIN7) */
+    DWORD    dwReserved[4];
+#endif
+} MSGBOXDATA, *PMSGBOXDATA, *LPMSGBOXDATA;
+
+
+#if defined(_WIN64)
+
+#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7) /* (NTDDI_VERSION >= NTDDI_WIN7) */
+C_ASSERT(sizeof(MSGBOXDATA) == 0x98);
+#elif (_WIN32_WINNT <= _WIN32_WINNT_WS03) /* (NTDDI_VERSION == NTDDI_WS03) */
+C_ASSERT(sizeof(MSGBOXDATA) == 0x88);
+#endif
+
+#else
+
+#if (_WIN32_WINNT <= _WIN32_WINNT_WIN2K) /* (NTDDI_VERSION <= NTDDI_WIN2KSP4) */
+C_ASSERT(sizeof(MSGBOXDATA) == 0x48);
+#elif (_WIN32_WINNT >= _WIN32_WINNT_WIN7) /* (NTDDI_VERSION >= NTDDI_WIN7) */
+C_ASSERT(sizeof(MSGBOXDATA) == 0x60);
+#else // (_WIN32_WINNT == _WIN32_WINNT_WINXP || _WIN32_WINNT == _WIN32_WINNT_WS03) /* (NTDDI_VERSION == NTDDI_WS03) */
+C_ASSERT(sizeof(MSGBOXDATA) == 0x4C);
+#endif
+
+#endif
+
+
+typedef int (WINAPI *SOFTMODALMESSAGEBOX)(LPMSGBOXDATA lpMsgBoxData);
+// int WINAPI SoftModalMessageBox(IN LPMSGBOXDATA lpMsgBoxData);
+SOFTMODALMESSAGEBOX SoftModalMessageBox = NULL;
+
+//
+// Example taken from http://rsdn.org/forum/winapi/3273168.1
+// See also http://www.vbforums.com/showthread.php?840593-Message-Box-with-Four-Buttons
+//
+int wmain(int argc, WCHAR* argv[])
+{
+    MSGBOXDATA data;
+    int res = 0;
+
+    INT pids[] =
+    {
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 /*, 2*/
+    };
+    /* NOTE: Buttons do NOT support resource IDs specifications! */
+    LPCWSTR ppText[] =
+    {
+        L"Button 1", L"Button 2", L"Button 3", L"Button 4", L"Button 5", L"Button 6", L"Button 7", L"Button 8", L"Button 9", L"Button 10", L"Button 11", L"Button 12", L"Button 13"
+    };
+
+    ZeroMemory(&data, sizeof(data));
+    data.mbp.cbSize = sizeof(data.mbp);
+    data.mbp.hwndOwner = FindWindowW(L"Shell_TrayWnd", NULL);
+    data.mbp.hInstance = GetModuleHandleW(NULL);
+    data.mbp.lpszText  = L"This is a message box made using the undocumented SoftModalMessageBox() API.";
+    data.mbp.lpszCaption = MAKEINTRESOURCEW(IDS_RES_CAPTION); // L"SoftModalMessageBox";
+    data.mbp.lpfnMsgBoxCallback = NULL; // SoftModalMessageBoxCallback;
+    data.mbp.dwStyle = MB_ICONINFORMATION | MB_RETRYCANCEL;
+
+    data.wLanguageId = 0;
+    data.pidButton      = pids;
+    data.ppszButtonText = ppText;
+    data.dwButtons  = _countof(pids);
+    data.uDefButton = 2;
+    data.uCancelId  = 0;
+#if (_WIN32_WINNT >= _WIN32_WINNT_WINXP) /* (NTDDI_VERSION >= NTDDI_WINXP) */
+    data.dwTimeout  = 3 * 1000;
+#endif
+
+    SoftModalMessageBox = (SOFTMODALMESSAGEBOX)GetProcAddress(GetModuleHandleW(L"user32.dll"), "SoftModalMessageBox");
+    if (!SoftModalMessageBox)
+    {
+        printf("SoftModalMessageBoxW not found in user32.dll\n");
+    }
+    else
+    {
+        res = SoftModalMessageBox(&data);
+        printf("Returned value = %i\n\n", res);
+    }
+
+    printf("Press any key to quit...\n");
+    _getch();
+    return 0;
+}
diff --git a/modules/rostests/win32/user32/softmodalmsgbox/softmodalmsgbox.rc b/modules/rostests/win32/user32/softmodalmsgbox/softmodalmsgbox.rc
new file mode 100644 (file)
index 0000000..e04c4ea
--- /dev/null
@@ -0,0 +1,11 @@
+
+#include <windef.h>
+#include "resource.h"
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+
+STRINGTABLE
+BEGIN
+    IDS_RES_CAPTION "Resource Caption"
+    IDS_RES_MESSAGE "Resource Message"
+END