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