Here guys, I wrote a little hook to get the WM_CLOSE event from GDK without affecting how GDK works. Its slightly less efficient because of the extra function call, but I think it should be ok.
#include <windows.h>
LONG_PTR GDK_wndproc;
bool GDK_CLOSING = false;
LRESULT CALLBACK newWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CLOSE:
GDK_CLOSING = true;
The_Console.Console_Dprintf("Main: Shutting Down...");
break;
}
return CallWindowProc((WNDPROC)GDK_wndproc, hWnd, msg, wParam, lParam);
}
void DarkGDK()
{
HWND hwnd = g_pGlob->hWnd;
GDK_wndproc = GetWindowLongPtr(hwnd, GWLP_WNDPROC);
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)newWndProc);
}
You can just query GDK_CLOSING to see if gdk is trying to close. This is useful if you have many threads, etc running that you want to exit gracefully in the event that gdk is closing.
EDIT: removed a useless line of code from the listing.