]> git.cworth.org Git - apitrace/blob - retrace/d3dretrace_ws.cpp
Resize window on IDirect3DDevice9::Reset.
[apitrace] / retrace / d3dretrace_ws.cpp
1 /**************************************************************************
2  *
3  * Copyright 2012 Jose Fonseca
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26
27 #include "d3dretrace.hpp"
28
29
30 namespace d3dretrace {
31
32
33 // XXX: Don't duplicate this code.
34
35 static LRESULT CALLBACK
36 WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
37 {
38     MINMAXINFO *pMMI;
39     switch (uMsg) {
40     case WM_GETMINMAXINFO:
41         // Allow to create a window bigger than the desktop
42         pMMI = (MINMAXINFO *)lParam;
43         pMMI->ptMaxSize.x = 60000;
44         pMMI->ptMaxSize.y = 60000;
45         pMMI->ptMaxTrackSize.x = 60000;
46         pMMI->ptMaxTrackSize.y = 60000;
47         break;
48     default:
49         break;
50     }
51
52     return DefWindowProc(hWnd, uMsg, wParam, lParam);
53 }
54
55
56 HWND
57 createWindow(int width, int height) {
58     static bool first = TRUE;
59     RECT rect;
60
61     if (first) {
62         WNDCLASS wc;
63         memset(&wc, 0, sizeof wc);
64         wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
65         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
66         wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
67         wc.lpfnWndProc = WndProc;
68         wc.lpszClassName = "d3dretrace";
69         wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
70         RegisterClass(&wc);
71         first = FALSE;
72     }
73
74     DWORD dwExStyle;
75     DWORD dwStyle;
76     HWND hWnd;
77
78     dwExStyle = 0;
79     dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
80
81     int x = 0, y = 0;
82
83     rect.left = x;
84     rect.top = y;
85     rect.right = rect.left + width;
86     rect.bottom = rect.top + height;
87
88     AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
89
90     hWnd = CreateWindowEx(dwExStyle,
91                           "d3dretrace", /* wc.lpszClassName */
92                           NULL,
93                           dwStyle,
94                           0, /* x */
95                           0, /* y */
96                           rect.right - rect.left, /* width */
97                           rect.bottom - rect.top, /* height */
98                           NULL,
99                           NULL,
100                           NULL,
101                           NULL);
102     ShowWindow(hWnd, SW_SHOW);
103     return hWnd;
104 }
105
106
107 void
108 resizeWindow(HWND hWnd, int width, int height) {
109     RECT rClient;
110     GetClientRect(hWnd, &rClient);
111     if (width  == rClient.right  - rClient.left &&
112         height == rClient.bottom - rClient.top) {
113         return;
114     }
115
116     RECT rWindow;
117     GetWindowRect(hWnd, &rWindow);
118     width  += (rWindow.right  - rWindow.left) - rClient.right;
119     height += (rWindow.bottom - rWindow.top)  - rClient.bottom;
120     SetWindowPos(hWnd, NULL, rWindow.left, rWindow.top, width, height, SWP_NOMOVE);
121 }
122
123
124
125 } /* namespace d3dretrace */