ReactOS 0.4.16-dev-2522-g97cc325
user32_apitest_menuui.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4 * PURPOSE: Tests for Menu UI
5 * COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include "precomp.h"
9
10#define CLASSNAME L"user32_apitest_menuui"
11
12#define MENUID_100 100
13#define MENUID_101 101
14#define MENUID_200 200
15#define MENUID_201 201
16
17static HMENU
19{
20 HMENU hMenu = CreateMenu();
21 HMENU hSubMenu = CreatePopupMenu();
22 InsertMenuW(hSubMenu, -1, MF_BYPOSITION | MF_STRING, MENUID_200, L"Item 200");
23 InsertMenuW(hSubMenu, -1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
24 InsertMenuW(hSubMenu, -1, MF_BYPOSITION | MF_STRING, MENUID_201, L"Item 201");
25 InsertMenuW(hMenu, -1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)hSubMenu, L"&File");
26 return hMenu;
27}
28
29static HMENU
31{
32 HMENU hMenu = CreatePopupMenu();
33 if (bShift)
34 {
35 HMENU hSubMenu = CreateMyPopupMenu(FALSE);
36 InsertMenuW(hMenu, -1, MF_BYPOSITION | MF_STRING, MENUID_100, L"Item 100");
38 InsertMenuW(hMenu, -1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)hSubMenu, L"Sub Menu");
39 }
40 else
41 {
42 InsertMenuW(hMenu, -1, MF_BYPOSITION | MF_STRING, MENUID_100, L"Item 100");
44 InsertMenuW(hMenu, -1, MF_BYPOSITION | MF_STRING, MENUID_101, L"Item 101");
45 }
46 return hMenu;
47}
48
49static VOID
51{
52 POINT pt;
54
56
57 INT nID = TrackPopupMenuEx(hMenu, uFlags | TPM_RETURNCMD, pt.x, pt.y, hwnd, NULL);
58 if (nID)
60}
61
62static VOID
64{
65 SetPropW(hwnd, L"Hit", UlongToHandle(nID));
66}
67
68static
71{
72 switch (uMsg)
73 {
74 case WM_CREATE:
75 return 0;
76 case WM_RBUTTONDOWN:
77 {
79 SetPropW(hwnd, L"Hit", NULL);
80 OnContextMenu(hwnd, hMenu, 0);
81 DestroyMenu(hMenu);
82 break;
83 }
84 case WM_INITMENU:
85 SetPropW(hwnd, L"Hit", NULL);
86 break;
87 case WM_COMMAND:
89 break;
90 case WM_DESTROY:
91 SetPropW(hwnd, L"Hit", NULL);
93 break;
94 default:
95 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
96 }
97 return 0;
98}
99
102 HINSTANCE hPrevInstance,
103 LPWSTR lpCmdLine,
104 INT nCmdShow)
105{
106 LPCWSTR pszText;
107
108 if (lpCmdLine && *lpCmdLine)
109 {
110 /* Check if argument is --list, rosautotest is trying to see if this is a test. */
111 if (wcscmp(L"--list", lpCmdLine) == 0)
112 {
113 /* This is a funny hack, but it works and doesn't require special handling. */
114 printf("Valid test names:\n");
115 return 0;
116 }
117
118 /* Set window title to the command line argument. */
119 pszText = lpCmdLine;
120 }
121
122 else
123 {
124 /* No command line arguments, set window title to 'user32_apitest_menuui'. */
125 pszText = L"user32_apitest_menuui";
126 }
127
129 wc.hInstance = hInstance;
132 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
134 if (!RegisterClassW(&wc))
135 return 1;
136
137 HMENU hMenu = CreateMyMenuBarMenu();
139 CW_USEDEFAULT, CW_USEDEFAULT, 400, 300,
140 NULL, hMenu, hInstance, NULL);
141 if (!hwnd)
142 {
143 DestroyMenu(hMenu);
144 return 1;
145 }
146
147 ShowWindow(hwnd, nCmdShow);
149
150 MSG msg;
151 while (GetMessageW(&msg, NULL, 0, 0))
152 {
155 }
156
157 DestroyMenu(hMenu);
158 return (INT)msg.wParam;
159}
#define msg(x)
Definition: auth_time.c:54
#define UlongToHandle(ul)
Definition: basetsd.h:91
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
UINT uFlags
Definition: api.c:59
#define CALLBACK
Definition: compat.h:35
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1972
#define pt(x, y)
Definition: drawing.c:79
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
#define printf
Definition: freeldr.h:104
LONG_PTR LPARAM
Definition: minwindef.h:175
LONG_PTR LRESULT
Definition: minwindef.h:176
UINT_PTR WPARAM
Definition: minwindef.h:174
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned int UINT
Definition: ndis.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
LPCWSTR lpszClassName
Definition: winuser.h:3293
HBRUSH hbrBackground
Definition: winuser.h:3291
HICON hIcon
Definition: winuser.h:3289
HINSTANCE hInstance
Definition: winuser.h:3288
HCURSOR hCursor
Definition: winuser.h:3290
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int32_t INT
Definition: typedefs.h:58
#define MENUID_100
#define MENUID_101
#define MENUID_200
static HMENU CreateMyMenuBarMenu(VOID)
static VOID OnContextMenu(HWND hwnd, HMENU hMenu, UINT uFlags)
#define CLASSNAME
#define MENUID_201
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
static VOID OnCommand(HWND hwnd, UINT nID)
static HMENU CreateMyPopupMenu(BOOL bShift)
INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow)
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WINAPI
Definition: msvc.h:6
#define CS_VREDRAW
Definition: winuser.h:666
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define COLOR_WINDOW
Definition: winuser.h:929
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_CREATE
Definition: winuser.h:1636
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
BOOL WINAPI InsertMenuW(_In_ HMENU, _In_ UINT, _In_ UINT, _In_ UINT_PTR, _In_opt_ LPCWSTR)
HMENU WINAPI CreateMenu(void)
Definition: menu.c:829
#define WM_COMMAND
Definition: winuser.h:1768
#define CS_HREDRAW
Definition: winuser.h:661
#define MF_STRING
Definition: winuser.h:138
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define IDC_ARROW
Definition: winuser.h:695
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:3064
#define WM_INITMENU
Definition: winuser.h:1773
#define CS_DBLCLKS
Definition: winuser.h:659
BOOL WINAPI TrackPopupMenuEx(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _In_ HWND, _In_opt_ LPTPMPARAMS)
#define MF_POPUP
Definition: winuser.h:136
#define IDI_APPLICATION
Definition: winuser.h:712
#define WM_RBUTTONDOWN
Definition: winuser.h:1807
#define MF_SEPARATOR
Definition: winuser.h:137
#define MF_BYPOSITION
Definition: winuser.h:203
BOOL WINAPI SetPropW(_In_ HWND, _In_ LPCWSTR, _In_opt_ HANDLE)
#define LoadIcon
Definition: winuser.h:5979
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5978
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4470
#define CW_USEDEFAULT
Definition: winuser.h:225
BOOL WINAPI DestroyMenu(_In_ HMENU)
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
#define VK_SHIFT
Definition: winuser.h:2238
#define WM_DESTROY
Definition: winuser.h:1637
#define TPM_RETURNCMD
Definition: winuser.h:2423
SHORT WINAPI GetKeyState(_In_ int)
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
WCHAR * LPWSTR
Definition: xmlstorage.h:184