| @@ -10,9 +10,7 @@ · 9 unmodified lines |
| 10 | 10 | |
| 11 | 11 | char szAppName[] = APPNAME; // The name of this application |
| 12 | 12 | char szTitle[] = APPNAME; // The title bar text |
| 13 | | −char *pWindowText; |
| 14 | | − |
| 15 | | −HINSTANCE g_hInst; // current instance |
| 13 | +const char *pWindowText; |
| 16 | 14 | |
| 17 | 15 | void CenterWindow(HWND hWnd); |
| 18 | 16 | |
| @@ -28,51 +26,49 @@ void CenterWindow(HWND hWnd); · 9 unmodified lines |
| 28 | 26 | |
| 29 | 27 | LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) |
| 30 | 28 | { |
| 31 | | − switch (message) |
| 32 | | − { |
| 33 | | − // ----------------------- first and last |
| 34 | | − case WM_CREATE: |
| 35 | | − CenterWindow(hwnd); |
| 36 | | − break; |
| 37 | | − |
| 38 | | − case WM_DESTROY: |
| 39 | | − PostQuitMessage(0); |
| 40 | | − break; |
| 41 | | − |
| 42 | | − |
| 43 | | − // ----------------------- get out of it... |
| 44 | | − case WM_RBUTTONUP: |
| 45 | | − DestroyWindow(hwnd); |
| 46 | | − break; |
| 47 | | − |
| 48 | | − case WM_KEYDOWN: |
| 49 | | − if (VK_ESCAPE == wParam) |
| 50 | | − DestroyWindow(hwnd); |
| 51 | | − break; |
| 52 | | − |
| 53 | | − |
| 54 | | − // ----------------------- display our minimal info |
| 55 | | − case WM_PAINT: |
| 56 | | − { |
| 57 | | − PAINTSTRUCT ps; |
| 58 | | − HDC hdc; |
| 59 | | − RECT rc; |
| 60 | | − hdc = BeginPaint(hwnd, &ps); |
| 61 | | − |
| 62 | | − GetClientRect(hwnd, &rc); |
| 63 | | − SetTextColor(hdc, RGB(240,240,96)); |
| 64 | | − SetBkMode(hdc, TRANSPARENT); |
| 65 | | − DrawText(hdc, pWindowText, -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER); |
| 66 | | − |
| 67 | | − EndPaint(hwnd, &ps); |
| 68 | | − break; |
| 69 | | − } |
| 70 | | − |
| 71 | | − // ----------------------- let windows do all other stuff |
| 72 | | − default: |
| 73 | | − return DefWindowProc(hwnd, message, wParam, lParam); |
| 74 | | − } |
| 75 | | − return 0; |
| 29 | + switch (message) { |
| 30 | + |
| 31 | + // ----------------------- first and last |
| 32 | + case WM_CREATE: |
| 33 | + CenterWindow(hwnd); |
| 34 | + break; |
| 35 | + |
| 36 | + case WM_DESTROY: |
| 37 | + PostQuitMessage(0); |
| 38 | + break; |
| 39 | + |
| 40 | + // ----------------------- get out of it... |
| 41 | + case WM_RBUTTONUP: |
| 42 | + DestroyWindow(hwnd); |
| 43 | + break; |
| 44 | + |
| 45 | + case WM_KEYDOWN: |
| 46 | + if (VK_ESCAPE == wParam) |
| 47 | + DestroyWindow(hwnd); |
| 48 | + break; |
| 49 | + |
| 50 | + // ----------------------- display our minimal info |
| 51 | + case WM_PAINT: |
| 52 | + { |
| 53 | + PAINTSTRUCT ps; |
| 54 | + HDC hdc; |
| 55 | + RECT rc; |
| 56 | + hdc = BeginPaint(hwnd, &ps); |
| 57 | + |
| 58 | + GetClientRect(hwnd, &rc); |
| 59 | + SetTextColor(hdc, RGB(240,240,96)); |
| 60 | + SetBkMode(hdc, TRANSPARENT); |
| 61 | + DrawText(hdc, pWindowText, -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER); |
| 62 | + |
| 63 | + EndPaint(hwnd, &ps); |
| 64 | + break; |
| 65 | + } |
| 66 | + |
| 67 | + // ----------------------- let windows do all other stuff |
| 68 | + default: |
| 69 | + return DefWindowProc(hwnd, message, wParam, lParam); |
| 70 | + } |
| 71 | + return 0; |
| 76 | 72 | } |
| 77 | 73 | |
| 78 | 74 | //+--------------------------------------------------------------------------- |
| @@ -83,57 +79,57 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) · 4 unmodified lines |
| 83 | 79 | // |
| 84 | 80 | //---------------------------------------------------------------------------- |
| 85 | 81 | int APIENTRY WinMain( |
| 86 | | − HINSTANCE hInstance, |
| 87 | | − HINSTANCE hPrevInstance, |
| 88 | | − LPSTR lpCmdLine, |
| 89 | | − int nCmdShow) |
| 82 | + HINSTANCE hInstance, |
| 83 | + HINSTANCE hPrevInstance, |
| 84 | + LPSTR lpCmdLine, |
| 85 | + int nCmdShow |
| 86 | + ) |
| 90 | 87 | { |
| 91 | | − MSG msg; |
| 92 | | − |
| 93 | | − WNDCLASS wc; |
| 94 | | − |
| 95 | | − HWND hwnd; |
| 96 | | − |
| 97 | | − // Fill in window class structure with parameters that describe |
| 98 | | − // the main window. |
| 99 | | − |
| 100 | | − ZeroMemory(&wc, sizeof wc); |
| 101 | | − wc.hInstance = hInstance; |
| 102 | | − wc.lpszClassName = szAppName; |
| 103 | | − wc.lpfnWndProc = (WNDPROC)WndProc; |
| 104 | | − wc.style = CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW; |
| 105 | | − wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); |
| 106 | | − wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); |
| 107 | | − wc.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 108 | | − |
| 109 | | − if (FALSE == RegisterClass(&wc)) return 0; |
| 110 | | − |
| 111 | | − // create the browser |
| 112 | | − hwnd = CreateWindow( |
| 113 | | − szAppName, |
| 114 | | − szTitle, |
| 115 | | − WS_OVERLAPPEDWINDOW|WS_VISIBLE, |
| 116 | | − CW_USEDEFAULT, |
| 117 | | − CW_USEDEFAULT, |
| 118 | | − 360,//CW_USEDEFAULT, |
| 119 | | − 240,//CW_USEDEFAULT, |
| 120 | | − 0, |
| 121 | | − 0, |
| 122 | | − g_hInst, |
| 123 | | − 0); |
| 124 | | − |
| 125 | | − if (NULL == hwnd) return 0; |
| 126 | | − |
| 127 | | − pWindowText = lpCmdLine[0] ? lpCmdLine : "Hello Windows!"; |
| 128 | | − |
| 129 | | − // Main message loop: |
| 130 | | − while (GetMessage(&msg, NULL, 0, 0) > 0) |
| 131 | | − { |
| 132 | | − TranslateMessage(&msg); |
| 133 | | − DispatchMessage(&msg); |
| 134 | | − } |
| 135 | | − |
| 136 | | − return msg.wParam; |
| 88 | + MSG msg; |
| 89 | + WNDCLASS wc; |
| 90 | + HWND hwnd; |
| 91 | + |
| 92 | + pWindowText = lpCmdLine[0] ? lpCmdLine : "Hello Windows!"; |
| 93 | + |
| 94 | + // Fill in window class structure with parameters that describe |
| 95 | + // the main window. |
| 96 | + |
| 97 | + ZeroMemory(&wc, sizeof wc); |
| 98 | + wc.hInstance = hInstance; |
| 99 | + wc.lpszClassName = szAppName; |
| 100 | + wc.lpfnWndProc = (WNDPROC)WndProc; |
| 101 | + wc.style = CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW; |
| 102 | + wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); |
| 103 | + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); |
| 104 | + wc.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 105 | + |
| 106 | + if (FALSE == RegisterClass(&wc)) |
| 107 | + return 0; |
| 108 | + |
| 109 | + // create the browser |
| 110 | + hwnd = CreateWindow( |
| 111 | + szAppName, |
| 112 | + szTitle, |
| 113 | + WS_OVERLAPPEDWINDOW|WS_VISIBLE, |
| 114 | + CW_USEDEFAULT, |
| 115 | + CW_USEDEFAULT, |
| 116 | + 360,//CW_USEDEFAULT, |
| 117 | + 240,//CW_USEDEFAULT, |
| 118 | + 0, |
| 119 | + 0, |
| 120 | + hInstance, |
| 121 | + 0); |
| 122 | + |
| 123 | + if (NULL == hwnd) |
| 124 | + return 0; |
| 125 | + |
| 126 | + // Main message loop: |
| 127 | + while (GetMessage(&msg, NULL, 0, 0) > 0) { |
| 128 | + TranslateMessage(&msg); |
| 129 | + DispatchMessage(&msg); |
| 130 | + } |
| 131 | + |
| 132 | + return msg.wParam; |
| 137 | 133 | } |
| 138 | 134 | |
| 139 | 135 | //+--------------------------------------------------------------------------- |
| @@ -142,18 +138,26 @@ int APIENTRY WinMain( · 2 unmodified lines |
| 142 | 138 | |
| 143 | 139 | void CenterWindow(HWND hwnd_self) |
| 144 | 140 | { |
| 145 | | − RECT rw_self, rc_parent, rw_parent; HWND hwnd_parent; |
| 146 | | − hwnd_parent = GetParent(hwnd_self); |
| 147 | | − if (NULL==hwnd_parent) hwnd_parent = GetDesktopWindow(); |
| 148 | | − GetWindowRect(hwnd_parent, &rw_parent); |
| 149 | | − GetClientRect(hwnd_parent, &rc_parent); |
| 150 | | − GetWindowRect(hwnd_self, &rw_self); |
| 151 | | − SetWindowPos(hwnd_self, NULL, |
| 152 | | − rw_parent.left + (rc_parent.right + rw_self.left - rw_self.right) / 2, |
| 153 | | − rw_parent.top + (rc_parent.bottom + rw_self.top - rw_self.bottom) / 2, |
| 154 | | − 0, 0, |
| 155 | | − SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE |
| 156 | | − ); |
| 141 | + HWND hwnd_parent; |
| 142 | + RECT rw_self, rc_parent, rw_parent; |
| 143 | + int xpos, ypos; |
| 144 | + |
| 145 | + hwnd_parent = GetParent(hwnd_self); |
| 146 | + if (NULL == hwnd_parent) |
| 147 | + hwnd_parent = GetDesktopWindow(); |
| 148 | + |
| 149 | + GetWindowRect(hwnd_parent, &rw_parent); |
| 150 | + GetClientRect(hwnd_parent, &rc_parent); |
| 151 | + GetWindowRect(hwnd_self, &rw_self); |
| 152 | + |
| 153 | + xpos = rw_parent.left + (rc_parent.right + rw_self.left - rw_self.right) / 2; |
| 154 | + ypos = rw_parent.top + (rc_parent.bottom + rw_self.top - rw_self.bottom) / 2; |
| 155 | + |
| 156 | + SetWindowPos( |
| 157 | + hwnd_self, NULL, |
| 158 | + xpos, ypos, 0, 0, |
| 159 | + SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE |
| 160 | + ); |
| 157 | 161 | } |
| 158 | 162 | |
| 159 | 163 | //+--------------------------------------------------------------------------- |