<?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>Dave Amenta .com &#187; Zune</title>
	<atom:link href="http://www.daveamenta.com/tag/zune/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daveamenta.com</link>
	<description>(dot (at dave daveamenta) com)</description>
	<lastBuildDate>Tue, 31 Jan 2012 17:22:23 +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>Zune Now Playing support for Digsby and Winamp-compatible nowplaying software.</title>
		<link>http://www.daveamenta.com/2010-07/zune-now-playing-support-for-digsby-and-winamp-compatible-nowplaying-software/</link>
		<comments>http://www.daveamenta.com/2010-07/zune-now-playing-support-for-digsby-and-winamp-compatible-nowplaying-software/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 18:42:38 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Zune]]></category>

		<guid isPermaLink="false">http://www.daveamenta.com/?p=542</guid>
		<description><![CDATA[The Zune media player delivers Now Playing information to Windows Live Messenger, but other software isn&#8217;t able to pick up these messages.  Quite a few users have asked for Zune Now Playing support in Digsby, so I put together this little app that lets this work.  The application itself is generic, converting Zune now playing [...]]]></description>
			<content:encoded><![CDATA[<p>The Zune media player delivers Now Playing information to Windows Live Messenger, but other software isn&#8217;t able to pick up these messages.  Quite a few users have asked for <a href="http://forum.digsby.com/viewtopic.php?id=614" target="_blank">Zune Now Playing support in Digsby</a>, so I put together this little app that lets this work.  The application itself is generic, converting Zune now playing messages into the more widely implemented Winamp now playing method.</p>
<p>Download the <a href="/download/Digsby-Zune.zip">executable and source (C++)</a>.</p>
<p>Code Listing:</p>

<div class="wp_syntax"><div 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;ZuneNowPlaying.h&quot;</span>
<span style="color: #339900;">#include &quot;LimitSingleInstance.h&quot; // KB243953</span>
<span style="color: #339900;">#include &lt;regex&gt;</span>
&nbsp;
<span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">tr1</span><span style="color: #008080;">::</span><span style="color: #007788;">wregex</span> pattern<span style="color: #008000;">&#40;</span>L<span style="color: #FF0000;">&quot;.*?<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>0Music<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>0.*?<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>0.*?<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>0(.*?)<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>0(.*?)<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>0&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
CLimitSingleInstance g_SingleInstanceObj<span style="color: #008000;">&#40;</span>L<span style="color: #FF0000;">&quot;{24F3CD83-9FFE-4DE6-951D-63958942F834}&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
HWND hWndWinamp<span style="color: #008080;">;</span>
HWND hWndWindowsLiveMessenger<span style="color: #008080;">;</span>
&nbsp;
LRESULT CALLBACK WndProc<span style="color: #008000;">&#40;</span>HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span>message<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">case</span> WM_COPYDATA<span style="color: #008080;">:</span>
			<span style="color: #008000;">&#123;</span>
				COPYDATASTRUCT <span style="color: #000040;">*</span>cds <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>COPYDATASTRUCT<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>lParam<span style="color: #008080;">;</span>
				<span style="color: #0000ff;">wchar_t</span> <span style="color: #000040;">*</span>str <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">wchar_t</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>cds<span style="color: #000040;">-</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span>lpData<span style="color: #008080;">;</span>
&nbsp;
				std<span style="color: #008080;">::</span><span style="color: #007788;">tr1</span><span style="color: #008080;">::</span><span style="color: #007788;">wcmatch</span> result<span style="color: #008080;">;</span>
				<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">tr1</span><span style="color: #008080;">::</span><span style="color: #007788;">regex_search</span><span style="color: #008000;">&#40;</span>str, result, pattern<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
				<span style="color: #008000;">&#123;</span>
					std<span style="color: #008080;">::</span><span style="color: #007788;">wstring</span> ret <span style="color: #000080;">=</span> result<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span>.<span style="color: #007788;">str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> L<span style="color: #FF0000;">&quot; - &quot;</span> <span style="color: #000040;">+</span> result<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span>.<span style="color: #007788;">str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
					SetWindowText<span style="color: #008000;">&#40;</span>hWndWinamp, ret.<span style="color: #007788;">c_str</span><span style="color: #008000;">&#40;</span><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: #0000ff;">else</span>
				<span style="color: #008000;">&#123;</span>
					SetWindowText<span style="color: #008000;">&#40;</span>hWndWinamp, L<span style="color: #FF0000;">&quot;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
				<span style="color: #008000;">&#125;</span>
				<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #0000ff;">case</span> WM_DESTROY<span style="color: #008080;">:</span>
			PostQuitMessage<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">case</span> WM_USER<span style="color: #008080;">:</span>
			<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>lParam <span style="color: #000080;">==</span> <span style="color: #0000dd;">104</span><span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> <span style="color: #666666;">// Winamp=Playing (always)</span>
			<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span> DefWindowProc<span style="color: #008000;">&#40;</span>hWnd, message, wParam, lParam<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> RegisterClasses<span style="color: #008000;">&#40;</span>HINSTANCE hInstance<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	WNDCLASSEX wcex <span style="color: #000080;">=</span> WNDCLASSEX<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	wcex.<span style="color: #007788;">cbSize</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>WNDCLASSEX<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	wcex.<span style="color: #007788;">lpfnWndProc</span>	<span style="color: #000080;">=</span> WndProc<span style="color: #008080;">;</span>
	wcex.<span style="color: #007788;">hInstance</span>		<span style="color: #000080;">=</span> hInstance<span style="color: #008080;">;</span>
	wcex.<span style="color: #007788;">hbrBackground</span>	<span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>HBRUSH<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>COLOR_WINDOW<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	wcex.<span style="color: #007788;">lpszClassName</span>	<span style="color: #000080;">=</span> L<span style="color: #FF0000;">&quot;MsnMsgrUIManager&quot;</span><span style="color: #008080;">;</span>
	RegisterClassEx<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>wcex<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	wcex.<span style="color: #007788;">lpszClassName</span>	<span style="color: #000080;">=</span> L<span style="color: #FF0000;">&quot;Winamp v1.x&quot;</span><span style="color: #008080;">;</span>
	RegisterClassEx<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>wcex<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">bool</span> CreateWindows<span style="color: #008000;">&#40;</span>HINSTANCE hInstance<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">// Pretend to be Windows Live Messenger, so WM_COPYDATA messages are sent to us.</span>
	hWndWindowsLiveMessenger <span style="color: #000080;">=</span> CreateWindow<span style="color: #008000;">&#40;</span>L<span style="color: #FF0000;">&quot;MsnMsgrUIManager&quot;</span>, L<span style="color: #FF0000;">&quot;&quot;</span>, WS_DISABLED,
		CW_USEDEFAULT, <span style="color: #0000dd;">0</span>, CW_USEDEFAULT, <span style="color: #0000dd;">0</span>, <span style="color: #0000ff;">NULL</span>, <span style="color: #0000ff;">NULL</span>, hInstance, <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">// Pretend to be Winamp (any version), so apps will pick us up for Now Playing.</span>
	hWndWinamp <span style="color: #000080;">=</span> CreateWindow<span style="color: #008000;">&#40;</span>L<span style="color: #FF0000;">&quot;Winamp v1.x&quot;</span>, L<span style="color: #FF0000;">&quot;&quot;</span>, WS_DISABLED,
		CW_USEDEFAULT, <span style="color: #0000dd;">0</span>, CW_USEDEFAULT, <span style="color: #0000dd;">0</span>, <span style="color: #0000ff;">NULL</span>, <span style="color: #0000ff;">NULL</span>, hInstance, <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> hWndWinamp <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span> hWndWindowsLiveMessenger<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> APIENTRY _tWinMain<span style="color: #008000;">&#40;</span>HINSTANCE hInstance, HINSTANCE <span style="color: #ff0000; font-style: italic;">/*hPrevInstance*/</span>, LPTSTR <span style="color: #ff0000; font-style: italic;">/*lpCmdLine*/</span>, <span style="color: #0000ff;">int</span> <span style="color: #ff0000; font-style: italic;">/*nCmdShow*/</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	MSG msg <span style="color: #000080;">=</span> MSG<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><span style="color: #000040;">!</span>g_SingleInstanceObj.<span style="color: #007788;">IsAnotherInstanceRunning</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>
		RegisterClasses<span style="color: #008000;">&#40;</span>hInstance<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>CreateWindows<span style="color: #008000;">&#40;</span>hInstance<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>GetMessage<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>msg, <span style="color: #0000ff;">NULL</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				TranslateMessage<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>msg<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
				DispatchMessage<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>msg<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>msg.<span style="color: #007788;">wParam</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #000080;">&lt;</span><span style="color: #000040;">/</span>regex<span style="color: #000080;">&gt;</span></pre></div></div>

<p><strong>How it works:</strong></p>
<p>It&#8217;s pretty simple, Zune software sends a WM_COPYDATA message to a window with class name <strong>MsnMsgrUIManager</strong>, the message contains a pointer to a unicode string, that looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">ZUNE\0Music\<span style="color: #208080;">01</span>\<span style="color: #0000dd;">0</span><span style="color: #008000;">&#123;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#125;</span> <span style="color: #000040;">-</span> <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#125;</span>\0TRACK_TITLE\0TRACK_ARTIST\0TRACK_ALBUM\0zune<span style="color: #008080;">:</span>ZUNE_GUID\<span style="color: #0000dd;">0</span>
&nbsp;
<span style="color: #666666;">// TRACK_TITLE: Title</span>
<span style="color: #666666;">// TRACK_ARTIST: Artist</span>
<span style="color: #666666;">// TRACK_ALBUM: Album</span>
<span style="color: #666666;">// ZUNE_GUID:  A GUID that may refer to the Zune device, Zune account, or Zune software itself.</span>
&nbsp;
<span style="color: #666666;">// Note:  {0} - {1} is the format of how the string should be displayed in WLM - I ignore this entirely.</span>
<span style="color: #666666;">// Note2:  This method is used by other software, so I don't gate on ZUNE for the sake of maximum flexibility.  </span>
<span style="color: #666666;">// Note3:  The &quot;1&quot; after Music specifies the playing state.  0=Stopped, 1=Playing.  I ignore this and instead just use whether or not the other fields exist.</span></pre></div></div>

<p>Note:  The \0&#8242;s in the above string are literally \ and 0, not NULL characters.</p>
<p>Using a regular expression to match the fields, The artist and title are extracted from the string, and set as the window caption for a window with class name <strong>Winamp v1.x</strong>.  Software (like Digsby, or other now playing apps) may use <a href="http://msdn.microsoft.com/en-us/library/ms633499(VS.85).aspx" target="_blank">FindWindow</a> to locate the fake Winamp player, and read the caption with <a href="http://msdn.microsoft.com/en-us/library/ms633520(VS.85).aspx" target="_blank">GetWindowText</a>.</p>
<p>You may need to install the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=a7b7a05e-6de6-4d3a-a423-37bf0912db84&#038;displaylang=en">Microsoft Visual C++ 2010 Redistributable Package (x86)</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveamenta.com/2010-07/zune-now-playing-support-for-digsby-and-winamp-compatible-nowplaying-software/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

