AND51 wrote:This is just an idea.
You commented your own idea even before you said it, here it is :
AND51 wrote:LOL...
This is epic LOL
If you doubleclick on gadget then WaitWindowEvent() will return two times, first time left click and second time double click because in reality you actually click two times (two left clicks), and OS calculates time passed from last click to generate doubleclick event if you clicked fast enough second time, so no matter how you arrange your cases, they both will be processed.
There is probably no other way than coding custom timer calculation to check for doubleclick...
Here is my quick attempt, it is not perfect, feel free to enhance it
Code: Select all
EnableExplicit
Global SysDoubleClickDelayMs = 500 ; According to Microsoft's MSDN website, the default timing in Windows is 500ms; change this value with some api which returns current sys doubleclick interval in milliseconds because users can edit this value in Control Panel
Global LastTimeOfLeftClick=-1
Global LeftClickOnlyProcessed=#True
Global lastMousePos_x=0
Global lastMousePos_y=0
Global currMousePos_x=0
Global currMousePos_y=0
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#Image_0
#ListView_1
EndEnumeration
;}
;{ Images
Enumeration
#Image_Image_0
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure CheckClick(void)
Repeat
If LastTimeOfLeftClick<>-1
If (ElapsedMilliseconds()-LastTimeOfLeftClick)>SysDoubleClickDelayMs
LeftClickOnlyProcessed=#False
Repeat : Delay(1) : Until LeftClickOnlyProcessed=#True
EndIf
EndIf
Delay(1)
ForEver
EndProcedure
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 450, 200, 400, 181, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
;If CreateGadgetList(WindowID(#Window_0))
ImageGadget(#Image_0, 13, 14, 180, 158, 0, #PB_Image_Border)
CreateThread(@CheckClick(),0)
ListViewGadget(#ListView_1, 211, 15, 151, 158)
;EndIf
EndIf
EndProcedure
CreateImage(0, 180, 158)
OpenWindow_Window_0()
;{- Event loop
Repeat
Event = WaitWindowEvent(1)
If Event=0
If LeftClickOnlyProcessed=#False
Event=#PB_Event_Gadget
EventGadget = #Image_0
EventType = #PB_EventType_LeftClick
Else
Continue
EndIf
EndIf
Select Event
; ///////////////////
Case #PB_Event_Gadget
If LeftClickOnlyProcessed=#True
EventGadget = EventGadget()
EventType = EventType()
EndIf
If EventGadget = #Image_0
If EventType = #PB_EventType_LeftClick
currMousePos_x=WindowMouseX(#Window_0)
currMousePos_y= WindowMouseY(#Window_0)
If (currMousePos_x<>lastMousePos_x) Or (currMousePos_y<>lastMousePos_y)
If LastTimeOfLeftClick<>-1
LeftClickOnlyProcessed=#False
EndIf
EndIf
lastMousePos_x=currMousePos_x
lastMousePos_y=currMousePos_y
LastTimeOfLeftClick=ElapsedMilliseconds()
If LeftClickOnlyProcessed=#False
AddGadgetItem(#ListView_1, -1, "Left Click :-(")
LeftClickOnlyProcessed=#True
LastTimeOfLeftClick=-1
EndIf
ElseIf EventType = #PB_EventType_LeftDoubleClick
LastTimeOfLeftClick=-1
AddGadgetItem(#ListView_1, -1, "Left Double Click :-)")
LeftClickOnlyProcessed=#True
EndIf
ElseIf EventGadget = #ListView_1
EndIf
; ////////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
CloseWindow(#Window_0)
Break
EndIf
EndSelect
ForEver
;
;}