hWnd = CreateWindow(... RECT rect; // Notice we don't use GetClientRect, //this is because we want the Window size and not the Client size. GetWindowRect(hWnd, &rect); HRGN hRgn = CreateRoundRectRgn(0, 0, rect.right - rect.left, rect.bottom - rect.top, 20, 20); // Set the new region SetWindowRgn(hWnd, hRgn, false);
// Now it's time to draw the new window. ShowWindow(hWnd, ...)
In the WinProc, we will have to process the WM_SIZING message:
case WM_SIZING:{ static POINT lastPos; POINT p; GetCursorPos(&p); // If it's the same old position, ignore this resizing. if (memcmp(&p, &lastPos, sizeof(POINT))) { HRGN hRgn = CreateRoundRectRgn(0, 0, ((PRECT)lParam)->right - ((PRECT)lParam)->left, ((PRECT)lParam)->bottom - ((PRECT)lParam)->top, 20, 20); SetWindowRgn(hWnd, hRgn, true); // Redraw window. lastPos = p; return 1; // We processed the message. } lastPos = p; }return 0; // This time, we didn't. case WM_SIZE:{ if (wParam != SIZE_MINIMIZED && wParam != SIZE_MAXHIDE) { RECT rect; GetWindowRect(hWnd, &rect); HRGN hRgn = CreateRoundRectRgn(0, 0, rect.right - rect.left, rect.bottom - rect.top, 20, 20); SetWindowRgn(hWnd, hRgn, true); // Redraw window. } }return 0;
// Cleanup: none // The system knows to delete the region object, // don't touch it once you called SetWindowRgn. |