1 /**************************************************************************
3 * Copyright 2012 Jose Fonseca
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 **************************************************************************/
27 #include "d3dretrace.hpp"
30 namespace d3dretrace {
33 // XXX: Don't duplicate this code.
35 static LRESULT CALLBACK
36 WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
43 PostMessage(hWnd, WM_CLOSE, 0, 0);
47 case WM_GETMINMAXINFO:
48 // Allow to create a window bigger than the desktop
49 pMMI = (MINMAXINFO *)lParam;
50 pMMI->ptMaxSize.x = 60000;
51 pMMI->ptMaxSize.y = 60000;
52 pMMI->ptMaxTrackSize.x = 60000;
53 pMMI->ptMaxTrackSize.y = 60000;
62 return DefWindowProc(hWnd, uMsg, wParam, lParam);
67 createWindow(int width, int height) {
68 static bool first = TRUE;
73 memset(&wc, 0, sizeof wc);
74 wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
75 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
76 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
77 wc.lpfnWndProc = WndProc;
78 wc.lpszClassName = "d3dretrace";
79 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
89 dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
95 rect.right = rect.left + width;
96 rect.bottom = rect.top + height;
98 AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
100 hWnd = CreateWindowEx(dwExStyle,
101 "d3dretrace", /* wc.lpszClassName */
106 rect.right - rect.left, /* width */
107 rect.bottom - rect.top, /* height */
112 ShowWindow(hWnd, SW_SHOW);
118 resizeWindow(HWND hWnd, int width, int height) {
120 GetClientRect(hWnd, &rClient);
121 if (width == rClient.right - rClient.left &&
122 height == rClient.bottom - rClient.top) {
127 GetWindowRect(hWnd, &rWindow);
128 width += (rWindow.right - rWindow.left) - rClient.right;
129 height += (rWindow.bottom - rWindow.top) - rClient.bottom;
130 SetWindowPos(hWnd, NULL, rWindow.left, rWindow.top, width, height, SWP_NOMOVE);
135 processEvents(void) {
137 while (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE)) {
138 if (uMsg.message == WM_QUIT) {
142 if (!TranslateAccelerator(uMsg.hwnd, NULL, &uMsg)) {
143 TranslateMessage(&uMsg);
144 DispatchMessage(&uMsg);
151 } /* namespace d3dretrace */