ReactOS 0.4.16-dev-1360-g66b782d
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{
107 wc.hInstance = hInstance;
110 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
112 if (!RegisterClassW(&wc))
113 return 1;
114
115 LPCWSTR pszText = (lpCmdLine && lpCmdLine[0]) ? lpCmdLine : L"user32_apitest_menuui";
116
117 HMENU hMenu = CreateMyMenuBarMenu();
119 CW_USEDEFAULT, CW_USEDEFAULT, 400, 300,
120 NULL, hMenu, hInstance, NULL);
121 if (!hwnd)
122 {
123 DestroyMenu(hMenu);
124 return 1;
125 }
126
127 ShowWindow(hwnd, nCmdShow);
129
130 MSG msg;
131 while (GetMessageW(&msg, NULL, 0, 0))
132 {
135 }
136
137 DestroyMenu(hMenu);
138 return (INT)msg.wParam;
139}
#define msg(x)
Definition: auth_time.c:54
#define UlongToHandle(ul)
Definition: basetsd.h:97
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
#define pt(x, y)
Definition: drawing.c:79
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
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:3261
HBRUSH hbrBackground
Definition: winuser.h:3259
HICON hIcon
Definition: winuser.h:3257
HINSTANCE hInstance
Definition: winuser.h:3256
HCURSOR hCursor
Definition: winuser.h:3258
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
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#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:1627
__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:1759
#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:3032
#define WM_INITMENU
Definition: winuser.h:1764
#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:1798
#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:5898
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5897
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4392
#define CW_USEDEFAULT
Definition: winuser.h:225
BOOL WINAPI DestroyMenu(_In_ HMENU)
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
#define VK_SHIFT
Definition: winuser.h:2221
#define WM_DESTROY
Definition: winuser.h:1628
#define TPM_RETURNCMD
Definition: winuser.h:2406
SHORT WINAPI GetKeyState(_In_ int)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185