<?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; COM</title>
	<atom:link href="http://www.unifieddiff.com/category/com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.unifieddiff.com</link>
	<description>I should do that! How hard could it be?!</description>
	<lastBuildDate>Sat, 30 Jan 2010 01:23:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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[COM]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Win32 & MFC]]></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>
<span id="more-207"></span>
<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: #666666;">// 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>
	</channel>
</rss>
