1 /*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4 * PURPOSE: Test for DM_REPOSITION
5 * COPYRIGHT: Copyright 2019 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8 #include "precomp.h"
9 #include <windowsx.h>
10
OnInitDialog(HWND hwnd,HWND hwndFocus,LPARAM lParam)11 static BOOL OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
12 {
13 RECT rc, rc2, rcWork;
14 INT cx, cy, nBitsPixel;
15 HMONITOR hMon;
16 MONITORINFO mi = { sizeof(mi) };
17 HDC hdc;
18
19 /* get monitor info */
20 hMon = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
21 ok(hMon != NULL, "hMon is NULL\n");
22 ok_int(GetMonitorInfoW(hMon, &mi), TRUE);
23 rcWork = mi.rcWork;
24
25 /* get size */
26 GetWindowRect(hwnd, &rc);
27 cx = rc.right - rc.left;
28 cy = rc.bottom - rc.top;
29
30 /* move */
31 ok_int(SetWindowPos(hwnd, NULL, rcWork.left - 80, rcWork.top - 80, 0, 0,
32 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER |
33 SWP_NOZORDER), TRUE);
34 ok_int(GetWindowRect(hwnd, &rc), TRUE);
35 ok_long(rc.left, rcWork.left - 80);
36 ok_long(rc.top, rcWork.top - 80);
37 ok_long(rc.right, rc.left + cx);
38 ok_long(rc.bottom, rc.top + cy);
39
40 /* reposition */
41 ok_int(SendMessageW(hwnd, DM_REPOSITION, 0, 0), 0);
42 ok_int(GetWindowRect(hwnd, &rc), TRUE);
43 ok_long(rc.left, rcWork.left);
44 ok_long(rc.top, rcWork.top);
45 ok_long(rc.right, rc.left + cx);
46 ok_long(rc.bottom, rc.top + cy);
47
48 /* move */
49 ok_int(SetWindowPos(hwnd, NULL,
50 rcWork.right - cx + 80, rcWork.bottom - cy + 80, 0, 0,
51 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER |
52 SWP_NOZORDER), TRUE);
53 ok_int(GetWindowRect(hwnd, &rc), TRUE);
54 ok_long(rc.left, rcWork.right - cx + 80);
55 ok_long(rc.top, rcWork.bottom - cy + 80);
56 ok_long(rc.right, rc.left + cx);
57 ok_long(rc.bottom, rc.top + cy);
58
59 /* reposition */
60 ok_int(SendMessageW(hwnd, DM_REPOSITION, 0, 0), 0);
61 ok_int(GetWindowRect(hwnd, &rc), TRUE);
62 ok_long(rc.left, rcWork.right - cx);
63 ok_long(rc.top, rcWork.bottom - cy - 4);
64 ok_long(rc.right, rc.left + cx);
65 ok_long(rc.bottom, rc.top + cy);
66
67 /* minimize */
68 ShowWindow(hwnd, SW_MINIMIZE);
69 ok_int(GetWindowRect(hwnd, &rc), TRUE);
70
71 /* reposition */
72 ok_int(SendMessageW(hwnd, DM_REPOSITION, 0, 0), 0);
73 ok_int(GetWindowRect(hwnd, &rc2), TRUE);
74 ok_int(EqualRect(&rc, &rc2), TRUE);
75
76 /* restore */
77 ShowWindow(hwnd, SW_RESTORE);
78
79 /* move */
80 ok_int(SetWindowPos(hwnd, NULL,
81 rcWork.right - cx + 80, rcWork.bottom - cy + 80, 0, 0,
82 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER |
83 SWP_NOZORDER), TRUE);
84 ok_int(GetWindowRect(hwnd, &rc), TRUE);
85 ok_long(rc.left, rcWork.right - cx + 80);
86 ok_long(rc.top, rcWork.bottom - cy + 80);
87 ok_long(rc.right, rc.left + cx);
88 ok_long(rc.bottom, rc.top + cy);
89
90 /* WM_DISPLAYCHANGE */
91 hdc = GetWindowDC(hwnd);
92 nBitsPixel = GetDeviceCaps(hdc, BITSPIXEL);
93 ReleaseDC(hwnd, hdc);
94 SendMessageW(hwnd, WM_DISPLAYCHANGE, nBitsPixel,
95 MAKELONG(GetSystemMetrics(SM_CXSCREEN),
96 GetSystemMetrics(SM_CYSCREEN)));
97 ok_int(GetWindowRect(hwnd, &rc), TRUE);
98 ok_long(rc.left, rcWork.right - cx + 80);
99 ok_long(rc.top, rcWork.bottom - cy + 80);
100 ok_long(rc.right, rc.left + cx);
101 ok_long(rc.bottom, rc.top + cy);
102
103 /* quit */
104 PostMessage(hwnd, WM_COMMAND, IDOK, 0);
105 return TRUE;
106 }
107
OnCommand(HWND hwnd,int id,HWND hwndCtl,UINT codeNotify)108 static void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
109 {
110 switch (id)
111 {
112 case IDOK:
113 case IDCANCEL:
114 EndDialog(hwnd, id);
115 break;
116 }
117 }
118
119 static INT_PTR CALLBACK
DialogProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)120 DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
121 {
122 switch (uMsg)
123 {
124 HANDLE_MSG(hwnd, WM_INITDIALOG, OnInitDialog);
125 HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
126 }
127 return 0;
128 }
129
START_TEST(DM_REPOSITION)130 START_TEST(DM_REPOSITION)
131 {
132 HMODULE hMod = GetModuleHandle(NULL);
133 ok(hMod != NULL, "\n");
134 DialogBox(hMod, TEXT("REPOSITION"), NULL, DialogProc);
135 }
136