Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent a double-click on an Open File dialog from registering a click on the form under it?

I have a custom control that's essentially a drawing canvas, and a program that uses it for editing files. When a new file is opened, though, something very strange can happen.

If the user double-clicks on the file in the Open File dialog (standard TOpenDialog control) instead of selecting an item and hitting ENTER, the canvas underneath registers a click event and ends up executing a draw action at the position of the cursor immediately after loading is complete.

Obviously this is not the intended behavior for this. I've noticed before that when you double-click the mouse, the double-click message arrives before the second click message. I think the dialog box might be closing from the double-click, and then the second click message arrives and gets sent to whatever's at the appropriate coordinates now that it's gone.

Is there any way I can make this stop happening? I can't tell my code "after loading, just eat the next click," because it could have been opened with the 'ENTER' key instead, and then it would miss the first legitimate click. Can anyone think of a better way to handle this? (Using Windows 7, in case it makes a difference.)

like image 947
Mason Wheeler Avatar asked Feb 04 '13 01:02

Mason Wheeler


1 Answers

If there's a "second click message," there's something wrong. (For one thing, Windows doesn't have "click" messages, just mouse-up and mouse-down messages.) A double click goes like this: mouse down, mouse up, double click, mouse up. The dialog disappears between the double-click message and the second mouse-up message. If your control receives the mouse-up message and treats it as a full click, then that explains the issue and you need to stop; a click is always a pair of mouse-down and mouse-up messages. If you haven't gotten both, then it's not a click.

like image 167
Rob Kennedy Avatar answered Sep 17 '22 14:09

Rob Kennedy