Dimi, if you think this is ugly, or if you are working on a better
solution,
please do protest.
Well, in part it's a matter of style, and IMO this will clutter the code. Moreover, the patch as it is now works by accident. For example:
/* send NM_RELEASEDCAPTURE notification */ - notify(infoPtr, NM_RELEASEDCAPTURE); + notify(infoPtr->hwndSelf, NM_RELEASEDCAPTURE);
if (!infoPtr->bFocus) SetFocus(infoPtr->hwndSelf);
See, after the notify() the infoPtr may be invalid. This means that if we assume the control can be deleted at any point we send out a notification, we have to reget and recheck infoPtr after every function call. There's got to be a better way.
I personally think an exception-based solution would be better. This is what exceptions where invented. I know they look alien in C, but I use them every day in Java for good effect. It's true, we have to be careful to release resources along the way, but we have only 6 such allocations that need protecting, and they are localized. And there we already have a try/catch simulated with goto's.
Another approach may be to ref count the structure pointed to by infoPtr, and release it at exit from WinProc when the count is 0. Sort of a poor man's garbage collection. I'm cool with this too, and in fact it may be cleaner then the exception-based solution.