Skip to content

Commit

Permalink
Fix resize and make window not closeable
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenAR committed Dec 16, 2020
1 parent 257fb4b commit a5f2684
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
16 changes: 6 additions & 10 deletions Aman/AmanWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Aman/AmanWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 14 additions & 11 deletions Aman/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,7 +70,7 @@ bool Window::create() {
return false;
}

HWND hwnd = CreateWindowEx(
HWND tmpHwnd = CreateWindowEx(
WS_EX_TOPMOST,
className.c_str(),
windowName.c_str(),
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions Aman/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {};
Expand All @@ -36,6 +36,5 @@ class Window {
void show(int nCmdShow);
bool processNextMessage();
void render(HWND hwnd);
bool exit;
};

0 comments on commit a5f2684

Please sign in to comment.