<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bc-programming &#187; subclassing</title>
	<atom:link href="http://bc-programming.com/blogs/category/subclassing/feed/" rel="self" type="application/rss+xml" />
	<link>http://bc-programming.com/blogs</link>
	<description>Programming, Possums, Ponies, and why you shouldn&#039;t mix any two.</description>
	<lastBuildDate>Wed, 16 May 2012 23:06:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Triple-Clicks revisited: implementing N-Clicks</title>
		<link>http://bc-programming.com/blogs/2009/11/triple-clicks-revisited-implementing-n-clicks/</link>
		<comments>http://bc-programming.com/blogs/2009/11/triple-clicks-revisited-implementing-n-clicks/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 15:59:30 +0000</pubDate>
		<dc:creator>BC_Programming</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[subclassing]]></category>
		<category><![CDATA[Theory]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://bc-programming.com/blogs/?p=22</guid>
		<description><![CDATA[In my previous entry, I discussed and provided code that would allow for the detection of Triple-Clicks on a window. By extending the provided architecture, it is relatively trivial to allow any number of consecutive clicks; for example, detecting pentuple clicks. The revisions are pretty easy; in my case, I created a structure to hold [...]]]></description>
			<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://bc-programming.com/blogs/2009/11/triple-clicks-revisited-implementing-n-clicks/" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>In my previous entry, I discussed and provided code that would allow for the detection of Triple-Clicks on a window. By extending the provided architecture, it is relatively trivial to allow any number of consecutive clicks; for example, detecting pentuple clicks.</p>
<p> <span id="more-22">  </span> </p>
<p>The revisions are pretty easy; in my case, I created a structure to hold what I previous had in a few module-level variables, to keep track of various data about each consecutive &#8220;click set&#8221; if that is a proper word to use here. Things such as the first click position, the last click position (these will obviously be the same for the &#8220;first&#8221; consecutive click (which is just a single-click, really) but could be used in later clicks to compare the distance values used, retrieved via GetSystemMetrics() using the SM_DRAGX and SM_DRAGY constants,(or was it SM_XDRAG and SM_YDRAG&#8230;) and comparing these values with the difference between each successive click. The ideal solution would be to compare each click position with the first click position, so that the clicking cannot move across the object very far from where the first click took place. The logic is pretty simple, and should be easy to follow. The project can be downloaded from  <a href="http://bc-programming.com/downloads/files/multiclick.zip"> here </a> .This is a tad different then the previous one, and is instead implemented as a sort of  &#8220;game&#8221;.</p>
<p>There are a few design and User interface considerations when using Multiple clicks in your UI; the most prevalent is probably that unless you tell your users that they can triple-click or quadruple click, they likely will not try it- that is, it isn&#8217;t really that intuitive. Additionally, when you do implement this behaviour, remember that, for example, with a triple click, a double click was already fired and handled before that; so don&#8217;t make successive clicks do vastly different things. the ideal scenario is to use successive clicks to do the same thing, but change the scope; for example, Word allowed you to click,double-click, and triple click text. the first click sets the position of the cursor, the second click selects the word that the cursor is in, and a triple click selects a paragraph. (In the outlook editor it actually selects the sentence I think, but let&#8217;s not split hairs&#8230;). In fact, it would make sense to conclude that as an unsaid rule you should only use triple clicks to build on behaviour that the single and double-clicks before them have already done, just as word does. if you make triple-clicks do something esoteric, such as, for example, triple clicking a drawing to save, consider instead opting for a toolbar button or menu item to perform this task, or perhaps a key combination (or both). </p>
<div id="fcbk_share"><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://bc-programming.com/blogs/2009/11/triple-clicks-revisited-implementing-n-clicks/" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://bc-programming.com/blogs/2009/11/triple-clicks-revisited-implementing-n-clicks/&via=BC_Programming&text=Triple-Clicks revisited: implementing N-Clicks&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div> <p><a href="http://bc-programming.com/blogs/?flattrss_redirect&amp;id=22&amp;md5=3965d436946ca86a4167d158f0899aeb" title="Flattr" target="_blank"><img src="http://bc-programming.com/blogs/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://bc-programming.com/blogs/2009/11/triple-clicks-revisited-implementing-n-clicks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=bc_programming&amp;popout=1&amp;url=http%3A%2F%2Fbc-programming.com%2Fblogs%2F2009%2F11%2Ftriple-clicks-revisited-implementing-n-clicks%2F&amp;language=en_GB&amp;category=software&amp;title=Triple-Clicks+revisited%3A+implementing+N-Clicks&amp;description=In+my+previous+entry%2C+I+discussed+and+provided+code+that+would+allow+for+the+detection+of+Triple-Clicks+on+a+window.+By+extending+the+provided+architecture%2C+it+is+relatively+trivial+to...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>Detecting Triple-Clicks</title>
		<link>http://bc-programming.com/blogs/2009/11/detecting-triple-clicks/</link>
		<comments>http://bc-programming.com/blogs/2009/11/detecting-triple-clicks/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 07:58:26 +0000</pubDate>
		<dc:creator>BC_Programming</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[subclassing]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://bc-programming.com/blogs/?p=19</guid>
		<description><![CDATA[Visual Basic 6; and, well- nearly any other relatively modern language; provides a way to detect mouse events. These usually include mouse down, mouse up, mouseclicks, and double clicks. Absent are any higher &#8220;N-clicks&#8221;; I speak, for the most part, of the triple click. The triple-click is a awkward sort of mouse input; but it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://bc-programming.com/blogs/2009/11/detecting-triple-clicks/" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>Visual Basic 6; and, well- nearly any other relatively modern language; provides a way to detect mouse events. These usually include mouse down, mouse up, mouseclicks, and double clicks. Absent are any higher &#8220;N-clicks&#8221;; I speak, for the most part, of the triple click. <span id="more-19">  </span> </p>
<p>The triple-click is a awkward sort of mouse input; but it&#8217;s quite simple to detect. It&#8217;s three clicks in a row. However, this is not what the program will see. For the most part, the program will see Mousedown,Mouseup,mousedown,doubleclick,mouseup; that is, windows will replace the mouse-down with the double-click message.</p>
<p>Visual Basic, and of course a number of other programming environments, translate windows messages into events of some sort. Specifically, Visual Basic has Click, Double-Click, mouseup, and mousedown. the behaviour and ordering mentioned above can be seen if one is  to log the events as they occur.</p>
<p>Detecting triple clicks is pretty easy, however; the idea is that a &#8220;triple click&#8221; is when you click three times and each click is within the double-click time from the previous click. this is easily facilitated by recording the DoubleClick time and testing the difference between the next click time and the previous click, and, if it is less then the doubleclicktime() (retrieved by the GetDoubleClickTime() API function) then register it as a TripleClick.</p>
<p>But such a mess! why not make a reusable class that can be used whenever triple-click functionality is desired? This is how I handle this type of problem- a missing event; I usually create a new class that raises that event, and only requires to be initialized and told what object it&#8217;s checking.Thus is born the CTripleClick class.</p>
<p>But exactly how, from the class&#8217;s perspective, does it achieve it&#8217;s functionality? There are actually a few options, of different complexity- the easiest, and maybe the safest, would be to use the Visual Basic &#8220;withevents&#8221; keyword on the object in question. However, this is problematic in that the CTripleClick Class is intended for use in various scenario&#8217;s- it might be used to detect triple-clicks on commandbuttons, pictureboxes, forms, usercontrols, and any number of other objects. Withevents, however, requires a specific classname. the &#8220;VBControlExtender&#8221; object can be used for controls, but we&#8217;d still need to hook a Form, Usercontrol, and all the intrinsic controls in different withevents variables. So that method is out of the question. There is one alternative, however.</p>
<p> <strong> Subclassing </strong> </p>
<p>Subclassing can provide a short and sweet solution to this problem. The way I used to subclass- the &#8220;unsafe&#8221; way, was to leverage Visual Basic&#8217;s &#8220;addressof&#8221; keyword and use SetWindowLong to redirect the window Procedure to my routine. This is unsafe because pressing the end button or even usually going into break mode, will cause Visual Basic to crash completely. This is the main reason many VB6 programmers avoid subclassing like the plague.</p>
<p>However, I have come across several implementations of safer subclassing methods that also do away with the Module dependency- thus making it possible to subclass as well as have no modules in a project, if that is desired for some reason. The implementation I have been using is from Planet-Source-code; namely,  <a href="http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=37102&amp;lngWId=1"> this entry </a> , which I believe to be a excellent implementation. Other implementations can be found at such places as VBAccelerator, but this is the one I was used to, so I used it <img src='http://bc-programming.com/blogs/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> .</p>
<p>Subclassing is a fairly simple concept; you &#8220;take over&#8221; the messages being sent to a window. You can then decide if you want to pass the message along to the &#8220;true&#8221; recipient, or keep them in the dark about it. The reason this particular trait  is important is that it is necessary for the objective of this class. My intent is to emulate what the double-click event does; that is, Windows sends Mousedown, mouseup,double-click,mouseup. When somebody triple-clicks, the intended messages that would be sent should be Mousedown,Mouseup,doubleclick,mouseup,tripleclick,mouseup. This will require us to hide the mousedown message that triggers the tripleclick event we fire.</p>
<p>My first attempt at this had some side-issues. I was hiding mouse-down perfectly fine, by setting the &#8220;lhandled&#8221; byref argument passed into my iSuperclass implementation to true. However, this also caused a few odd issues both with VB events and the way the windows reacted, mostly related to mouse capture. The solution was to call &#8220;DefWindowProc&#8221; which performs the default operations for a window. In this case, it handles the focus and mouse capture of the window.</p>
<p>For further study, consult the source I made for this, in a test project called, rightly enough, TripleClick. I have uploaded it here:</p>
<p> <a href="http://bc-programming.com/downloads/files/tripleclick.zip"> here </a>  </p>
<div id="fcbk_share"><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://bc-programming.com/blogs/2009/11/detecting-triple-clicks/" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://bc-programming.com/blogs/2009/11/detecting-triple-clicks/&via=BC_Programming&text=Detecting Triple-Clicks&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div> <p><a href="http://bc-programming.com/blogs/?flattrss_redirect&amp;id=19&amp;md5=e82d70405ae1eb03aebe90bc8d687960" title="Flattr" target="_blank"><img src="http://bc-programming.com/blogs/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://bc-programming.com/blogs/2009/11/detecting-triple-clicks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=bc_programming&amp;popout=1&amp;url=http%3A%2F%2Fbc-programming.com%2Fblogs%2F2009%2F11%2Fdetecting-triple-clicks%2F&amp;language=en_GB&amp;category=software&amp;title=Detecting+Triple-Clicks&amp;description=Visual+Basic+6%3B+and%2C+well-+nearly+any+other+relatively+modern+language%3B+provides+a+way+to+detect+mouse+events.+These+usually+include+mouse+down%2C+mouse+up%2C+mouseclicks%2C+and+double+clicks.+Absent...&amp;tags=blog" type="text/html" />
	</item>
	</channel>
</rss>

