Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <windowsx.h>
- HWND CreateTestWindow(WNDPROC);
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
- static bool moving{};
- switch (msg) {
- case WM_DESTROY: {
- PostQuitMessage(0);
- return 0;
- }
- case WM_LBUTTONDOWN: {
- moving = true;
- return 0;
- }
- case WM_LBUTTONUP: {
- moving = false;
- return 0;
- }
- case WM_MOUSEMOVE: {
- static POINT old{0, 0};
- if (moving) {
- RECT r;
- GetWindowRect(hwnd, &r);
- int x = GET_X_LPARAM(lParam);
- int y = GET_Y_LPARAM(lParam);
- RECT newPos;
- newPos.left = r.left + x - old.x;
- newPos.top = r.top + y - old.y;
- SetWindowRgn(hwnd, nullptr, FALSE);
- SetWindowPos(hwnd, nullptr, newPos.left, newPos.top, 0, 0,
- SWP_NOZORDER | SWP_NOSIZE | SWP_NOREDRAW
- );
- SetWindowRgn(hwnd, CreateEllipticRgn(200, 200, 600, 400), FALSE);
- }
- old.x = GET_X_LPARAM(lParam);
- old.y = GET_Y_LPARAM(lParam);
- return 0;
- }
- }
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- int main() {
- HWND hwnd = CreateTestWindow(WndProc);
- SetWindowRgn(hwnd, CreateEllipticRgn(200, 200, 600, 400), TRUE);
- MSG msg;
- while (GetMessage(&msg, nullptr, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- HWND CreateTestWindow(WNDPROC f) {
- WNDCLASS wc;
- ZeroMemory(&wc, sizeof wc);
- wc.hInstance = GetModuleHandle(nullptr);
- wc.lpfnWndProc = f;
- wc.lpszClassName = "Test Window Class";
- wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1);
- RegisterClass(&wc);
- return CreateWindow("Test Window Class", "Test Window",
- WS_OVERLAPPEDWINDOW | WS_VISIBLE,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- nullptr, nullptr, GetModuleHandle(nullptr), nullptr
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement