<?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>GuShH&#039;s DevBlog &#187; Windows</title>
	<atom:link href="http://gushh.net/blog/?tag=windows&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://gushh.net/blog</link>
	<description>This blog is about software, electronics engineering and game development.</description>
	<lastBuildDate>Tue, 24 Jan 2012 00:31:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>TimeLapse lib</title>
		<link>http://gushh.net/blog/timelapse-lib/</link>
		<comments>http://gushh.net/blog/timelapse-lib/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 18:48:02 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[callback]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[gettickcount]]></category>
		<category><![CDATA[lib]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[time lapse]]></category>
		<category><![CDATA[timelapse]]></category>
		<category><![CDATA[timer]]></category>
		<category><![CDATA[timing]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=171</guid>
		<description><![CDATA[This little lib is used to keep track of time using the low resolution timer provided by the OS (in Windows &#8220;GetTickCount&#8221;). The goal of this type of library is to encapsulate timing actions. It was originally designed for game development in mind but needless to say you can use it and adapt it to [...]]]></description>
			<content:encoded><![CDATA[<p>This little lib is used to keep track of time using the low resolution timer provided by the OS (in Windows &#8220;GetTickCount&#8221;). The goal of this type of library is to encapsulate timing actions. It was originally designed for game development in mind but needless to say you can use it and adapt it to your own needs.</p>
<p>Basically you define a time interval as you create the &#8220;timelapse&#8221; instance. Every time you call the update function a simple check determines whether the time was reached or not. This is trivial, but encapsulating it makes sense. Specially if you plan to create an animation system in the future!</p>
<p><span id="more-171"></span><br />
The code:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">EnableExplicit</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Prototype</span>.i TimeLapse_Callback<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.i <span style="color: #000066;">&#41;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Structure</span> TIMELAPSE
	old_time.i			<span style="color: #ff0000; font-style: italic;">; Stores the &quot;old&quot; time value.</span>
	new_time.i			<span style="color: #ff0000; font-style: italic;">; Stores the &quot;new&quot; time value.</span>
	time_out.i			<span style="color: #ff0000; font-style: italic;">; Time period for the TimeLapse , in ms.</span>
	<span style="color: #000066;">*</span>callback.TimeLapse_Callback	<span style="color: #ff0000; font-style: italic;">; User callback.</span>
	userdata.i			<span style="color: #ff0000; font-style: italic;">; User data.</span>
<span style="color: #000066; font-weight: bold;">EndStructure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">CompilerSelect</span> #PB_Compiler_OS
	<span style="color: #000066; font-weight: bold;">CompilerCase</span> #PB_OS_Windows
		<span style="color: #000066; font-weight: bold;">Macro</span> _time<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> : timeGetTime_<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>		: <span style="color: #000066; font-weight: bold;">EndMacro</span>
	<span style="color: #000066; font-weight: bold;">CompilerDefault</span>
		<span style="color: #000066; font-weight: bold;">Macro</span> _time<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> : <span style="color: #0000ff;">ElapsedMilliseconds</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>	: <span style="color: #000066; font-weight: bold;">EndMacro</span>
<span style="color: #000066; font-weight: bold;">CompilerEndSelect</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i TimeLapseCreate<span style="color: #000066;">&#40;</span> Timeout.i, <span style="color: #000066;">*</span>Callback.TimeLapse_Callback <span style="color: #000066;">=</span> #Null, UserData.i <span style="color: #000066;">=</span> #Null <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.TimeLapse  <span style="color: #000066;">*</span>this <span style="color: #000066;">=</span> <span style="color: #0000ff;">AllocateMemory</span><span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>TimeLapse <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #000066; font-weight: bold;">With</span> <span style="color: #000066;">*</span>this
			<span style="color: #000066;">\</span>new_time 	<span style="color: #000066;">=</span> _time<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
			<span style="color: #000066;">\</span>old_time 	<span style="color: #000066;">=</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>new_time
			<span style="color: #000066;">\</span>time_out	<span style="color: #000066;">=</span> Timeout
			<span style="color: #000066;">\</span>callback	<span style="color: #000066;">=</span> <span style="color: #000066;">*</span>Callback
			<span style="color: #000066;">\</span>userdata	<span style="color: #000066;">=</span> UserData
		<span style="color: #000066; font-weight: bold;">EndWith</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this
&nbsp;
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i TimeLapseDestroy<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.TIMELAPSE  <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #0000ff;">FreeMemory</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>this<span style="color: #000066;">&#41;</span>
		<span style="color: #000066;">*</span>this <span style="color: #000066;">=</span> #Null
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this
&nbsp;
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i TimeLapseUpdate<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.TIMELAPSE  <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>new_time <span style="color: #000066;">=</span> _time<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">&#40;</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>new_time <span style="color: #000066;">-</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>old_time<span style="color: #000066;">&#41;</span> <span style="color: #000066;">=&gt;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>time_out<span style="color: #000066;">&#41;</span>
&nbsp;
			<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>old_time <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>new_time
&nbsp;
			<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>callback
				<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>callback<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this <span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> #True
&nbsp;
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
&nbsp;
<span style="color: #ff0000; font-style: italic;">; Helper routines</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i TimeLapseSet<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.TIMELAPSE , Timeout.i <span style="color: #000066;">&#41;</span>
&nbsp;
 	<span style="color: #000066; font-weight: bold;">If</span> Timeout <span style="color: #000066;">&gt;</span> <span style="color: #CC0000;">0</span>
		<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>time_out <span style="color: #000066;">=</span> Timeout
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i TimeLapseGet<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.TIMELAPSE  <span style="color: #000066;">&#41;</span>
&nbsp;
 	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>time_out
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>Example:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">OpenConsole</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">Define</span>.TIMELAPSE  <span style="color: #000066;">*</span>test_timer  <span style="color: #000066;">=</span> TimeLapseCreate<span style="color: #000066;">&#40;</span> <span style="color: #CC0000;">500</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">Repeat</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> TimeLapseUpdate<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>test_timer  <span style="color: #000066;">&#41;</span>
			<span style="color: #0000ff;">PrintN</span><span style="color: #000066;">&#40;</span><span style="color: #009900;">&quot; Timer says hi!&quot;</span> <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #0000ff;">Delay</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">Until</span> <span style="color: #0000ff;">Inkey</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #0000ff;">Chr</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">27</span><span style="color: #000066;">&#41;</span>
	<span style="color: #0000ff;">CloseConsole</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndIf</span>
<span style="color: #000066; font-weight: bold;">End</span></pre></div></div>

<p>The nice thing about this library is the ability to use callbacks. Whenever a callback is defined, once the timer reaches the maximum allowed time-lapse, it&#8217;ll return by executing the callback.</p>
<p>In the callback you can do anything you want; From simple event triggering to manipulating another timer depending on XYZ conditions: it&#8217;s up to you!.</p>
<p><strong>Just keep in mind:</strong> Always return &#8220;true&#8221; unless you want to invalidate the update call.</p>
<p>Here is a more advanced example with a callback, user data and multiple timers:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Procedure</span>.i MyCallback<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.TIMELAPSE  <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #ff0000; font-style: italic;">; It's imperative that you return #true (1) in your callbacks if you want the &quot;Update&quot; calls to pass once the timeout is reached.</span>
	<span style="color: #ff0000; font-style: italic;">; This is a design choice for flexibility and nothing else.</span>
&nbsp;
	<span style="color: #0000ff;">ConsoleColor</span><span style="color: #000066;">&#40;</span><span style="color: #0000ff;">Random</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">15</span><span style="color: #000066;">&#41;</span>, <span style="color: #0000ff;">Random</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">15</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span>
	<span style="color: #0000ff;">PrintN</span><span style="color: #000066;">&#40;</span><span style="color: #009900;">&quot; Hi from the callback! &quot;</span><span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #0000ff;">PrintN</span><span style="color: #000066;">&#40;</span> <span style="color: #009900;">&quot; The other timer is set to: &quot;</span> <span style="color: #000066;">+</span> <span style="color: #0000ff;">Str</span><span style="color: #000066;">&#40;</span> TimeLapseGet<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>userdata <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span> <span style="color: #000066;">+</span> <span style="color: #009900;">&quot;ms&quot;</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #0000ff;">PrintN</span><span style="color: #000066;">&#40;</span> <span style="color: #009900;">&quot; ...Reducing the time interval down by 50 ms... &quot;</span> <span style="color: #000066;">&#41;</span>
&nbsp;
	TimeLapseSet<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>userdata, TimeLapseGet<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>userdata <span style="color: #000066;">&#41;</span> <span style="color: #000066;">-</span> <span style="color: #CC0000;">50</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #0000ff;">ConsoleColor</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">15</span>, <span style="color: #CC0000;">0</span><span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> #True
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Define</span>.TIMELAPSE  <span style="color: #000066;">*</span>timer_one 	<span style="color: #000066;">=</span> TimeLapseCreate<span style="color: #000066;">&#40;</span> <span style="color: #CC0000;">500</span> <span style="color: #000066;">&#41;</span>				<span style="color: #ff0000; font-style: italic;">; The first TimeLapse , nothing special.</span>
<span style="color: #000066; font-weight: bold;">Define</span>.TIMELAPSE  <span style="color: #000066;">*</span>timer_two 	<span style="color: #000066;">=</span> TimeLapseCreate<span style="color: #000066;">&#40;</span> <span style="color: #CC0000;">2000</span>, @MyCallback<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, <span style="color: #000066;">*</span>timer_one <span style="color: #000066;">&#41;</span>	<span style="color: #ff0000; font-style: italic;">; The second TimeLapse , it manipulates the first one through a callback.</span>
<span style="color: #000066; font-weight: bold;">Define</span>.TIMELAPSE  <span style="color: #000066;">*</span>timer_three	<span style="color: #000066;">=</span> TimeLapseCreate<span style="color: #000066;">&#40;</span> <span style="color: #CC0000;">20</span><span style="color: #000066;">*</span><span style="color: #CC0000;">1000</span> <span style="color: #000066;">&#41;</span>				<span style="color: #ff0000; font-style: italic;">; This TimeLapse  will simply let us exit the example after the set time.</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">OpenConsole</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #0000ff;">EnableGraphicalConsole</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #000066;">&#41;</span>
	<span style="color: #0000ff;">ConsoleColor</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">15</span>, <span style="color: #CC0000;">0</span><span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.i quit <span style="color: #000066;">=</span> #False
&nbsp;
	<span style="color: #000066; font-weight: bold;">Repeat</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> TimeLapseUpdate<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>timer_three <span style="color: #000066;">&#41;</span>
			quit <span style="color: #000066;">=</span> #True
		<span style="color: #000066; font-weight: bold;">Else</span>
			<span style="color: #000066; font-weight: bold;">If</span> TimeLapseUpdate<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>timer_one <span style="color: #000066;">&#41;</span>
				<span style="color: #0000ff;">PrintN</span><span style="color: #000066;">&#40;</span><span style="color: #009900;">&quot;timer_one: &quot;</span> <span style="color: #000066;">+</span> <span style="color: #0000ff;">Str</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>timer_one<span style="color: #000066;">\</span>time_out<span style="color: #000066;">&#41;</span> <span style="color: #000066;">+</span> <span style="color: #009900;">&quot;ms reached.&quot;</span><span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">EndIf</span>
			<span style="color: #000066; font-weight: bold;">If</span> TimeLapseUpdate<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>timer_two <span style="color: #000066;">&#41;</span>
				<span style="color: #0000ff;">PrintN</span><span style="color: #000066;">&#40;</span><span style="color: #009900;">&quot;timer_two: &quot;</span> <span style="color: #000066;">+</span> <span style="color: #0000ff;">Str</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>timer_two<span style="color: #000066;">\</span>time_out<span style="color: #000066;">&#41;</span> <span style="color: #000066;">+</span> <span style="color: #009900;">&quot;ms reached.&quot;</span><span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #0000ff;">Delay</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Until</span> <span style="color: #0000ff;">Inkey</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #0000ff;">Chr</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">27</span><span style="color: #000066;">&#41;</span> <span style="color: #000066; font-weight: bold;">Or</span> quit 
&nbsp;
	<span style="color: #0000ff;">PrintN</span><span style="color: #000066;">&#40;</span> <span style="color: #009900;">&quot;timer_three: The example finished.&quot;</span> <span style="color: #000066;">&#41;</span>
&nbsp;
	TimeLapseDestroy<span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>timer_one<span style="color: #000066;">&#41;</span>
	TimeLapseDestroy<span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>timer_two<span style="color: #000066;">&#41;</span>
	TimeLapseDestroy<span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>timer_three<span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #0000ff;">Input</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
	<span style="color: #0000ff;">CloseConsole</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndIf</span>
<span style="color: #000066; font-weight: bold;">End</span></pre></div></div>

<p>The examples are crude, but they show every function in the library.<br />
Should you have any questions, feel free to ask.</p>
<p>I&#8217;ll soon post the &#8220;Animation&#8221; lib that depends on &#8220;TimeLapse&#8221;.</p>
<p>Cheers.</p>
<g:plusone href='http://gushh.net/blog/timelapse-lib/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/timelapse-lib/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Centered MessageRequester() / MessageBox()</title>
		<link>http://gushh.net/blog/pb-centered-messagerequester/</link>
		<comments>http://gushh.net/blog/pb-centered-messagerequester/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 16:25:00 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[CBT]]></category>
		<category><![CDATA[Centered Dialog]]></category>
		<category><![CDATA[Dual Screen]]></category>
		<category><![CDATA[Fanboy]]></category>
		<category><![CDATA[GuShH]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[MessageBox]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[pb]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[SetWindowsHookEx]]></category>
		<category><![CDATA[UnhookWindowsHookEx]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=87</guid>
		<description><![CDATA[As usual, I was browsing the PureBasic forums to see what was new, nothing much (heh&#8230;) but something caught my attention, the fact that some user requested for the IDE&#8217;s message dialogs to be &#8220;centered&#8221; ( because he had multiple displays and the messages would appear in between them ) just to get shit-faced by [...]]]></description>
			<content:encoded><![CDATA[<p>As usual, I was browsing the PureBasic forums to see what was new, nothing much (heh&#8230;) but something caught my attention, the fact that some user requested for the IDE&#8217;s message dialogs to be &#8220;centered&#8221; ( because he had multiple displays and the messages would appear in between them ) just to get shit-faced by an actual staff member!</p>
<p>You can&#8217;t just say &#8220;it&#8217;s Microsoft&#8217;s fault&#8221; &#8212; Are you in some sort of mac-only cleanse?, What&#8217;s your #%&amp;%#$ problem?!</p>
<p>Those who &#8220;pass the ball&#8221; (as the user suggested) are part of the problem. You, being a programmer can certainly code a simple CBT hook, right?. Are you against hooks, perhaps &#8211; you are a purist, I hear&#8230; Sorry, but sometimes solutions <strong>are</strong> &#8220;dirty&#8221; and you have to live with them.</p>
<div id="attachment_88" class="wp-caption aligncenter" style="width: 658px"><img class="size-full wp-image-88 " title="split_screen" src="http://gushh.net/blog/wp-content/uploads/2009/07/split_screen.jpg" alt="Just for the record, I too use a split-screen and I find it annoying that dialog boxes are not centered to their parent." width="648" height="203" /><p class="wp-caption-text">Just for the record, I too use a split-screen and I find it annoying that dialog boxes are not centered to their parent.</p></div>
<p><span id="more-87"></span></p>
<p>I certainly think that this sort of behavior is not good for a business, but then again they&#8217;ve been cat-walking away from reality for years now (Look at their website if not, look at the fact that they haven&#8217;t implemented basic functionality to their language and by basic I mean a proper container library and whatnot!). Most of their user-base consists of people who are afraid of real, world-class languages. That&#8217;s my opinion, take it or leave it.</p>
<p>But before you throw crap at me do remember that I support them, I just don&#8217;t like the way they&#8217;re doing things. Pretty much like Apple does (they do crap) however the fanboys don&#8217;t realize this and they see any criticism as bad for the company image, when in fact what damages the company is that nonsense wall they put up when anybody, and I do mean &#8220;anybody&#8221; says &#8220;anything&#8221; that appears to be &#8220;against&#8221; their product/s.</p>
<p>Even if you don&#8217;t like it at least have the decency to hear those who are genuinely interested in your product, those who are giving away (and for free) true and useful suggestions for you to improve them. I don&#8217;t give a damn about this particular user but I do care when a so called company does this sort of things to their own users, it&#8217;s just uncalled for and plainly unprofessional.</p>
<p>Have a nice day, code follows.</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">; This snippet was based on the following code by Microsoft:</span>
<span style="color: #ff0000; font-style: italic;">; http://support.microsoft.com/kb/180936</span>
<span style="color: #000066; font-weight: bold;">EnableExplicit</span> <span style="color: #ff0000; font-style: italic;">; The only way to go.</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i CenterMsgCallBack<span style="color: #000066;">&#40;</span> uMsg.i, wParam.i, lParam.i <span style="color: #000066;">&#41;</span> 
&nbsp;
	<span style="color: #000066; font-weight: bold;">Select</span> uMsg
		<span style="color: #000066; font-weight: bold;">Case</span> #HCBT_ACTIVATE
&nbsp;
			<span style="color: #000066; font-weight: bold;">Define</span>.RECT typFormRect, typRectMsg
			<span style="color: #000066; font-weight: bold;">Define</span>.i plMsgHook, hWnd
			<span style="color: #000066; font-weight: bold;">Define</span>.i lxPos, lyPos
&nbsp;
			hWnd <span style="color: #000066;">=</span> GetParent_<span style="color: #000066;">&#40;</span>wParam<span style="color: #000066;">&#41;</span> 																																																		<span style="color: #ff0000; font-style: italic;">; the parent will be the callee</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">If</span> hWnd 																																																											<span style="color: #ff0000; font-style: italic;">; can't hurt to check.</span>
&nbsp;
				plMsgHook 	<span style="color: #000066;">=</span> GetWindowLong_<span style="color: #000066;">&#40;</span> hWnd, #GWL_USERDATA <span style="color: #000066;">&#41;</span> 																																				<span style="color: #ff0000; font-style: italic;">; get the hook address</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">If</span> plMsgHook 																																																								<span style="color: #ff0000; font-style: italic;">; can't hurt to check.</span>
&nbsp;
					GetWindowRect_<span style="color: #000066;">&#40;</span> hWnd, typFormRect <span style="color: #000066;">&#41;</span>
					GetWindowRect_<span style="color: #000066;">&#40;</span> wParam, typRectMsg <span style="color: #000066;">&#41;</span>
&nbsp;
					lxPos <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>typFormRect<span style="color: #000066;">\</span><span style="color: #0000ff;">Left</span> <span style="color: #000066;">+</span> <span style="color: #000066;">&#40;</span>typFormRect<span style="color: #000066;">\</span><span style="color: #0000ff;">Right</span> <span style="color: #000066;">-</span> typFormRect<span style="color: #000066;">\</span><span style="color: #0000ff;">Left</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">/</span> <span style="color: #CC0000;">2</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">-</span> <span style="color: #000066;">&#40;</span><span style="color: #000066;">&#40;</span>typRectMsg<span style="color: #000066;">\</span><span style="color: #0000ff;">Right</span> <span style="color: #000066;">-</span> typRectMsg<span style="color: #000066;">\</span><span style="color: #0000ff;">Left</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">/</span> <span style="color: #CC0000;">2</span><span style="color: #000066;">&#41;</span>
					lyPos <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>typFormRect<span style="color: #000066;">\</span>Top  <span style="color: #000066;">+</span>	<span style="color: #000066;">&#40;</span>typFormRect<span style="color: #000066;">\</span>Bottom <span style="color: #000066;">-</span> typFormRect<span style="color: #000066;">\</span>Top<span style="color: #000066;">&#41;</span> <span style="color: #000066;">/</span> <span style="color: #CC0000;">2</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">-</span> <span style="color: #000066;">&#40;</span><span style="color: #000066;">&#40;</span>typRectMsg<span style="color: #000066;">\</span>Bottom <span style="color: #000066;">-</span> typRectMsg<span style="color: #000066;">\</span>Top<span style="color: #000066;">&#41;</span> <span style="color: #000066;">/</span> <span style="color: #CC0000;">2</span><span style="color: #000066;">&#41;</span>
&nbsp;
					SetWindowPos_<span style="color: #000066;">&#40;</span> wParam, <span style="color: #CC0000;">0</span>, lxPos, lyPos, <span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">0</span>,	#SWP_NOSIZE <span style="color: #000066;">|</span> #SWP_NOZORDER <span style="color: #000066;">|</span> #SWP_NOACTIVATE <span style="color: #000066;">&#41;</span> 														<span style="color: #ff0000; font-style: italic;">; position the window.</span>
					UnhookWindowsHookEx_<span style="color: #000066;">&#40;</span>plMsgHook<span style="color: #000066;">&#41;</span> 																																													<span style="color: #ff0000; font-style: italic;">; release the hook.</span>
					SetWindowLong_<span style="color: #000066;">&#40;</span> hWnd, #GWL_USERDATA, #Null <span style="color: #000066;">&#41;</span> 																																							<span style="color: #ff0000; font-style: italic;">; unset the user data.</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #000066; font-weight: bold;">EndSelect</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span> 
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i CenteredMessageRequester<span style="color: #000066;">&#40;</span> Title.s, Text.s, Flags.i<span style="color: #000066;">=</span>#Null, hWnd.i<span style="color: #000066;">=</span>#Null <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.i lInstance, lThreadID, plMsgHook
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066; font-weight: bold;">Not</span> hWnd
		hWnd <span style="color: #000066;">=</span> <span style="color: #0000ff;">WindowID</span><span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">GetActiveWindow</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> hWnd
&nbsp;
		lInstance <span style="color: #000066;">=</span> GetWindowLong_<span style="color: #000066;">&#40;</span> hWnd, #GWL_HINSTANCE <span style="color: #000066;">&#41;</span>
		lThreadID <span style="color: #000066;">=</span> GetCurrentThreadId_<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> lInstance <span style="color: #000066; font-weight: bold;">And</span> lThreadID 																																																			<span style="color: #ff0000; font-style: italic;">; just to make sure, can't hurt.</span>
&nbsp;
			plMsgHook <span style="color: #000066;">=</span> SetWindowsHookEx_<span style="color: #000066;">&#40;</span>#WH_CBT, @CenterMsgCallBack<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, lInstance, lThreadID<span style="color: #000066;">&#41;</span> 																						<span style="color: #ff0000; font-style: italic;">; create the cbt hook.</span>
			SetWindowLong_<span style="color: #000066;">&#40;</span>	hWnd, #GWL_USERDATA, plMsgHook <span style="color: #000066;">&#41;</span> 																																							<span style="color: #ff0000; font-style: italic;">; save the hook address, we'll need it to release it.</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> MessageBox_<span style="color: #000066;">&#40;</span> hWnd, Text, Title, Flags <span style="color: #000066;">&#41;</span>																																				<span style="color: #ff0000; font-style: italic;">; finally, create the message box.</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>And a small example:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #0000ff;">OpenWindow</span><span style="color: #000066;">&#40;</span> <span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">500</span>, <span style="color: #CC0000;">200</span>, <span style="color: #CC0000;">400</span>, <span style="color: #CC0000;">200</span>, <span style="color: #009900;">&quot;testing&quot;</span> <span style="color: #000066;">&#41;</span>																																											<span style="color: #ff0000; font-style: italic;">; test window</span>
<span style="color: #0000ff;">MessageRequester</span><span style="color: #000066;">&#40;</span> <span style="color: #009900;">&quot;:(&quot;</span>, <span style="color: #009900;">&quot;I'm a normal messagebox&quot;</span>, #MB_APPLMODAL <span style="color: #000066;">|</span> #MB_ICONERROR <span style="color: #000066;">&#41;</span>																									<span style="color: #ff0000; font-style: italic;">; conventional msgbox</span>
CenteredMessageRequester<span style="color: #000066;">&#40;</span> <span style="color: #009900;">&quot;:)&quot;</span>, <span style="color: #009900;">&quot;I'm a centered messagebox!&quot;</span>, #MB_APPLMODAL <span style="color: #000066;">|</span> #MB_ICONEXCLAMATION <span style="color: #000066;">&#41;</span>																	<span style="color: #ff0000; font-style: italic;">; our centered msgbox.</span></pre></div></div>

<p>The &#8220;Programmer&#8221; can now copy&amp;paste and compile.</p>
<p>Cheers.</p>
<p>PS: You can also find the source in here: <a href="http://gushh.net/dev/?file=pb/centermessagebox.pb">http://gushh.net/dev/?file=pb/centermessagebox.pb</a> As usual, that&#8217;s my code repository for PB.</p>
<g:plusone href='http://gushh.net/blog/pb-centered-messagerequester/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/pb-centered-messagerequester/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: gushh.net @ 2012-02-09 07:17:44 by W3 Total Cache -->
