LRESULT CALLBACK onMsgOld (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK myMsg (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
if (message == WM_DESTROY) {
// do whatwever you need at window destroying time
}
return onMsgOld(hwnd, message, wParam, lParam);
}
void main () {
onMsgOld = on_message;
on_message = myMsg;
...