WM_LBUTTONDBLCLK strange behavior

I want drawn ellipses to 'disappear' on double click. To do so, the canvas is redrawn, and the nondoubleclicked ellipses are restored. When I use the doubleclick case instead of the rightclick case, the earlier deleted ellipses appear again on the canvas. Any idea on how to let WM_LBUTTONDBLCLK behave exactly as WM_RBUTTONDOWN?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  case WM_LBUTTONDBLCLK: {//
	   		//case WM_RBUTTONDOWN:  {
	   			hdcx[n] = BeginPaint(hwnd, &ps);
	    		hdcx[n] = GetDC(hwnd);

	    		//Delete double-clicked circles
	   			for(int i = 0; i < n; i++){
			   		x = LOWORD(lParam);
	    	 		y = HIWORD(lParam);
	   				DeleteObject(hdcx[i]);
	   			}
   				RedrawWindow(hwnd, &lprcUpdate, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);

   				//Restore other undragged circles
   				for(int i = 0; i < n; i++){
					hdcx[i] = BeginPaint(hwnd, &ps);
					hdcx[i] = GetDC(hwnd);
   					if((x <= X[i]+12 && x >= X[i]-12 && y <= Y[i]+12 && y >= Y[i]-12)){
   						mybool2[i] = true;
   					}
   					else if(mybool2[i] == false){
   						if(NoteDuration[i] == 1.0){
        				    HBRUSH hbr=CreateSolidBrush(RGB(255,255,255)); /*white brush*/
        				    HBRUSH hOld=(HBRUSH)SelectObject(hdcx[i],hbr);
   							Ellipse(hdcx[i], X[i], Y[i], X[i]+12, Y[i]+12);
   						}
   						else if(NoteDuration[i] == 0.5){
        				    HBRUSH hbr=CreateSolidBrush(RGB(255,255,255)); /*white brush*/
        				    HBRUSH hOld=(HBRUSH)SelectObject(hdcx[i],hbr);
   							Ellipse(hdcx[i], X[i], Y[i], X[i]+12, Y[i]+12);
   							MoveToEx(hdcx[i], X[i]+12, Y[i]+6, 0);
   							LineTo(hdcx[i],X[i]+12, Y[i]-28);
   						}
        				else if(NoteDuration[i] == 0.25){
        				    HBRUSH hbr=CreateSolidBrush(RGB(0,0,0)); /*black brush*/
        				    HBRUSH hOld=(HBRUSH)SelectObject(hdcx[i],hbr);
        					Ellipse(hdcx[i], X[i], Y[i], X[i]+12, Y[i]+12);
        	    			MoveToEx(hdcx[i], X[i]+12, Y[i]+6, 0);
        	    			LineTo(hdcx[i],X[i]+12, Y[i]-28);
        	    		}
   					}
   				}

	   			break;
	   		}
Your code looks insane to me.
Any idea on how to let WM_LBUTTONDBLCLK behave exactly as WM_RBUTTONDOWN?


Counterquestions: OS did really trigger WM_LBUTTONDBLCLK? In your code there is for sure no WM_LBUTTONDOWN or WM_LBUTTONCLICK or similar that acts already on a normal left mouse button down? Typically the double click tend to trouble such they trigger immediately the single click variant and after a "double click delay" the OS also triggers the doulbe click message.
@dutch, after I cleaned my monitor from the spit laugh, I note that while this code is typical of the C era of Windows programming, it is a bit....much.

@bchinfosieeuw, what dutch is pointing to is the fact that the code here should be inside functions representative of the acts, so the large switch this is obviously inside isn't digging a hole into the Earth.

That said, let's focus on what I THINK I understand to be your question.

I THINK you're saying that when you implement this as a case for right button down, it works, but not when the case is left double click.

So, I have to ask, what does your code do for LButtonDown and/or LButtonUp?

All double click logic must acknowledge that button downs and ups will appear before the double click can be "sensed" and then acknowledged. As a result, all double click interface design must be in the context of a single click first (usually selection of some kind), upon which the additional action of the double will be enacted, and the redundant single click is of not negative influence on the result.

That is USUALLY what interferes here. There is no such thing as a double click without single clicks, and no good reliable way of avoiding the single click (it would require you note but do not act on the single click, then wait long enough for a double click timeout to pass before acting on the single click - not fun).

@Niccolo, I was thinking more of hdcx[n] getting the return value of BeginPaint and then overwriting that with the return value of GetDC (possibly writing both outside the array), then calling DeleteObject on every member (while assigning x and y over and over again from the params for no reason), then grabbing another BeginPaint/GetDC pair into the same hdcx element IN A LOOP with no releases ... yikes.

Anyway, your explanation of what is probably his underlying problem is interesting. As you say, the best design is where you want the single-click action as the first part of an extended double-click action. Otherwise you need to fool around with a timers, but at that point you're pretty much beginning to re-implement the double-click logic.

To do it you would probably turn off the setting to receive double-click methods automatically (which presumably involves it's own timer) and do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
WM_LBUTTON_DOWN:
    if double-click timer is not running:
       start double-click timer
    else:
       stop double-click timer
       do double-click logic
    break       

WM_TIMER:
    if double-click timer expired:
        stop double-click timer (if needed(?))
        do single-click logic
    break

But that kind of logic can make the single click seem a little unresponsive since it can't repsond until the timer ends.
Last edited on
I managed to solve my problem myself using your tips. Thank you.
@dutch


I was thinking more of hdcx[n] getting the return value of BeginPaint and then overwriting that with the return value of GetDC (possibly writing both outside the array), then calling DeleteObject on every member (while assigning x and y over and over again from the params for no reason)


My eyes glazed over before I got far enough to notice any of that.

I just started in with the notion that a double click was being attempted in place of a right click, and that's hardly ever going to work right. I assumed OP was saying the right click worked, and just letting the rest of that lexical debris be what it is.


...at that point you're pretty much beginning to re-implement the double-click logic.


Which is quite ugly UI (users wonder why the left click is sluggish). Better to consider the old left hold/right click thing, or maybe go with control/alt/command modifiers.



@bchinfosieeuw, It would be interesting to know what helped.
Last edited on
Topic archived. No new replies allowed.