<?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>Unified Diff &#187; Bob</title>
	<atom:link href="http://www.unifieddiff.com/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.unifieddiff.com</link>
	<description>crazy hacks with a side of shouting</description>
	<lastBuildDate>Sun, 05 Feb 2012 02:47:32 +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>Remotely Set a User&#8217;s Desktop Wallpaper</title>
		<link>http://www.unifieddiff.com/2010/12/15/remotely-set-a-users-desktop-wallpaper/</link>
		<comments>http://www.unifieddiff.com/2010/12/15/remotely-set-a-users-desktop-wallpaper/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 20:32:44 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Win32]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://www.unifieddiff.com/?p=377</guid>
		<description><![CDATA[I recently discussed, with a coworker, the feasibility of changing a logged on user&#8217;s desktop wallpaper remotely. It was an interesting problem with quite a number of challenges. The Win32 security model is very complex and I had to jump through a lot of hoops for what I thought would be a fairly simple task. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discussed, with a coworker, the feasibility of changing a logged on user&#8217;s desktop wallpaper remotely. It was an interesting problem with quite a number of challenges. The Win32 security model is very complex and I had to jump through a lot of hoops for what I thought would be a fairly simple task. Overall it was a very enlightening experience but I did learn a new appreciation for <em>seteuid(0)</em>.</p>
<p><span id="more-377"></span></p>
<p>My journey began (as these journeys often do) by perusing the Win32 API on MSDN. I knew it was possible to change the wallpaper path in the registry, but that change would only take effect the next time the user logged in. What I needed was a way to set the user&#8217;s wallpaper and force their desktop to refresh. I wrote a simple prototype to set my wallpaper by calling <a href="http://msdn.microsoft.com/en-us/library/ms724947%28v=vs.85%29.aspx">SystemParametersInfo()</a> with SPI_SETDESKWALLPAPER and SPIF_SENDCHANGE, and it worked as expected. But how could I do this remotely?</p>
<p>I wrote a simple batch script to copy my prototype to the target machine and then start the process with WMI.</p>
<pre>
mkdir \\%1\c$\tmp
copy chwp.exe \\%1\c$\tmp
copy cat-owned.bmp \\%1\c$\tmp
wmic /node:"%1" /user:bob.carroll process call create ^
   "cmd.exe /c c:\tmp\chwp.exe \tmp\cat-owned.bmp > c:\tmp\out.txt"
</pre>
<p>Initially, the call kept failing with ERROR_INSUFFICIENT_BUFFER. I&#8217;m a domain administrator so I had the necessary rights, but logging in at the console before running my script seemed to fix the issue. That suggests the problem was caused by not having a profile, but I didn&#8217;t look into it further.</p>
<p>At this point I was able to remotely launch my application, but it was executing in a service <a href="http://msdn.microsoft.com/en-us/library/ms687096%28v=vs.85%29.aspx">window station</a>. I figured that my application would need to run in the context of the <a href="http://msdn.microsoft.com/en-us/library/ms682573%28v=vs.85%29.aspx">interactive desktop</a> before I could change the user&#8217;s wallpaper. It was easy enough to attach to <em>WinSta0\Default</em>, but I had to adjust the window station&#8217;s DACL in order to open it for WINSTA_ALL_ACCESS.</p>
<p>With my application running in the correct desktop context, I attempted to call <em>SystemParametersInfo()</em> but it failed with ERROR_ACCESS_DENIED. This actually made sense because I was still executing as myself but I didn&#8217;t own the desktop session. I thought about impersonating the console user, but I needed an <a href="http://msdn.microsoft.com/en-us/library/aa374909%28v=vs.85%29.aspx">access token</a> and <a href="http://msdn.microsoft.com/en-us/library/aa378184%28v=vs.85%29.aspx">LogonUser()</a> requires a password. Calling <a href="http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/Token/NtCreateToken.html">NtCreateToken()</a> might work, but I&#8217;d have to fill the token myself. If only I could steal the console user&#8217;s token somehow&#8230;</p>
<p>Since I was executing in the console user&#8217;s desktop session, I was able to locate the <em>Program Manager</em> window and then get the EXPLORER.EXE process ID. Ideally, I could copy the access token from EXPLORER.EXE and use it to impersonate the console user. I enabled <em>SeDebugPrivilege</em> and opened the process for all access, but I was unable to call <a href="http://msdn.microsoft.com/en-us/library/aa379295%28v=vs.85%29.aspx">OpenProcessToken()</a> with TOKEN_DUPLICATE. Apparently the token itself has a DACL and I was implicitly not allowed to read it.</p>
<p>After hours of reading, I couldn&#8217;t find a way around this without stomping on the token and granting myself access. So I switched on <em>SeTakeOwnershipPrivilege</em> and did just that. Interestingly, calling <a href="http://msdn.microsoft.com/en-us/library/aa379591%28v=vs.85%29.aspx">SetTokenInformation()</a> failed with ERROR_ACCESS_DENIED, but calling <a href="http://msdn.microsoft.com/en-us/library/aa379578%28v=vs.85%29.aspx">SetKernelObjectSecurity()</a> succeeded. Once I had rights to read the token, I copied it and called <a href="http://msdn.microsoft.com/en-us/library/aa378612%28v=vs.85%29.aspx">ImpersonateLoggedOnUser()</a>. Now I was running in the console user&#8217;s desktop session as that user.</p>
<p>And for the moment of triumph: running my script from machine A caused the desktop wallpaper to change on machine B! I made a <a href="http://www.unifieddiff.com/files/chwp-demo.avi">video</a> to demo the tool.</p>
<p>You can find the sources <a href="http://github.com/rcarz/chwp">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unifieddiff.com/2010/12/15/remotely-set-a-users-desktop-wallpaper/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://www.unifieddiff.com/files/chwp-demo.avi" length="2888704" type="video/avi" />
		</item>
		<item>
		<title>DoD Common Access Card on Linux</title>
		<link>http://www.unifieddiff.com/2010/09/18/cac-on-linux/</link>
		<comments>http://www.unifieddiff.com/2010/09/18/cac-on-linux/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 02:09:34 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[DoD CAC]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PKI]]></category>
		<category><![CDATA[Portage]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.unifieddiff.com/?p=328</guid>
		<description><![CDATA[There are times when I need to use my Common Access Card at home. Being a Linux user, I figured this would be challenging to configure. It took a few hours of trying different packages and directions, but I finally have it working. Considering the process isn&#8217;t entirely straightforward, I thought it&#8217;d be good to [...]]]></description>
			<content:encoded><![CDATA[<p>There are times when I need to use my <a href="http://www.cac.mil/">Common Access Card</a> at home. Being a Linux user, I figured this would be challenging to configure. It took a few hours of trying different packages and directions, but I finally have it working. Considering the process isn&#8217;t entirely straightforward, I thought it&#8217;d be good to document the steps here.</p>
<p><span id="more-328"></span></p>
<p>My desktop is running Gentoo Linux with the SCM Microsystems SCR331-LC1 smart card reader. Other readers will probably work, but I know for certain that this one does.</p>
<p>1. Download and untar the <a href="http://www.unifieddiff.com/files/cackey-0.5.12_ebuild.tar.bz2">CACKey ebuild</a> into your <em>PORTDIR_OVERLAY</em>.</p>
<p>2. Edit <em>/etc/portage/packages.keywords</em> and add the following lines:</p>
<pre>
app-crypt/cackey ~x86
dev-perl/pcsc-perl ~x86
sys-apps/pcsc-tools ~x86
</pre>
</p>
<p>3. Edit <em>/etc/portage/packages.use</em> and add the following lines:</p>
<pre>
sys-apps/pcsc-lite usb
sys-apps/pcsc-tools usb
</pre>
</p>
<p>4. Download <em>cackey-0.5.12-1.src.rpm</em> from <a href="https://software.forge.mil/sf/frs/do/viewRelease/projects.community_cac/frs.cackey.0_5_12">Software Forge</a> and drop it in <em>/usr/portage/distfiles</em>. Unfortunately, you&#8217;ll need your CAC to download CACKey.</p>
<p>5. Merge some packages:</p>
<pre>$ sudo emerge pcsc-lite pcsc-tools cackey ccid</pre>
</p>
<p>6. In Firefox, go to Edit &gt; Preferences &gt; Advanced &gt; Encryption. Click on the Security Devices button, and click the Load button. Use <em>DoD CAC</em> for the module name, and set the module file to <em>/usr/lib/libcackey.so</em>.</p>
<p>7. Download and install the <a href="http://dodpki.c3pki.chamb.disa.mil/rootca.html">DoD Root certificates</a> in Firefox.</p>
<p>8. Test your CAC at <a href="https://www.us.army.mil/">AKO/DKO</a>.</p>
<p>I originally tried using CoolKey but Firefox always claimed the card was not present. <a href="https://bugzilla.redhat.com/show_bug.cgi?id=534172">This post</a> pointed me in the right direction. It seems that cards manufactured on or after January 14, 2010 no longer work with CoolKey.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unifieddiff.com/2010/09/18/cac-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Block Windows Shut Down</title>
		<link>http://www.unifieddiff.com/2010/01/28/block-windows-shut-down/</link>
		<comments>http://www.unifieddiff.com/2010/01/28/block-windows-shut-down/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 18:51:27 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Why Sys Admins Hate Me]]></category>
		<category><![CDATA[Win32]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.unifieddiff.com/?p=252</guid>
		<description><![CDATA[It&#8217;s hard to describe just how much I HATE rebooting my computer. If I have to use a Windows computer for any extended period of time, then I always change update policies to disallow automatic reboots. In fact, I usually click the irritating &#8220;Remind me in ten minutes&#8221; button every ten minutes for three weeks [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s hard to describe just how much I <strong><u>HATE</u></strong> rebooting my computer. If I have to use a Windows computer for any extended period of time, then I always change update policies to disallow automatic reboots. In fact, I usually click the irritating <em>&#8220;Remind me in ten minutes&#8221;</em> button every ten minutes for three weeks before I finally allow Windows to restart (or until I stop the Automatic Updates service).</p>
<p>So you can imagine how annoyed I was to come into work twice this week to the blue Windows logon screen. Every time this happens it takes me twenty minutes to figure out what I was doing the day before, what I have to do today, and where I stopped with my work. And really what made this so much more painful was that it happened without any advanced warning.</p>
<p><span id="more-252"></span></p>
<p>And that&#8217;s what got me thinking: could I <em>block</em> restart requests? I researched the Windows shut down process online and then went to work on a prototype. From what I read, calling <a href="http://msdn.microsoft.com/en-us/library/aa376868(VS.85).aspx">ExitWindowsEx</a> sends <em>WM_QUERYENDSESSION</em> to all top-level windows. Applications that are not ready to shut down should return <em>false</em>. I figured the best strategy was to install a system-wide hook and filter the message.</p>
<p>Initially I attempted to capture <em>WM_QUERYENDSESSION</em> with the <em>WH_GETMESSAGE</em> hook and replace it with <em>WM_NULL</em>, but trial-and-error revealed that it&#8217;s sent through <a href="http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx">SendMessage</a> and not posted to the window&#8217;s queue. This meant that I couldn&#8217;t filter out the message.</p>
<p>I switched to <em>WH_CALLWNDPROC</em> and was able to capture the message, but not actually modify it. Since my DLL is memory-mapped into the local process space, it seemed like the only way to filter the message was to create a new <em>WindowProc</em> function that handles <em>WM_QUERYENDSESSION</em> and always returns <em>false</em>. Then inside the hook procedure, I could intercept the message and call <a href="http://msdn.microsoft.com/en-us/library/ms633591(VS.85).aspx">SetWindowLong</a> to replace the window&#8217;s message procedure.</p>
<p>This demonstrates the basic concept:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">LRESULT CALLBACK CallWndProc<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> nCode, WPARAM wParam, LPARAM lParam<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>nCode <span style="color: #000080;">==</span> HC_ACTION<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
      CWPSTRUCT <span style="color: #000040;">*</span>msg <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>CWPSTRUCT<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>lParam<span style="color: #008080;">;</span>
&nbsp;
      <span style="color: #ff0000; font-style: italic;">/* hijack the window proc when we see a shut down message */</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>msg<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>message <span style="color: #000080;">==</span> WM_QUERYENDSESSION<span style="color: #008000;">&#41;</span>
          oldwndproc <span style="color: #000080;">=</span> SetWindowLong<span style="color: #008000;">&#40;</span>msg<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>hwnd, GWL_WNDPROC, <span style="color: #008000;">&#40;</span>DWORD<span style="color: #008000;">&#41;</span>WindowProc<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> CallNextHookEx<span style="color: #008000;">&#40;</span>g_callwndhk, nCode, wParam, lParam<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
LRESULT CALLBACK WindowProc<span style="color: #008000;">&#40;</span>HWND hWnd, UINT uiMessage, 
        WPARAM wParam, LPARAM lParam<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #ff0000; font-style: italic;">/* intercept shut down messages */</span>
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>uiMessage <span style="color: #000080;">==</span> WM_QUERYENDSESSION<span style="color: #008000;">&#41;</span>
      <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> DefWindowProc<span style="color: #008000;">&#40;</span>hWnd, uiMessage, wParam, lParam<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

</p>
<p>When my little application starts, it calls <a href="http://msdn.microsoft.com/en-us/library/ms686227(VS.85).aspx">SetProcessShutdownParameters</a> with level <em>0x4FF</em> to increase the chances of trapping the message first. I figured this was a good idea since I know its <em>WindowProc</em> function can be safely hijacked. Now when Windows sends <em>WM_QUERYENDSESSION</em> the response is always &#8220;NO!&#8221;. The added exclamation there is a call to <a href="http://msdn.microsoft.com/en-us/library/aa376630(VS.85).aspx">AbortSystemShutdown</a>, which is probably unnecessary but I do it just to be safe. Also, I added an alert message box to warn me when a reboot is triggered.</p>
<p>I&#8217;m sort of amazed this actually worked. Some day I&#8217;ll test it against <a href="http://msdn.microsoft.com/en-us/library/aa376873(VS.85).aspx">InitiateSystemShutdown</a> and <a href="http://msdn.microsoft.com/en-us/library/aa376868(VS.85).aspx">ExitWindowsEx</a> with <em>EWX_FORCE</em> to see how it holds up. Interestingly, Windows Vista/7 provides <a href="http://msdn.microsoft.com/en-us/library/aa376877(VS.85).aspx">ShutdownBlockReasonCreate</a> for seemingly outright blocking shut down attempts.</p>
<p>You can obtain the sources to this project <a href="http://github.com/rcarz/LifeGuard">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unifieddiff.com/2010/01/28/block-windows-shut-down/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Remove Tabs From the Windows Taskbar</title>
		<link>http://www.unifieddiff.com/2009/06/06/remove-tabs-from-the-windows-taskbar/</link>
		<comments>http://www.unifieddiff.com/2009/06/06/remove-tabs-from-the-windows-taskbar/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 04:54:03 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Win32]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.unifieddiff.com/?p=207</guid>
		<description><![CDATA[I&#8217;m very picky about my desktop environment. I like windows, toolbars, icons, etc. to be arranged in a certain way. Typically, I turn off annoying prompts and nag screens in Windows, and unhide &#8220;scary&#8221; advanced options in OS X. One hard-to-fix pet peeve is when applications put an icon in the notification area (near the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m very picky about my desktop environment. I like windows, toolbars, icons, etc. to be arranged in a certain way. Typically, I turn off annoying prompts and nag screens in Windows, and unhide &#8220;scary&#8221; advanced options in OS X. One hard-to-fix pet peeve is when applications put an icon in the notification area (near the clock) AND leave a tab in the taskbar. This wastes valuable taskbar real estate.</p>
<p>I use <a href="http://www.igniterealtime.org/projects/spark/index.jsp">Spark</a> on my workstation to connect to the company&#8217;s internal IM server. The application works alright, but the contacts window always appears in the taskbar. So I started to think about ways I could programmatically solve my problem.</p>
<p><span id="more-207"></span></p>
<p>I <em>could</em> set the WS_EX_TOOLWINDOW style on the window, but that would alter the window&#8217;s appearance. What I really wanted was a way to tell Windows to remove the tab. A quick search on Google turned up the answer: use COM to create an instance of ITaskbarList. The interface has the function ITaskbarList::DeleteTab() which takes a window handle. Perfect!</p>
<p>Now I just needed to get the window&#8217;s handle. FindWindow() would have worked, but that meant hard-coding my username into the program. I felt a more elegant solution was to enumerate all of the windows, and look for the one with the right class and title prefix.</p>
<p>Since the tab would reappear every time I brought the contact list window to the foreground, I ended up wrapping my fix with a loop and a timer. Here&#8217;s the finished product:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/* NoSpark.cpp - Hides the Spark contacts window tab in the taskbar */</span>
&nbsp;
<span style="color: #339900;">#include &lt;windows.h&gt;</span>
<span style="color: #339900;">#include &lt;Shobjidl.h&gt;</span>
&nbsp;
BOOL CALLBACK EnumWindowsProc<span style="color: #008000;">&#40;</span>HWND, LPARAM<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> WINAPI WinMain<span style="color: #008000;">&#40;</span>HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, <span style="color: #0000ff;">int</span> nCmdShow<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	HANDLE htmr <span style="color: #000080;">=</span> CreateWaitableTimer<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span>, TRUE, L<span style="color: #FF0000;">&quot;CheckSpark&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	LARGE_INTEGER lidt<span style="color: #008080;">;</span>
	ITaskbarList<span style="color: #000040;">*</span> ptl<span style="color: #008080;">;</span>
&nbsp;
	__int64 qwdt <span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">60</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">10000000</span><span style="color: #008080;">;</span> <span style="color: #ff0000; font-style: italic;">/* 1 minute */</span>
	lidt.<span style="color: #007788;">LowPart</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>DWORD<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>qwdt <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0xFFFFFFFF</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	lidt.<span style="color: #007788;">HighPart</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>LONG<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>qwdt <span style="color: #000080;">&gt;&gt;</span> <span style="color: #0000dd;">32</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>TRUE<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		SetWaitableTimer<span style="color: #008000;">&#40;</span>htmr, <span style="color: #000040;">&amp;</span>lidt, <span style="color: #0000dd;">0</span>, <span style="color: #0000ff;">NULL</span>, <span style="color: #0000ff;">NULL</span>, FALSE<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		WaitForSingleObject<span style="color: #008000;">&#40;</span>htmr, INFINITE<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		HWND hsparkwnd <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
		EnumWindows<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>EnumWindowsProc, <span style="color: #008000;">&#40;</span>LPARAM<span style="color: #008000;">&#41;</span><span style="color: #000040;">&amp;</span>hsparkwnd<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>hsparkwnd <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">continue</span><span style="color: #008080;">;</span>
&nbsp;
		CoInitialize<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		HRESULT ret <span style="color: #000080;">=</span> CoCreateInstance<span style="color: #008000;">&#40;</span>
			CLSID_TaskbarList, 
			<span style="color: #0000ff;">NULL</span>, 
			CLSCTX_SERVER, 
			IID_ITaskbarList, 
			<span style="color: #008000;">&#40;</span>LPVOID<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span>ptl
		<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>ret <span style="color: #000080;">==</span> S_OK<span style="color: #008000;">&#41;</span>
			ptl<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>DeleteTab<span style="color: #008000;">&#40;</span>hsparkwnd<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		ptl<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Release<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		CoUninitialize<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
BOOL CALLBACK EnumWindowsProc<span style="color: #008000;">&#40;</span>HWND hwnd, LPARAM lParam<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">int</span> tmpsz <span style="color: #000080;">=</span> <span style="color: #0000dd;">16</span><span style="color: #008080;">;</span>
	LPWSTR lptmp <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>LPWSTR<span style="color: #008000;">&#41;</span><span style="color: #0000dd;">malloc</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>WCHAR<span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> tmpsz<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	RtlZeroMemory<span style="color: #008000;">&#40;</span>lptmp, tmpsz<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	GetClassName<span style="color: #008000;">&#40;</span>hwnd, lptmp, tmpsz<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>wcscmp<span style="color: #008000;">&#40;</span>lptmp, L<span style="color: #FF0000;">&quot;SunAwtFrame&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">free</span><span style="color: #008000;">&#40;</span>lptmp<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span> TRUE<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	RtlZeroMemory<span style="color: #008000;">&#40;</span>lptmp, tmpsz<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	GetWindowText<span style="color: #008000;">&#40;</span>hwnd, lptmp, tmpsz<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>wcscmp<span style="color: #008000;">&#40;</span>lptmp, L<span style="color: #FF0000;">&quot;Spark -&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>HWND<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span> lParam<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> hwnd<span style="color: #008080;">;</span>
		<span style="color: #0000dd;">free</span><span style="color: #008000;">&#40;</span>lptmp<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span> FALSE<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000dd;">free</span><span style="color: #008000;">&#40;</span>lptmp<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> TRUE<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>To compile this program, create a new, empty Visual C++ project. Create a new cpp file and drop the code above inside. If you get compile errors about converting <em>wchar_t*</em> to <em>const char*</em> then change your character set from Multibyte to Unicode in the project properties.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unifieddiff.com/2009/06/06/remove-tabs-from-the-windows-taskbar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dipping Duck</title>
		<link>http://www.unifieddiff.com/2009/05/12/dipping-duck/</link>
		<comments>http://www.unifieddiff.com/2009/05/12/dipping-duck/#comments</comments>
		<pubDate>Wed, 13 May 2009 03:53:04 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Why Sys Admins Hate Me]]></category>
		<category><![CDATA[Win32]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.unifieddiff.com/?p=164</guid>
		<description><![CDATA[So I was trying to read a document on my computer at work today, while making notes on a piece of paper. But every five minutes the screensaver would activate, causing me to stop writing, type my password, and find my place in the document again. Needless to say it was quite annoying. Now you [...]]]></description>
			<content:encoded><![CDATA[<p>So I was trying to read a document on my computer at work today, while making notes on a piece of paper. But every five minutes the screensaver would activate, causing me to stop writing, type my password, and find my place in the document again. Needless to say it was quite annoying.</p>
<p align="center"><img src="/images/dilbert2045782050802.gif" alt="Dilbert comic" /></p>
<p><span id="more-164"></span></p>
<p>Now you might be wondering why I don&#8217;t just change the screensaver time-out or turn off the requirement for a password. Well even though I&#8217;m a local administrator, there is a domain-wide GPO that prevents me from doing so. (Yes I know I can edit the registry, but that setting doesn&#8217;t survive a GP refresh.) I understand the reason for the policy, but five minutes seems a bit too short.</p>
<p>I wanted to fix this problem AND keep my job at the same time. Alice&#8217;s &#8220;dipping duck&#8221; inspired me to write a simple program to simulate mouse movement.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;windows.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> WINAPI WinMain<span style="color: #008000;">&#40;</span>HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, <span style="color: #0000ff;">int</span> nCmdShow<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    HANDLE htmr <span style="color: #000080;">=</span> CreateWaitableTimer<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span>, TRUE, L<span style="color: #FF0000;">&quot;CheckIdle&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    LARGE_INTEGER lidt<span style="color: #008080;">;</span>
    LASTINPUTINFO lii<span style="color: #008080;">;</span>
&nbsp;
    __int64 qwdt <span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">30</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">10000000</span><span style="color: #008080;">;</span> <span style="color: #ff0000; font-style: italic;">/* 30 seconds */</span>
    lidt.<span style="color: #007788;">LowPart</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>DWORD<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>qwdt <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0xFFFFFFFF</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    lidt.<span style="color: #007788;">HighPart</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>LONG<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>qwdt <span style="color: #000080;">&gt;&gt;</span> <span style="color: #0000dd;">32</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>TRUE<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        SetWaitableTimer<span style="color: #008000;">&#40;</span>htmr, <span style="color: #000040;">&amp;</span>lidt, <span style="color: #0000dd;">0</span>, <span style="color: #0000ff;">NULL</span>, <span style="color: #0000ff;">NULL</span>, FALSE<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        WaitForSingleObject<span style="color: #008000;">&#40;</span>htmr, INFINITE<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        RtlZeroMemory<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>lii, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>LASTINPUTINFO<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        lii.<span style="color: #007788;">cbSize</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>LASTINPUTINFO<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        BOOL ret <span style="color: #000080;">=</span> GetLastInputInfo<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>lii<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">int</span> threshold <span style="color: #000080;">=</span> <span style="color: #0000dd;">3</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">60</span><span style="color: #008080;">;</span> <span style="color: #ff0000; font-style: italic;">/* 3 minutes */</span>
        <span style="color: #0000ff;">int</span> idletime <span style="color: #000080;">=</span> ret <span style="color: #008080;">?</span> <span style="color: #008000;">&#40;</span>GetTickCount<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> lii.<span style="color: #007788;">dwTime</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> <span style="color: #0000dd;">1000</span> <span style="color: #008080;">:</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
        BOOL scrnsvr <span style="color: #000080;">=</span> FALSE<span style="color: #008080;">;</span>
        SystemParametersInfo<span style="color: #008000;">&#40;</span>SPI_GETSCREENSAVERRUNNING, <span style="color: #0000dd;">0</span>, <span style="color: #000040;">&amp;</span>scrnsvr, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>idletime <span style="color: #000080;">&gt;</span> threshold <span style="color: #000040;">&amp;&amp;</span> <span style="color: #000040;">!</span>scrnsvr<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            MOUSEINPUT mi<span style="color: #008080;">;</span>
            RtlZeroMemory<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>mi, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>MOUSEINPUT<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            mi.<span style="color: #007788;">dwFlags</span> <span style="color: #000080;">=</span> MOUSEEVENTF_MOVE<span style="color: #008080;">;</span>
            mi.<span style="color: #007788;">dx</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
            mi.<span style="color: #007788;">dy</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
&nbsp;
            INPUT in<span style="color: #008080;">;</span>
            in.<span style="color: #007788;">type</span> <span style="color: #000080;">=</span> INPUT_MOUSE<span style="color: #008080;">;</span>
            in.<span style="color: #007788;">mi</span> <span style="color: #000080;">=</span> mi<span style="color: #008080;">;</span>
&nbsp;
            SendInput<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span>, <span style="color: #000040;">&amp;</span>in, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>in<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Every thirty seconds the program checks to see if the computer is idle. After three minutes of inactivity (and if the screensaver isn&#8217;t running), it moves the mouse cursor one pixel down and to the right. If I lock the workstation or manually activate the screensaver, the program won&#8217;t do anything. To compile this program, create a new empty C++ Win32 application project. Add a new cpp file, drop in the code above, and hit &#8220;Build Solution&#8221;.</p>
<p>Now the screensaver won&#8217;t be a nuisance when I&#8217;m trying to read. I just have to make sure to hit Win-L before I leave my desk!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unifieddiff.com/2009/05/12/dipping-duck/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OpenTN3270</title>
		<link>http://www.unifieddiff.com/2008/12/27/opentn3270/</link>
		<comments>http://www.unifieddiff.com/2008/12/27/opentn3270/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 09:17:10 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C++/CLI]]></category>
		<category><![CDATA[IBM Mainframe]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[TN3270]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.unifieddiff.com/?p=540</guid>
		<description><![CDATA[OpenTN3270 is a free terminal emulator for connecting to mainframes that support IBM 3270 terminals. Major features include basic colors, adjustable screen and font sizes, and SSL support. The emulator is a CLR library used by a front-end GUI. Source code for both is released under the GNU GPL. More information (including source code and [...]]]></description>
			<content:encoded><![CDATA[<p>OpenTN3270 is a free terminal emulator for connecting to mainframes that support IBM 3270 terminals. Major features include basic colors, adjustable screen and font sizes, and SSL support.</p>
<p>The emulator is a CLR library used by a front-end GUI. Source code for both is released under the <a href="http://www.gnu.org/copyleft/gpl.html">GNU GPL</a>.</p>
<p>More information (including source code and binary downloads) will come soon. This page is here to remind me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unifieddiff.com/2008/12/27/opentn3270/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FUSE Extension for PHP</title>
		<link>http://www.unifieddiff.com/2008/12/15/fuse-extension-for-php/</link>
		<comments>http://www.unifieddiff.com/2008/12/15/fuse-extension-for-php/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 01:24:03 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Fuse]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.unifieddiff.com/?p=122</guid>
		<description><![CDATA[Well, it&#8217;s official&#8230; I&#8217;m a geek. A few weeks ago I started writing an extension for the PHP runtime that provides bindings to libfuse. Back up a few months&#8212; I wrote a PHP script to screen-scrape the Trac web interface and allow me to grab source code to a project I&#8217;m working on. My solution [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it&#8217;s official&#8230; I&#8217;m a geek. A few weeks ago I started writing an extension for the PHP runtime that provides bindings to <a href="http://fuse.sourceforge.net/">libfuse</a>. Back up a few months&mdash; I wrote a PHP script to screen-scrape the <a href="http://trac.edgewall.org/">Trac</a> web interface and allow me to grab source code to a project I&#8217;m working on.</p>
<p>My solution worked but it was pretty ugly. So I wondered if it would be better to implement a FUSE file system to do the same task. Unfortunately PHP didn&#8217;t have bindings for libfuse at the time. After several failed attempts at using SWIG to automagically generate an extension, I came to the harsh realization that if I wanted FUSE bindings I&#8217;d have to do it myself. I mean&#8230; how hard could it be?</p>
<p>It actually wasn&#8217;t too bad. I read a bunch of non-existent documentation on the Zend API and went to work on a prototype. It took me about a week, but I now have a working PHP extension. I&#8217;ve also since implemented <a href="/projects/tracfs">TracFS</a> to replace my ugly script.</p>
<p><span id="more-122"></span></p>
<p>I&#8217;m almost finished with writing the documentation for the PHP website. To build the extension, you have to check out the sources from CVS.</p>
<pre>
$ svn co http://svn.php.net/repository/pecl/fuse/trunk/ php_fuse
$ cd php_fuse &amp;&amp; phpize
$ ./configure
$ make &amp;&amp; sudo make install
</pre>
<p>You&#8217;ll need to install PHP and FUSE (or <a href="http://code.google.com/p/macfuse/">MacFUSE</a>) before you can build the extension. Once everything is installed, you can test php_fuse with the scripts in pecl/fuse/examples. For now, the extension does not support writing files, only reading. Sometime in the near future I will implement the rest of the VFS callbacks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unifieddiff.com/2008/12/15/fuse-extension-for-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TracFS</title>
		<link>http://www.unifieddiff.com/2008/12/15/tracfs/</link>
		<comments>http://www.unifieddiff.com/2008/12/15/tracfs/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 03:16:19 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Fuse]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Shibboleth]]></category>

		<guid isPermaLink="false">http://www.unifieddiff.com/?p=534</guid>
		<description><![CDATA[TracFS is a mountable POSIX virtual file system that allows you to read a Subversion repository through the Trac web interface. Why is this useful? It&#8217;s not&#8230; unless you can&#8217;t access the repository directly, but can see the files in the source browser. Using rsync (or a similar tool), you can maintain a local copy [...]]]></description>
			<content:encoded><![CDATA[<p>TracFS is a mountable POSIX virtual file system that allows you to read a <a href="http://subversion.tigris.org/">Subversion</a> repository through the <a href="http://trac.edgewall.org/">Trac</a> web interface. Why is this useful? It&#8217;s not&#8230; unless you can&#8217;t access the repository directly, but can see the files in the source browser. Using rsync (or a similar tool), you can maintain a local copy of the repository contents.</p>
<p>TracFS uses <a href="http://fuse.sourceforge.net/">FUSE</a> for VFS operations and is written in PHP. It also supports authenticating with a <a href="http://shibboleth.internet2.edu/">Shibboleth</a> SSO gateway. Other authentication mechanisms can be easily added in the future.</p>
<p><span id="more-534"></span></p>
<h2>Install</h2>
<ul>
<li><strong>Install FUSE</strong> &mdash; You can use your distro&#8217;s package manager or visit the project site for manual installation instructions.
<ul>
<li><strong>Linux/BSD</strong> &mdash; <a href="http://fuse.sourceforge.net/">http://fuse.sourceforge.net/</a></li>
<li><strong>OS X</strong> &mdash; <a href="http://code.google.com/p/macfuse/">http://code.google.com/p/macfuse/</a></li>
</ul>
</li>
<li><strong>Install PHP</strong> &mdash; Consult the <a href="http://us.php.net/manual/en/install.general.php">PHP manual</a> for your platform.</li>
<li><strong>Install php_fuse</strong> &mdash; Follow the build instructions <a href="/2008/12/15/fuse-extension-for-php/">here</a>.</li>
<li><strong>Check out TracFS</strong> &mdash; Using a git client, check out <a href="http://github.com/rcarz/tracfs">http://github.com/rcarz/tracfs</a>.</li>
</ul>
<p>TracFS is licensed under the <a href="http://www.gnu.org/copyleft/gpl.html">GNU GPL</a>.</p>
<h2>How to Use</h2>
<p>Mounting a file system is very simple. Suppose you want to mount Trac&#8217;s source tree to /Volume/trac, you would execute:</p>
<pre>
$ mkdir /Volumes/trac
$ php ~/Desktop/tracfs/tracfs.php http://trac.edgewall.org/ /Volumes/trac
</pre>
<p>Tada! The Trac sources appear as regular files in your file manager.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unifieddiff.com/2008/12/15/tracfs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building Amarok 1.4 on Leopard</title>
		<link>http://www.unifieddiff.com/2008/06/30/building-amarok-14-on-leopard/</link>
		<comments>http://www.unifieddiff.com/2008/06/30/building-amarok-14-on-leopard/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 18:02:39 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Amarok]]></category>
		<category><![CDATA[Autotools]]></category>
		<category><![CDATA[Fink]]></category>
		<category><![CDATA[libxine]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://www.robertjcarroll.com/?p=31</guid>
		<description><![CDATA[I love Amarok and wanted to install it on my MacBook. With Qt4 on the horizon, it will be possible to run Amarok natively in OS X without an X server. But I didn&#8217;t want to wait for Amarok2 to become stable, so I looked into compiling Amarok 1.4 and running it under X. I [...]]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://amarok.kde.org/">Amarok</a> and wanted to install it on my MacBook. With Qt4 on the horizon, it will be possible to run Amarok natively in OS X without an X server. But I didn&#8217;t want to wait for Amarok2 to become stable, so I looked into compiling Amarok 1.4 and running it under X.</p>
<p>I tried following the <a href="http://amarok.kde.org/wiki/On_OS_X">On OS X</a> guide with limited success. Apparently, ffmpeg won&#8217;t compile on Leopard and that caused the entire libxine compilation to fail. I tried various combinations of configure flags, but none seemed to help. I looked at the source to try and fix it, but unfortunately I&#8217;m not terribly familiar with x86 assembly.</p>
<p><span id="more-31"></span></p>
<p>The problem code had to do with video rendering, so since Amarok doesn&#8217;t use it I just cut it out of the build process. Edit <strong>src/combined/ffmpeg/Makefile</strong> and find</p>
<pre>xineplug_LTLIBRARIES = xineplug_decode_ff.la xineplug_decode_dvaudio.la</pre>
<p>and replace with</p>
<pre>xineplug_LTLIBRARIES = xineplug_decode_dvaudio.la</pre>
</p>
<p>After that, edit <strong>src/post/Makefile</strong> and find</p>
<pre>SUBDIRS = planar goom visualizations mosaico deinterlace audio</pre>
<p>and replace with</p>
<pre>SUBDIRS = goom visualizations mosaico audio</pre>
<p>Now libxine will build.</p>
<p>With libxine installed, I had a few more steps to build Amarok. I installed taglib</p>
<pre>$ sudo fink install taglib</pre>
<p>I also had to specify the location of the OpenGL framework I wanted to use</p>
<pre>
LDFLAGS=&quot;-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/ \
  A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/ \
  A/Libraries/libGL.dylib&quot;
</pre>
<p>And finally, this is how I configured Amarok</p>
<pre>./configure --prefix=/sw --with-qt-includes=/sw/include/qt \
  --with-qt-libraries=/sw/lib/qt3/lib</pre>
</p>
<p>I now have Amarok successfully compiled and running on Leopard. This took me quite a bit of time to get right, so I&#8217;m hoping someone else will find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unifieddiff.com/2008/06/30/building-amarok-14-on-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Draw ListView with Double Buffering</title>
		<link>http://www.unifieddiff.com/2008/05/30/custom-draw-listview-with-double-buffering/</link>
		<comments>http://www.unifieddiff.com/2008/05/30/custom-draw-listview-with-double-buffering/#comments</comments>
		<pubDate>Sat, 31 May 2008 04:33:19 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C++/CLI]]></category>
		<category><![CDATA[GDI]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[Win32]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.robertjcarroll.com/?p=29</guid>
		<description><![CDATA[For one of my pet projects, I needed to add a graphic to certain ListView rows. I considered owner-drawing the control, but that seemed messy. What I really wanted was a way to draw on top of whatever Windows painted. I couldn&#8217;t find a nifty .NET way to do this, so remembering a technique from [...]]]></description>
			<content:encoded><![CDATA[<p>For one of my pet projects, I needed to add a graphic to certain ListView rows. I considered owner-drawing the control, but that seemed messy. What I really wanted was a way to draw on top of whatever Windows painted. I couldn&#8217;t find a nifty .NET way to do this, so remembering a technique from the MFC days, I decided to <a href="http://msdn.microsoft.com/en-us/library/bb761817(VS.85).aspx">custom draw</a> the ListView. This would let me inject my own drawing code and let Windows handle the rest. Perfect!</p>
<p>I had originally implemented the ListView using a control style to <a href="http://geekswithblogs.net/cpound/archive/2006/02/27/70834.aspx">eliminate the annoying flicker</a> every time the list was repainted. Once I started custom drawing the control, I saw odd artifacts in the ListView&#8217;s client area when I scrolled or moved the mouse. If I turned off double buffering, it worked fine.</p>
<p><span id="more-29"></span></p>
<p>I studied the custom draw process looking for my mistake, but I couldn&#8217;t find any. I even used the <a href="http://www.aisto.com/roeder/dotnet/">.NET Reflector</a> to look at Microsoft&#8217;s implementation. The message I&#8217;m filtering has a handle to the control&#8217;s back-buffer. So it seemed like I should just be able to draw directly into that. But no matter what I did, it produced the same artifacts.</p>
<p>After about three days of banging my head, I managed to make it work by drawing into my own buffer and then using <a href="http://msdn.microsoft.com/en-us/library/ms532278(VS.85).aspx">BitBlt()</a> to copy my image to the control&#8217;s buffer. I also had to set the double buffer style with a window message rather than using the built-in property, although admittedly, I&#8217;m not sure why.</p>
<p>I like visual aids, so here&#8217;s a code snippet from my project. I changed names and removed a bunch of unnecessary lines for easier reading.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &quot;stdafx.h&quot;</span>
<span style="color: #339900;">#include &quot;MyListViewControl.h&quot;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> MyListViewControl<span style="color: #008080;">;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> System<span style="color: #008080;">::</span><span style="color: #007788;">Drawing</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> System<span style="color: #008080;">::</span><span style="color: #007788;">Windows</span><span style="color: #008080;">::</span><span style="color: #007788;">Forms</span><span style="color: #008080;">;</span>
&nbsp;
MyListViewControl<span style="color: #008080;">::</span><span style="color: #007788;">MyListViewControl</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">bool</span> MyListViewControl<span style="color: #008080;">::</span><span style="color: #007788;">CustomDraw</span><span style="color: #008000;">&#40;</span>Message<span style="color: #000040;">%</span> m<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	System<span style="color: #008080;">::</span><span style="color: #007788;">Drawing</span><span style="color: #008080;">::</span><span style="color: #007788;">Rectangle</span><span style="color: #000040;">^</span> mprc<span style="color: #008080;">;</span>
	System<span style="color: #008080;">::</span><span style="color: #007788;">String</span><span style="color: #000040;">^</span> cchQueueIndex<span style="color: #008080;">;</span>
	ListViewItem<span style="color: #000040;">^</span> mpItem<span style="color: #008080;">;</span>
	LPNMCUSTOMDRAW lpnmcd<span style="color: #008080;">;</span>
	Graphics<span style="color: #000040;">^</span> mpgfx<span style="color: #008080;">;</span>
	HDC hmemdc<span style="color: #008080;">;</span>
	RECT sOrderRect<span style="color: #008080;">;</span>
	RECT sStopRect<span style="color: #008080;">;</span>
	Brush<span style="color: #000040;">^</span> mpbgbr<span style="color: #008080;">;</span>
	Brush<span style="color: #000040;">^</span> mpfgbr<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> nOrderLen<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> nOrderOffset<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> nRightEdge<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> nRectWidth<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> nItem<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Grab the custom draw info</span>
	lpnmcd <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>LPNMCUSTOMDRAW<span style="color: #008000;">&#41;</span>m.<span style="color: #007788;">LParam</span>.<span style="color: #007788;">ToPointer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Figure out which drawing stage we're in</span>
	<span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span>lpnmcd<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>dwDrawStage<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>	
&nbsp;
	<span style="color: #666666;">// Control Pre-paint</span>
	<span style="color: #0000ff;">case</span> <span style="color: #008000;">&#40;</span>CDDS_PREPAINT<span style="color: #008000;">&#41;</span><span style="color: #008080;">:</span>
&nbsp;
		<span style="color: #666666;">// Request to be notified during item draw</span>
		__super<span style="color: #008080;">::</span><span style="color: #007788;">WndProc</span><span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		m.<span style="color: #007788;">Result</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>System<span style="color: #008080;">::</span><span style="color: #007788;">IntPtr</span><span style="color: #008000;">&#41;</span>CDRF_NOTIFYITEMDRAW<span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
&nbsp;
&nbsp;
	<span style="color: #666666;">// List Item Pre-paint</span>
	<span style="color: #0000ff;">case</span> <span style="color: #008000;">&#40;</span>CDDS_ITEMPREPAINT<span style="color: #008000;">&#41;</span><span style="color: #008080;">:</span>
&nbsp;
		<span style="color: #666666;">// Request to be notified after item draw</span>
		__super<span style="color: #008080;">::</span><span style="color: #007788;">WndProc</span><span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		m.<span style="color: #007788;">Result</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>System<span style="color: #008080;">::</span><span style="color: #007788;">IntPtr</span><span style="color: #008000;">&#41;</span>CDRF_NOTIFYPOSTPAINT<span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
&nbsp;
&nbsp;
	<span style="color: #666666;">// List Item Post-paint</span>
	<span style="color: #0000ff;">case</span> <span style="color: #008000;">&#40;</span>CDDS_ITEMPOSTPAINT<span style="color: #008000;">&#41;</span><span style="color: #008080;">:</span>
&nbsp;
		__super<span style="color: #008080;">::</span><span style="color: #007788;">WndProc</span><span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #666666;">// Get the current item</span>
		nItem <span style="color: #000080;">=</span> <span style="color: #0000ff;">static_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>lpnmcd<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>dwItemSpec<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		mpItem <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>ListViewItem<span style="color: #000040;">^</span><span style="color: #008000;">&#41;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Items<span style="color: #008000;">&#91;</span>nItem<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>		
&nbsp;
		<span style="color: #666666;">// Get the device context and item bounds</span>
		mpgfx <span style="color: #000080;">=</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>CreateGraphics<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		mprc <span style="color: #000080;">=</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetItemRect<span style="color: #008000;">&#40;</span>nItem, ItemBoundsPortion<span style="color: #008080;">::</span><span style="color: #007788;">Label</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #666666;">// *** Your custom drawing code here ***</span>
&nbsp;
		<span style="color: #666666;">// Copy the bubble to the screen DC</span>
		hmemdc <span style="color: #000080;">=</span> <span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span>HDC<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">static_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">void</span><span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>mpgfx<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetHdc<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		BitBlt<span style="color: #008000;">&#40;</span> 
			lpnmcd<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>hdc, 
			sOrderRect.<span style="color: #007788;">left</span>, 
			mprc<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Y, 
			nRectWidth, 
			mprc<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Height, 
			hmemdc, 
			sOrderRect.<span style="color: #007788;">left</span>, 
			mprc<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Y, 
			SRCCOPY<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		mpgfx<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>ReleaseHdc<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>System<span style="color: #008080;">::</span><span style="color: #007788;">IntPtr</span><span style="color: #008000;">&#41;</span>hmemdc<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #666666;">// Let Windows redraw the border</span>
		m.<span style="color: #007788;">Result</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>System<span style="color: #008080;">::</span><span style="color: #007788;">IntPtr</span><span style="color: #008000;">&#41;</span>CDRF_DODEFAULT<span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> MyListViewControl<span style="color: #008080;">::</span><span style="color: #007788;">WndProc</span><span style="color: #008000;">&#40;</span>Message<span style="color: #000040;">%</span> m<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	LPNMHDR lpnmhdr<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span>m.<span style="color: #007788;">Msg</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #666666;">// Reflected Notifications</span>
	<span style="color: #0000ff;">case</span> <span style="color: #008000;">&#40;</span>OCM_NOTIFY<span style="color: #008000;">&#41;</span><span style="color: #008080;">:</span>
&nbsp;
		<span style="color: #666666;">// Get the notification</span>
		lpnmhdr <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>LPNMHDR<span style="color: #008000;">&#41;</span>m.<span style="color: #007788;">LParam</span>.<span style="color: #007788;">ToPointer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>lpnmhdr <span style="color: #000080;">==</span> <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #666666;">// We want custom draw messages</span>
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>lpnmhdr<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>code <span style="color: #000080;">==</span> NM_CUSTOMDRAW  
				<span style="color: #000040;">&amp;&amp;</span> lpnmhdr<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>hwndFrom <span style="color: #000080;">==</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Handle.<span style="color: #007788;">ToPointer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>CustomDraw<span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
				<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #008000;">&#125;</span>
&nbsp;
	__super<span style="color: #008080;">::</span><span style="color: #007788;">WndProc</span><span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

</p>
<p>And here&#8217;s the header file with the double buffering message call:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#pragma once</span>
&nbsp;
<span style="color: #0000ff;">namespace</span> MyListView
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">public</span> ref <span style="color: #0000ff;">class</span> MyListView <span style="color: #008080;">:</span> 
		<span style="color: #0000ff;">public</span> System<span style="color: #008080;">::</span><span style="color: #007788;">Windows</span><span style="color: #008080;">::</span><span style="color: #007788;">Forms</span><span style="color: #008080;">::</span><span style="color: #007788;">ListView</span>
	<span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
		<span style="color: #0000ff;">bool</span> CustomDraw<span style="color: #008000;">&#40;</span>System<span style="color: #008080;">::</span><span style="color: #007788;">Windows</span><span style="color: #008080;">::</span><span style="color: #007788;">Forms</span><span style="color: #008080;">::</span><span style="color: #007788;">Message</span><span style="color: #000040;">%</span> m<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
		<span style="color: #0000ff;">virtual</span> property <span style="color: #0000ff;">bool</span> DoubleBuffered
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">bool</span> get<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> override
			<span style="color: #008000;">&#123;</span>
				LRESULT lStyles <span style="color: #000080;">=</span> <span style="color: #008080;">::</span><span style="color: #007788;">SendMessage</span><span style="color: #008000;">&#40;</span> 
					<span style="color: #008000;">&#40;</span>HWND<span style="color: #008000;">&#41;</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Handle.<span style="color: #007788;">ToPointer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, 
					LVM_GETEXTENDEDLISTVIEWSTYLE, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
				<span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span>lStyles <span style="color: #000040;">&amp;</span> LVS_EX_DOUBLEBUFFER<span style="color: #008000;">&#41;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
			<span style="color: #008000;">&#125;</span>
&nbsp;
			<span style="color: #0000ff;">void</span> set <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">bool</span> fValue<span style="color: #008000;">&#41;</span> override
			<span style="color: #008000;">&#123;</span>
				<span style="color: #666666;">// I tried using the DoubleBuffered property, but I</span>
				<span style="color: #666666;">// get artifacts. So, let's do this the MFC way...</span>
				<span style="color: #008080;">::</span><span style="color: #007788;">SendMessage</span><span style="color: #008000;">&#40;</span> 
					<span style="color: #008000;">&#40;</span>HWND<span style="color: #008000;">&#41;</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Handle.<span style="color: #007788;">ToPointer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, 
					LVM_SETEXTENDEDLISTVIEWSTYLE, 
					LVS_EX_DOUBLEBUFFER, 
					LVS_EX_DOUBLEBUFFER<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
		<span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> WndProc<span style="color: #008000;">&#40;</span>System<span style="color: #008080;">::</span><span style="color: #007788;">Windows</span><span style="color: #008080;">::</span><span style="color: #007788;">Forms</span><span style="color: #008080;">::</span><span style="color: #007788;">Message</span><span style="color: #000040;">%</span> m<span style="color: #008000;">&#41;</span> override<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
		MyListViewControl<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

</p>
<p>I spend days searching online and couldn&#8217;t find anyone who talked about custom drawing a .NET ListView with double buffering. I hope somebody will find this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unifieddiff.com/2008/05/30/custom-draw-listview-with-double-buffering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

