Skip to content

Commit

Permalink
windows: only quit once the last window has been closed
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Sep 18, 2024
1 parent b3fde41 commit 77544f8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gral_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ static ID2D1StrokeStyle *stroke_style;
static IWICImagingFactory *imaging_factory;
static IDWriteFactory *dwrite_factory;
static DWORD main_thread_id;
static int window_count = 0;

struct gral_draw_context {
ID2D1HwndRenderTarget *target;
Expand Down Expand Up @@ -490,7 +491,10 @@ static LRESULT CALLBACK window_procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LP
window_data->target->Release();
}
delete window_data;
PostQuitMessage(0);
window_count--;
if (window_count == 0) {
PostQuitMessage(0);
}
return 0;
}
default:
Expand Down Expand Up @@ -921,6 +925,7 @@ gral_window *gral_window_create(gral_application *application, int width, int he
window_data->cursor = LoadCursor(NULL, IDC_ARROW);
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)window_data);
ShowWindow(hwnd, SW_SHOW);
window_count++;
return (gral_window *)hwnd;
}

Expand Down

0 comments on commit 77544f8

Please sign in to comment.