There's a fairly easy way to accomplish this, actually. If you create a new window, Windows API style, the GDK doesn't respond properly, and the new window is controlled with the old window's frame. When the X is hit, the new window is sent WM_DESTROY and closes, doing apparently nothing to the window, but creating an event you can then use to do whatever you want, then close the GDK window with a return. I'll make an example if I have time later.
EDIT:
I worked it out a bit, and the window double-draw method works, but not exactly correctly. The GDK catches the new window's closing and prevents it from handling the message WM_DESTROY on its own. To see what I mean, I've got a quick code snippet.
#include "DarkGDK.h"
#include <windows.h>
#include <globstruct.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "WindowsApp";
void BeforeExit(void);
void DarkGDK ( void )
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
HWND minWindow;
MSG minWmessages;
WNDCLASSEX minWwincl;
hwnd = CreateWindowEx (
0,
szClassName,
"Extra Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
550,
400,
g_pGlob->hWnd,
NULL,
g_pGlob->hInstance,
NULL
);
ShowWindow(hwnd,1);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
dbSetWindowTitle("Attention");
dbSyncOn();
dbSync();
dbSetTextFont("Tahoma");
dbSetTextSize(48);
dbCenterText(dbScreenWidth()/2,dbScreenHeight()/4,"Click the close button.");
dbSync();
dbWaitKey();
return;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
BeforeExit();
PostQuitMessage(0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
void BeforeExit(void){
MessageBox(g_pGlob->hWnd,"This ran before the program exited.","Attention!",MB_OK);
return;
}
If you compile and run that, the message box is never made, and therefore BeforeExit(); doesn't get called, like it should according to the switch that handles the second window's messages.
Sorry, this method isn't going to work. However, I've heard of some people catching windows messages with the GDK, perhaps you'd be able to do that instead?
My site, for various stuff that I make.