[ROSTESTS] Add an interactive test for the user32.dll API SoftModalMessageBox().

This commit is contained in:
Hermès Bélusca-Maïto 2018-08-16 22:01:52 +02:00
parent 4f7318b759
commit 5fedabbf0a
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
5 changed files with 141 additions and 0 deletions

View file

@ -1,4 +1,5 @@
add_subdirectory(biditext)
add_subdirectory(paintdesktop)
add_subdirectory(softmodalmsgbox)
add_subdirectory(sysicon)
add_subdirectory(winstation)

View file

@ -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)

View file

@ -0,0 +1,2 @@
#define IDS_RES_CAPTION 101
#define IDS_RES_MESSAGE 102

View file

@ -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;
}

View file

@ -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