Anybody for a challenge? This one has beat me.

Ive got a VB6 project with a HookWindow to capture windows events for an MDI form. Using the X to close the form in Windows98, tool tip 'Close' appears just before the MDI form closes.

Windows raises an event to erase the background left by the tool tip just before it raises the Deactivate, QueryUnload etc. So basically, the VB is trying to repaint but the form is unloading taking all the resources first so it all goes horribly wrong. When the MDI form completes its unload which should be the end of the exe, the HookWindow cannot be killed because it still has the repaint event pending. This causes the MDI form to relaunch itself when further messages are raised!!

Can anyone think of a way to stop the repaint event OR to distinguish that its the repaint event from the close button.

We cant turn the tool tips off 'cause they're in the current user bit of the registry. We cant wait in the QueryUnload till the repaint finishes because once you've pressed the X it doesnt seem to let the repaint event finish anyway, even if you're waiting in code.