diff --git a/Aman/AmanWindow.cpp b/Aman/AmanWindow.cpp index 54f1054..b5c62b4 100644 --- a/Aman/AmanWindow.cpp +++ b/Aman/AmanWindow.cpp @@ -124,22 +124,18 @@ void AmanWindow::mouseReleased(CPoint cursorPosClient) { this->doResize = false; } -void AmanWindow::mouseMoved(CPoint cursorPosClient) { - ClientToScreen(hwnd, &cursorPosClient); - - CPoint diff = cursorPosClient - prevMousePosition; +void AmanWindow::mouseMoved(CPoint cursorPosClient, CPoint cursorPosScreen) { + if (menuBar->onMouseMove(cursorPosClient)) { + requestRepaint(); + } + CPoint diff = cursorPosScreen - prevMousePosition; if (this->doResize) { this->resizeWindowBy(diff); } else if (this->moveWindow) { this->moveWindowBy(diff); } - - if (menuBar->onMouseMove(cursorPosClient)) { - requestRepaint(); - } - - prevMousePosition = cursorPosClient; + prevMousePosition = cursorPosScreen; } void AmanWindow::mouseWheelSrolled(CPoint cursorPosClient, short delta) { diff --git a/Aman/AmanWindow.h b/Aman/AmanWindow.h index dd6e0eb..29309ea 100644 --- a/Aman/AmanWindow.h +++ b/Aman/AmanWindow.h @@ -49,7 +49,7 @@ class AmanWindow : public Window { void mousePressed(CPoint cursorPosClient) override; void mouseReleased(CPoint cursorPosClient) override; - void mouseMoved(CPoint cursorPosClient) override; + void mouseMoved(CPoint cursorPosClient, CPoint cursorPosScreen) override; void mouseWheelSrolled(CPoint cursorPosClient, short delta) override; void windowClosed() override; void drawContent(HDC hdc, CRect clientRect) override; diff --git a/Aman/Window.cpp b/Aman/Window.cpp index 6ffd825..817eb5e 100644 --- a/Aman/Window.cpp +++ b/Aman/Window.cpp @@ -6,17 +6,20 @@ Window::Window(const std::string& className, const std::string& windowName) { this->className = className; this->windowName = windowName; - create(); - show(SW_SHOWNORMAL); + if (create()) { + show(SW_SHOWNORMAL); + + // Thread responsible for updating the window + CreateThread(0, NULL, lookForMessages, this, NULL, &threadId); + } - // Thread responsible for updating the window - CreateThread(0, NULL, lookForMessages, this, NULL, &threadId); } Window::~Window() { - SendMessage(hwnd, WM_CLOSE, 0, 0); + DestroyWindow(hwnd); + HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE); + UnregisterClass(className.c_str(), hInstance); WaitForSingleObject(&threadId, INFINITE); - int i = 32; } // Window thread procedure @@ -67,7 +70,7 @@ bool Window::create() { return false; } - HWND hwnd = CreateWindowEx( + HWND tmpHwnd = CreateWindowEx( WS_EX_TOPMOST, className.c_str(), windowName.c_str(), @@ -82,7 +85,7 @@ bool Window::create() { this ); - SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU); + SetWindowLong(tmpHwnd, GWL_STYLE, GetWindowLong(tmpHwnd, GWL_STYLE) | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU); return true; } @@ -121,8 +124,8 @@ LRESULT CALLBACK Window::handleMessage(UINT message, WPARAM wParam, LPARAM lPara switch (message) { case WM_CLOSE: { - DestroyWindow(hwnd); - UnregisterClass(className.c_str(), hInstance); + // Should not close + return 0; } break; case WM_DESTROY: { windowClosed(); @@ -148,7 +151,7 @@ LRESULT CALLBACK Window::handleMessage(UINT message, WPARAM wParam, LPARAM lPara mouseReleased(cursorPosClient); } break; case WM_MOUSEMOVE: { - mouseMoved(cursorPosClient); + mouseMoved(cursorPosClient, cursorPosScreen); } break; case WM_MOUSEWHEEL: { short delta = GET_WHEEL_DELTA_WPARAM(wParam); diff --git a/Aman/Window.h b/Aman/Window.h index dbdcba5..d467ff5 100644 --- a/Aman/Window.h +++ b/Aman/Window.h @@ -17,7 +17,7 @@ class Window { // Should be overridden by child class: virtual void mousePressed(CPoint cursorPosClient) {}; virtual void mouseReleased(CPoint cursorPosClient) {}; - virtual void mouseMoved(CPoint cursorPosClient) {}; + virtual void mouseMoved(CPoint cursorPosClient, CPoint cursorPosScreen) {}; virtual void mouseWheelSrolled(CPoint cursorPosClient, short delta) {}; virtual void windowClosed() {}; virtual void drawContent(HDC hdc, CRect clientRect) {}; @@ -36,6 +36,5 @@ class Window { void show(int nCmdShow); bool processNextMessage(); void render(HWND hwnd); - bool exit; };