image ResEx Logo
ResExcellence www : Powered by Google
Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Articles
   3D
   Audio
   Custom Controls
   General RB
   Graphics
   Hacks
   Mac OS X
   Menus
   Novelty
   Printing
   REALbasic 2005
   REALbasic 2006
   Registration
   Resources
   Reviews
   Serial
   Speech
   Sockets
   XML
   Video
Resource Links
News
   Current News
   February 2006
   January 2006
   December 2005
   November 2005
   October 2005
   September 2005
   August 2005
   July 2005
   June 2005
   May 2005
   April 2005
   March 2005









REALbasic for Dummies
by Erick Tejkowski


Learning REALbasic through Applications
by Clayton E., Crooks II


REALbasic for Macintosh
by Michael Swaine


REALbasic Cross-Platform Application Development
by Mark S. Choate





Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander
Tell us about a bad link. Thank You!

Double Click Canvas by Seth Willits
01-17-04

Printer Version




Double Clicks
Well, I don't suppose I need to tell you what double clicks are, so I guess I'll just tell that we're going to make a canvas subclass which accepts double clicks on every platform, using the actual system double click time!

Design
Okay, it's really simple. Create a new class named "DblClickCanvas" with a super of Canvas. Create one new event named "DoubleClick", a property "mLastClickTicks as Integer", and a new protected method "WasDoubleClick() as Boolean". (Note that the image below doesn't show that it's protected. I'm too lazy to make a new image!) In the MouseDown event of our canvas we'll return true so that the MouseUp event is called. In the MouseUp event we'll simply ask: "if WasDoubleClick then DoubleClick" which will call the DoubleClick event when appropriate.

The WasDoubleClick Method
On the Mac, the toolbox command GetDblTime() returns the maximum number of ticks that can pass between clicks. On Windows, the function GetDoubleClickTime() returns the maximum number of milliseconds. What we'll do is convert the milliseconds value on windows into ticks by dividing by 1000 and multiplying by 60 (a tick is 1/60th of a second) to make the very very core of the code the same for each platform.

The code to get the double click time in ticks for every platform is:

dim doubleClickTime as Integer

#if TargetCarbon then
   Declare Function GetDblTime Lib "CarbonLib" () as Integer
   doubleClickTime = GetDblTime()
#else
   #if TargetMacOS then
      Declare Function GetDblTime Lib "InterfaceLib" () as Integer
      doubleClickTime = GetDblTime()
   #endif
#endif
#if TargetWin32 then
   Declare Function GetDoubleClickTime Lib "User32.DLL" () as Integer
   doubleClickTime = GetDoubleClickTime() / 1000 * 60
#endif

Once you have the doubleClickTime, all you need to do is check that the difference of the current time and the time of the last click (mLastClickTicks) is less than or equal to it! If it is, we return true. Regardless of whether it is or isn't, we always need to set mLastClickTicks to the current Ticks value since we need to record the time of each click.

// If the two clicks happened close enough together in time
if (Ticks - mLastClickTicks) <= doubleClickTime then
   return true
end if
mLastClickTicks = Ticks

The Finished Product
That's all there is to it. Drag an instance of the DblClickCanvas class to a window and put some code in the DoubleClick event. Pretty simple! You can download the project here.

(Click on the image for a full view of the class)




Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement. [an error occurred while processing this directive]