Hi,
as far as I tested, the window callback function always receive the window destroying message.

Code:
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;
	...



Salud!