I guess things like this happen to you when you perform Sunday morning programming. My app got a WM_LBUTTONUP without a preceding WM_LBUTTONDOWN... And since that happened before any other button down/up activity in the application, some things were not setup properly "yet" so the app crashed.
The problem was not so much to fix the crash, as to understand what was going on and how to reproduce it. I was using the app when this happened, no other app was involved, so how could I possibly get a button up without a preceding button down?
So here is what happens and how to verify it.
First open an instance of Notepad, make its window have a relatively small size and position it somewhere around the center of your monitor.
Then open Spy++ (you are a developer, right?) and press Alt+F3 to open the Find Window dialog. Select the edit window inside Notepad and click OK (Notepad must be opened first otherwise Spy++ will complain it cannot find the window, in which case go to the main window and refresh). Right click on the window and select "Messages" to start logging the message traffic for this window. Then press CTRL+o to open the logging options dialog.
Go to the Messages tab, Clear All and then select only the Mouse messages as shown below:
Click OK and press DEL to clear any messages that have already been logged.
Now move the mouse carefully, so that it does not enter the edit control client area, and position it on Notepad's caption bar. Double click the caption bar to maximize Notepad's window and then take a look at the messages logged by Spy++:
Ooops... Where did this WM_LBUTTONUP come from? ;-) You can guess what happens... As soon as the window manager sees the double click message it resizes the window, releases mouse capture (probably it had it) and then the button up message from the 2nd click lands in whatever happens to be under the mouse location of the double click. Since the window got maximized, that location is now occupied by the edit control in Notepad.
Most likely the same thing would happen the other way round, if a maximized window gets restored with a double click. The final button up message will land on whatever was underneath, but usually at that part of the screen you will find another window's caption bar, so no harm done.
I tried to reproduce this situation using Notepad in conjunction with other apps, clicking inside the other app then dragging and releasing over Notepad's edit control, but I could not get this situation to happen, even using my favorite trick which is move the mouse over the target app and while holding it clicked use ALT+TAB to switch to the target app, then release the mouse. Everybody was capturing the mouse properly.
If you can find another way to "naturally" reproduce this condition (i.e. not by sending programmatically an unpaired WM_LBUTTONUP message to the window) please be kind enough to let me know!