Page 1 of 2

Posted: Thu Jan 11, 2007 1:29 am
by srod
Here you are. This is pretty rough around the edges, but it seems to work reasonably well! There's probably better ways.

Win xp only.

Code: Select all

Global timerset

Procedure TimerProc(uID, uMsg, dwUser, dw1, dw2) 
If timerset = 0
  Debug "Single click!"
EndIf
timerset=0
EndProcedure 


If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateGadgetList(WindowID(0))
    ListIconGadget(0, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(0, 1, "Address", 250)
    AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
    AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
    Repeat
      Event = WaitWindowEvent()
      Select Event
        Case #PB_Event_Gadget
        If EventGadget()=0
          Select EventType()
            Case #PB_EventType_LeftClick
              timeSetEvent_(200,10,@TimerProc(),0, #TIME_ONESHOT)
            Case #PB_EventType_LeftDoubleClick
              timerset=1
              Debug "Double click!"

          EndSelect
        EndIf
      EndSelect
      
     Until Event = #PB_Event_CloseWindow
   EndIf
 EndIf

Posted: Thu Jan 11, 2007 3:50 am
by rsts
Pretty darn slick. Now to revisit all my doubleclick routines :)

cheers

Posted: Thu Jan 11, 2007 11:10 am
by srod
Be careful though as you need to ensure that the timer count:

Code: Select all

timeSetEvent_(200,10,@TimerProc(),0, #TIME_ONESHOT) 
200 milliseconds in this case, is enough to ensure that a double-click can pass, but not too long that you notice the delay.

On my system, the max double-click delay is 500 milliseconds, i.e. 0.5 of a second but because the #WM_LBUTTONDOWN message takes time to process, I had to settle for a count of 200. This obviously depends upon the speed of your system.

You might be better using something like:

Code: Select all

timeSetEvent_(GetDoubleClickTime_()/2, 10, @TimerProc(), 0, #TIME_ONESHOT) 
etc.

Posted: Fri May 25, 2007 4:33 pm
by rsts
Guess I'll resurrect this topic.

I have a program that handles single and double clicks on a listicongadget.

All was fine until I needed to change the single click routine to read a record from a sqlite database (The single click process was previously just internal processing from a linked list).

Now, I find it next to impossible to consistently recognize the doubleclick. Best performance is if I doubleclick very slowly, but even that is not concistent and not a very good solution.

I was playing with srod's method above, but it was also very inconsistent and I need the solution to be cross windows not just XP, so couldn't really use it anyway.

I'm processing the events via normal #PB_EventType_LeftClick and #PB_EventType_LeftDoubleClick, but have a callback in the program if there's a callback solution.

Any reason why the processing in the singleclick routine so negatively impacts the recognition of the doubleclick by windows?

The sequence of events is not a problem as I want to perform the singleclick processing even if there's a doubleclick. It's just that since the singleclick process 'slowed down' due to the database read, I can't cocsistently recognize the doubleclick.

Does this make sense or am i once again lost in the wilderness?

cheers

Posted: Fri May 25, 2007 5:46 pm
by netmaestro
You could try my version here:

http://www.purebasic.fr/english/viewtop ... 81&start=3

Upon getting a single click it waits to see if it'll change to a doubleclick. You can insert your action code so that if it's a doubleclick it does both actions, and doesn't do the singleclick action by itself unless it really didn't change to a double. That way you're not being held up as the timing is always the same.

Posted: Fri May 25, 2007 6:02 pm
by rsts
Thanks once again, I'll give this method a try.

Still trying to figure out why this didn't show up on my search? I thought I had done one just on doubleclick, but may have searched on doubleclick and listicon. I try so many, I tend to get confused :)

cheers

Posted: Fri May 25, 2007 6:35 pm
by rsts
That seems to have done it, Mr Hero. :)

I had tried some things that were attempts at something like this, but didn't know you could 'nest' the waitwindowevent because I seem to have misinterpreted the help explanation "WaitWindowEvent() can only be called once per event loop" to meaning that couldn't be done.

To top it all off, I had seen this 'tip' when you first posted it, but couldn't locate it when I searched.

Oh well, all's well that ends with a netmaestro solution :) What a contributor!

cheers

Posted: Fri May 25, 2007 6:40 pm
by netmaestro
Thanks for the kind words, I'm glad it's getting sorted out.

The help doc for WaitWindowEvent() is left over from an earlier time, before you could put a parameter in. So another WaitWindowEvent() without the parameter would indeed lock up the loop, but with the 1ms timeout it's all good.

Posted: Fri May 25, 2007 10:42 pm
by Edwin Knoppert
Windows API GetDoubleClickTime() can be used to determine the maximum time to make it a real doubleclick.

A doubleclick is determined by classstyle CS_DBLCLKS

-- Edit:
I overlooked an earlier response about the API :)