<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>UberDemo : WPF</title><link>http://blogs.msdn.com/uberdemo/archive/tags/WPF/default.aspx</link><description>Tags: WPF</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Circumventing an IE/Flash Display Issue in the WPF WebBrowser control on x64 machines</title><link>http://blogs.msdn.com/uberdemo/archive/2009/07/09/circumventing-an-ie-flash-display-issue-in-the-wpf-webbrowser-control-on-x64-machines.aspx</link><pubDate>Thu, 09 Jul 2009 19:29:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9827086</guid><dc:creator>uberdemo</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/uberdemo/comments/9827086.aspx</comments><wfw:commentRss>http://blogs.msdn.com/uberdemo/commentrss.aspx?PostID=9827086</wfw:commentRss><description>&lt;p&gt;Recently I wrote some code with the intent to display an embedded YouTube Flash video in Window Presentation Foundation’s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx" target="_blank"&gt;WebBrowser&lt;/a&gt; control. I ran into an interesting problem. Internet Explorer displayed a broken object icon on some machines, but not others. After some investigation it appeared that the Flash video was displaying properly on x86 machines and failing to appear on x64 machines. Apparently the x64 build of the WPF application spawns an x64 instance of IE. The Flash object does not display, since IE attempts to load the x64 version of Flash, which incidentally does not yet exist for x64 versions of Windows.&lt;/p&gt; &lt;p&gt;To solve the problem, set the compiler to explicitly compile the app to x86, and it becomes a non-issue. The downside is that the app can no longer take advantage of x64 capabilities, but for many cases this is probably fine.&lt;/p&gt; &lt;p&gt;Incidentally here is the code that I used:&lt;/p&gt; &lt;p&gt;private string embedded = "&amp;lt;html style=\"margin:0 0 0 0; background-color:Black; overflow:hidden\"&amp;gt;" + &lt;br&gt;"&amp;lt;script event=onload for=window&amp;gt;document.body.scroll=\"no\"&amp;lt;/script&amp;gt;"+ "&amp;lt;object width=\"425\" height=\"344\"&amp;gt;" + &lt;br&gt;"&amp;lt;param name=\"movie\" value=\"http://www.youtube.com/v/{0}&amp;amp;hl=en&amp;amp;fs=1\"&amp;gt;&amp;lt;/param&amp;gt;" + &lt;br&gt;"&amp;lt;param name=\"allowFullScreen\" value=\"true\"&amp;gt;&amp;lt;/param&amp;gt;" + "&amp;lt;param name=\"allowscriptaccess\" value=\"always\"&amp;gt;&amp;lt;/param&amp;gt;" + &lt;br&gt;"&amp;lt;embed src=\"http://www.youtube.com/v/{0}&amp;amp;hl=en&amp;amp;fs=1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"425\" height=\"344\"&amp;gt;&amp;lt;/embed&amp;gt;" + &lt;br&gt;"&amp;lt;/object&amp;gt;&amp;lt;/html&amp;gt;"; &lt;/p&gt; &lt;p&gt;WebBrowser wb = new WebBrowser();&lt;br&gt;wb.Width = 425;&lt;br&gt;wb.Height = 344;&lt;br&gt;wb.NavigateToString(string.Format(embeded, passInPathToVideo));&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9827086" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/uberdemo/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/Interop/default.aspx">Interop</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/Internet+Explorer/default.aspx">Internet Explorer</category></item><item><title>Glimmer Released!</title><link>http://blogs.msdn.com/uberdemo/archive/2009/04/28/glimmer-released.aspx</link><pubDate>Wed, 29 Apr 2009 01:23:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9574444</guid><dc:creator>uberdemo</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/uberdemo/comments/9574444.aspx</comments><wfw:commentRss>http://blogs.msdn.com/uberdemo/commentrss.aspx?PostID=9574444</wfw:commentRss><description>&lt;p&gt;The Mix Online_ team has just released their latest work: Glimmer. Glimmer is a WPF tool that generates jQuery so that you can easily create effects for your website! Check it out at &lt;a href="http://www.visitmix.com/lab/glimmer"&gt;http://www.visitmix.com/lab/glimmer&lt;/a&gt;&lt;/p&gt;&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="304" height="228"&gt;   &lt;param name="source" value="http://channel9.msdn.com/App_Themes/default/VideoPlayer2009_02_24.xap" /&gt;   &lt;param name="initParams" value="m=http://mschannel9.vo.msecnd.net/o9/mix/labs/glimmer/glimmer.wmv,autostart=false,autohide=true,showembed=true, thumbnail=http://mschannel9.vo.msecnd.net/o9/mix/labs/glimmer/glimmerVideo.jpg, postid=0" /&gt;   &lt;param name="background" value="#00FFFFFF" /&gt;   &lt;a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"&gt;   &lt;img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /&gt;   &lt;/a&gt;   &lt;/object&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9574444" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/uberdemo/archive/tags/Design/default.aspx">Design</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/jQuery/default.aspx">jQuery</category></item><item><title>MIX09’ing it up with a Tetris Version of Flotzam</title><link>http://blogs.msdn.com/uberdemo/archive/2009/03/20/mix09-ing-it-up-with-a-tetris-version-of-flotzam.aspx</link><pubDate>Fri, 20 Mar 2009 20:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9492909</guid><dc:creator>uberdemo</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/uberdemo/comments/9492909.aspx</comments><wfw:commentRss>http://blogs.msdn.com/uberdemo/commentrss.aspx?PostID=9492909</wfw:commentRss><description>&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image002_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image002_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image002 border=0 alt=clip_image002 src="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image002_thumb.jpg" width=244 height=159 mce_src="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image002_thumb.jpg"&gt;&lt;/A&gt; 
&lt;P&gt;For MIX09, our team decided to create a new look for Flotzam that was to be shown prior to the keynotes. We’d thought about possibly creating a Vegas slot machine version, but we ended up choosing Tetris, since it was very much in line with the #MIX09 theme. It sounded like an exciting project, so I jumped on it! &lt;A href="http://systim.spaces.live.com/" mce_href="http://systim.spaces.live.com/"&gt;Tim Aidlin&lt;/A&gt; designed the user experience and the look and feel, and &lt;A href="http://rhizohm.net/irhetoric" mce_href="http://rhizohm.net/irhetoric"&gt;Karsten Januszewski&lt;/A&gt; modified the data object model to support binding a single data template type to any one of the available Flotzam data sources collected from the various feeds: Twitter, Flickr, RSS, etc. 
&lt;P&gt;We brainstormed about what we wanted it to do, and settled on creating a somewhat simplified version of Tetris that avoided rotating the blocks. Flotzam Tetris needed to specifically target the 16x9 format used in the MIX09 keynote screens. This translated into 1280px by 720px dimensions, a fairly low resolution by today’s standards, which forced us to experiment with shape sizes. We needed to keep a careful balance between ensuring readability of the text in the back row of the keynote sessions while looking esthetically pleasing; the less blocks on screen, the less compelling it appears. 
&lt;P&gt;The Tetris logic itself was simple enough; I found several samples on the web to draw from. I chose to borrow some ideas from the CodePlex &lt;A href="http://code.msdn.microsoft.com/WPFTetris/Release/ProjectReleases.aspx?ReleaseId=382" mce_href="http://code.msdn.microsoft.com/WPFTetris/Release/ProjectReleases.aspx?ReleaseId=382"&gt;WPF Tetris&lt;/A&gt; that Karsten showed me, but this only got us about halfway. Absent was how to programmatically solve which Tetris blocks should fall based on the pieces that had already fallen. There are probably a few ways to solve this problem. I chose to take a commonly used game approach of using a buffer for the Tetris shapes defined as an array of integers, which I’ll call a &lt;B&gt;table&lt;/B&gt;. Zero represents an empty space, and a one represents a space occupied by a &lt;B&gt;block,&lt;/B&gt; the fundamental unit that makes up Tetris shapes. It turned out to be convenient to use integers since it very was handy to add up columns and rows for calculating when a row was full or calculating the total height of a stack of shapes for a particular column. 
&lt;P&gt;The shapes are defined in the &lt;B&gt;TetrisShape&lt;/B&gt; class. The individual blocks that compose a shape are represented in a Point array offset from a (0,0) origin. The TetrisShape class also contains a &lt;B&gt;Position&lt;/B&gt; property that maintains the absolute position of a TetrisShape shape in the table. 
&lt;P&gt;There are two other interesting parts to the TetrisShape class. The first is a &lt;B&gt;Weight&lt;/B&gt; property that allows us to define how important the shape is, so that we can get a better spread of shape usage. It’s used in determining the probability that it will be chosen as the “next” shape to be dropped. The second is the &lt;B&gt;ShapeSignature()&lt;/B&gt; method which returns a series of numbers, as a string, that define the “signature” of the bottom of a shape. So for example a 2 x 2 square would have a signature of “00”, or a 3 x 2 Tee shape would have a signature of “101”. The numbers represent the distance to the bottom block from an imaginary line running under the shape. This reason that this signature is returned as a string is so that string operators can be used to match the signature of a shape to the signature of all the other shapes settled in the table. 
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image004_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image004_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image004 border=0 alt=clip_image004 src="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image004_thumb.jpg" width=158 height=159 mce_src="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image004_thumb.jpg"&gt;&lt;/A&gt; &lt;A href="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image006_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image006_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image006 border=0 alt=clip_image006 src="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image006_thumb.jpg" width=193 height=149 mce_src="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/MIX09ingitupwithaTetrisVersionofFlotzam_9077/clip_image006_thumb.jpg"&gt;&lt;/A&gt; 
&lt;P&gt;Fig. 1: Example of the signature of a Square shape vs. a Tee shape. 
&lt;P&gt;The &lt;B&gt;GetShapeNeededInTable()&lt;/B&gt; method returns the signature of entire width of the bottom of the table. This is a function that examines the height of the columns of the settled shapes in the table to obtain the signature. Once we have this, we can see if a shape can fit in the table by simply calling: ShapeNeeded.Contains(ts.ShapeSignature()). If the call returns true it’s a suitable shape and the shape is stored it in a temporary list that gets sorted based on the TetrisShape Weight property. If there’s more than one shape in the temporary list it randomly chooses one of the shapes with the two highest weights and returns the chosen shape. 
&lt;P&gt;The shape chosen then gets bound to the data source and gets added to the VisualTree and displayed on screen. When a row is completed it causes all the “settled” shapes to drop down one level. If a shape drops below the bottom threshold it gets removed from the VisualTree and also the table shape list to prevent a memory leak. 
&lt;P&gt;The main loop is the &lt;STRONG&gt;RunTetrisFlotzam()&lt;/STRONG&gt; method, which is called at regular intervals by a timer (.7 seconds in by default.) This method contains a method that determines whether a shape can drop down or whether it is “settled” it also calls a function that animates the shapes from one position to the next in a programmatic manner. We wanted the animation to have easing, but it would take a bit of reorganization of the code to make this happen. 
&lt;P&gt;You’ll find the source code for Flotzam and Tetris Flotzam &lt;A href="http://flotzam.com/" mce_href="http://flotzam.com/"&gt;here&lt;/A&gt;. This was a fun project and perhaps you can make some interesting modifications to it. If you do, be sure to let us &lt;A href="mailto:mixon@microsoft.com" mce_href="mailto:mixon@microsoft.com"&gt;know&lt;/A&gt;! &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9492909" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/uberdemo/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/Flotzam/default.aspx">Flotzam</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/Tetris/default.aspx">Tetris</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/MIX09/default.aspx">MIX09</category></item><item><title>Capturing a WebCam stream to a WMV file from within a WPF application</title><link>http://blogs.msdn.com/uberdemo/archive/2008/03/27/capturing-a-webcam-stream-to-a-wmv-file-from-within-a-wpf-application.aspx</link><pubDate>Fri, 28 Mar 2008 00:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8340416</guid><dc:creator>uberdemo</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/uberdemo/comments/8340416.aspx</comments><wfw:commentRss>http://blogs.msdn.com/uberdemo/commentrss.aspx?PostID=8340416</wfw:commentRss><description>&lt;P&gt;I was asked to help out with a demo, my assignment was to capture some video from a WebCam that was to be used for the Cirque du Soleil demo for MIX08. There were a few ways to do this, none which were obviously attractive. There are many 3&lt;SUP&gt;rd&lt;/SUP&gt; party tools that capture video and output to a file, but none I found were extendable and usable from within an application. Another thought was to use the DirectX API’s to do the capture, but this required some fairly involved interop. Windows Media Encoder was not an obvious choice, but to my delight ended up being perfect for the job. I was satisfied with the results. Windows Media Encoder Series 9 has type libraries that expose its COM API’s and can be added to a Visual Studio project directly as references. Visual Studio automatically generates Runtime Callable Wrappers for them.&lt;/P&gt;
&lt;P&gt;This is a not a production quality sample, but I thought it still lhad some value getting it out there, since I spent quite some time finding out how to go about this.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;A few things to mention up front&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;· The Windows Media Encoder Series 9 (WME9 from here on) has a bug on Windows Vista that requires a hotfix to be installed. It &lt;U&gt;needs&lt;/U&gt; to be installed as an Administrator of the machine. You can run it as a non-Admin, but the hotfix will &lt;U&gt;not&lt;/U&gt; install properly and will not report errors. If you find that anytime you access WME9 code (on Vista) and the application crashes without error, you can be sure that the hotfix is not installed properly.&lt;/P&gt;
&lt;P&gt;· This sample shows at a basic level how to access audio level information via a Managed DirectX API (Microsoft.DirectX.DirectSound is the DLL referenced) and so requires installing some managed DLL’s. I happened to find these DLLs in the Microsoft LifeCam install, so that’s how I installed them, instead of installing the entire Managed DirectX SDK. There may be a faster/better way to install these DLL’s but I haven’t taken the time to look around for it. If you decide not to install this software, you will need to comment the relevant code.&lt;/P&gt;
&lt;P&gt;· You will need a WebCam that functions on your PC to run this sample. This means that you need to install your WebCam’s software and ensure that it works outside of the context of this sample. I myself used the a Microsoft Vx6000 LifeCam, but I’ve tested this app with two other WebCams without issue. The application detects and lists the WebCam in a ComboBox on application launch.&lt;/P&gt;
&lt;P&gt;· This application was built in Visual Studio 2008, and will also open properly in Expression Blend 2.0 Beta (February). A DesignTimeHelper class has been added to make it easier to see some of the application elements in the designer at design-time.&lt;/P&gt;
&lt;P&gt;· To run this project in Visaul Studio you will need to uncheck the “Loader Lock” thrown checkbox due to the audio level code. To get to this dialog choose Debug -&amp;gt; Exceptions from the Visual Studio menu and expand the “Managed Debugging Assistants” node.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/CapturingaWebCamstreamtoaWMVfilefromwith_C724/clip_image002_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/CapturingaWebCamstreamtoaWMVfilefromwith_C724/clip_image002_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=128 alt=clip_image002 src="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/CapturingaWebCamstreamtoaWMVfilefromwith_C724/clip_image002_thumb.jpg" width=244 border=0 mce_src="http://blogs.msdn.com/blogfiles/uberdemo/WindowsLiveWriter/CapturingaWebCamstreamtoaWMVfilefromwith_C724/clip_image002_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Installing and running the sample&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;1. Install WME9 from: &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=5691ba02-e496-465a-bba9-b2f1182cdf24&amp;amp;DisplayLang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=5691ba02-e496-465a-bba9-b2f1182cdf24&amp;amp;DisplayLang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyID=5691ba02-e496-465a-bba9-b2f1182cdf24&amp;amp;DisplayLang=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;2. [optional] Install the WME9 SDK from: &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=000a16f5-d62b-4303-bb22-f0c0861be25b&amp;amp;DisplayLang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=000a16f5-d62b-4303-bb22-f0c0861be25b&amp;amp;DisplayLang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyID=000a16f5-d62b-4303-bb22-f0c0861be25b&amp;amp;DisplayLang=en&lt;/A&gt; (The WME9 SDK ended up being very helpful, although I found that the samples in the “samples” directories were not as helpful as the actual content in the CHM file. There are complete samples hidden in the text of the CHM files that were enlightening.)&lt;/P&gt;
&lt;P&gt;3. [required for Windows Vista only] Copy the WME9 hotfix locally from: &lt;A href="http://download.microsoft.com/download/0/3/d/03d35c05-67da-40e0-9e45-3ea0ca6329a4/windowsmedia9-kb929182-intl.exe" mce_href="http://download.microsoft.com/download/0/3/d/03d35c05-67da-40e0-9e45-3ea0ca6329a4/windowsmedia9-kb929182-intl.exe"&gt;http://download.microsoft.com/download/0/3/d/03d35c05-67da-40e0-9e45-3ea0ca6329a4/windowsmedia9-kb929182-intl.exe&lt;/A&gt; (Right-click and choose “Run as Administrator” to install)&lt;/P&gt;
&lt;P&gt;4. Install the Microsoft LifeCam Software from: &lt;A href="http://download.microsoft.com/download/1/9/5/195512A9-1C1E-4429-BFF0-613D8D92E122/LC14.exe" mce_href="http://download.microsoft.com/download/1/9/5/195512A9-1C1E-4429-BFF0-613D8D92E122/LC14.exe"&gt;http://download.microsoft.com/download/1/9/5/195512A9-1C1E-4429-BFF0-613D8D92E122/LC14.exe&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;5. Copy the sample project bits from &lt;A href="http://www.hugli.org/code/videoencoder/videoencoder.zip" mce_href="http://www.hugli.org/code/videoencoder/videoencoder.zip"&gt;http://www.hugli.org/code/videoencoder/videoencoder.zip&lt;/A&gt; expand it and place the VideoEncoder directory in a directory of your choice. Typically I place content in a c:\users\public\demos directory, since this directory is accessible from all profiles without security issues.&lt;/P&gt;
&lt;P&gt;6. Install any necessary software for your WebCam and plug it in.&lt;/P&gt;
&lt;P&gt;7. Launch the project in Visual Studio 2008.&lt;/P&gt;
&lt;P&gt;8. Modify the OUTPUT_PATH to be a directory that your identity has write access to. The path c:\users\public is the default and will work on Vista, however for XP you will need to modify this path.&lt;/P&gt;
&lt;P&gt;9. Press F5. After the application launches you should see two ComboBox’s and a clickable image. &lt;/P&gt;
&lt;P&gt;10. Choose your WebCam from the “Video Source” Combobox and use the default profile (384 Kbps.)&lt;/P&gt;
&lt;P&gt;11. Click on the image and a video dialog will fade/animate in.&lt;/P&gt;
&lt;P&gt;12. Press “Begin Recording.” There will be a slight delay and a video preview will appear on the video dialog. Note that there are also crosshairs, recording status and progress bars to indicate audio level that overlay the video. &lt;/P&gt;
&lt;P&gt;13. Press the “Record” button and you will see timecode start advancing in the video overlay.&lt;/P&gt;
&lt;P&gt;14. Press the “Save” button and the video strean will be closed and saved to disk in the directory specified in OUTPUT_PATH. &lt;/P&gt;
&lt;P&gt;15. The video is then added to a WrapPanel as a MediaElement&lt;/P&gt;
&lt;P&gt;16. End Sample.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;How was sample done?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Now I’m going to cover the application and some of its hidden subtlties. I wrote this sample in a couple of days since the demo had to be put together in short order. If I had more time, I’d break out the audio related content into its own class and spend some time cleaning up the VideoEncoder class that wraps up all the encoding logic. Another thing that I would do is break out the VideoWindow code into its own UserControl. UserControls cannot draw outside of its own bounds so you would need to allow the UserControl to span the width/height of the entire application to allow for the video fadein animation. There are some problems in the code at present. The most troublesome is that sometimes I find that when capturing video the encoder captures only blank video, and I haven’t found the cause of it yet.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;WME9 archiving&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;One thing that confused me about WME9 initially was that as soon as the Encoder was started the video started capturing to disk and it was only then that a a preview would show up in the preview drawing surface (both happened simultaneously). What I really wanted instead was to see the video preview *before* I began capturing the video, so that I could center my WebCam on my subject, and then and only then start the video capture to disk. Well, it turns out that when the Encoder is started, the video starts capturing (Archiving as they refer to it) immediately, by default. To change the behaviour to what I wanted, i.e. to see a preview before the video captured begins, I needed to set the Encoder.EnableAutoArchive property to false (from its default true), and then start the Encoder. At this point the preview begins displaying in the application, and then we can optionally start the video capture by clicking on the “Begin Recording” button with this call:&lt;/P&gt;
&lt;P&gt;Encoder.Archive(WMENC_ARCHIVE_TYPE.WMENC_ARCHIVE_LOCAL, WMENC_ARCHIVE_OPERATION.WMENC_ARCHIVE_START);&lt;/P&gt;
&lt;P&gt;Encoder.PrepareToEncode(true);&lt;/P&gt;
&lt;P&gt;and end the video capture with this call: &lt;/P&gt;
&lt;P&gt;Encoder.Archive(WMENC_ARCHIVE_TYPE.WMENC_ARCHIVE_LOCAL, WMENC_ARCHIVE_OPERATION.WMENC_ARCHIVE_STOP);&lt;/P&gt;
&lt;P&gt;It’s also good to know that if you want to capture to an entirely new “archive” file, you will need to stop the encoder, redefine the capture file info and then restart the encoder.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Interop&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;To get the Video to display in a WPF application took some simple interop. It was interesting for me to find out that you can get a Handle from all WPF elements using IntPtr handle = ((System.Windows.Interop.HwndSource)myElement).Handle so that I could have the video draw on a specific element, but all elements returned the same Handle (the parent windows Handle.) This wasn’t very useful since the video ended up being drawn inside the entire Window no matter which element I chose. To workaround this, I instead created a WindowsFormsHost element and added it to the VisualTree. I then added a System.Windows.Forms.Panel as a child to that WindowsFormsHost (note it is important that the WindowsFormsHost has a child, since the WindowsFormHost element itself gives you the handle of the parent Window, which again is not what we want. The differentiating factor is that System.Windows.Forms controls have a Handle property which makes it very convenient to get the Handle. All System.Windows.Forms.Panel controls are Windows themselve’s. This makes it easy to grab a handle and draw within the bounds of the panel. It should be noted that having all controls be windows can lead to resource and performace problems for large numbers of children, this is not an issue in WPF. The Handle property returns a System.IntPtr which we then pass directly to the Preview.SetViewProperties method along with the video stream itself. Doing this draws on the panel.&lt;/P&gt;
&lt;P&gt;When you draw directly on a surface using this technique, there is a side-effect in a WPF application; you no longer can see WPF elements residing on top of this drawing surface anywhere in the VisualTree. I call it a “black hole”, since it obscures or cuts a hole into any window-less elements you try to place on top of it, whether a child element or an element with a higher z-order. This is essentially because the OS can only address something with a handle (a Window in this case) and so it draws the video after all the other elements in the WPF window are drawn.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Video overlay&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;So how then was the video overlay done? It was accomplished by placing yet another Window on top of the video. The WPF Popup element just happens to be a Window with its own handle. There is a side-effect to this technique: if the parent window is moved, you will find that the Popup doesn’t move along with the parent. This can be remedied by subcribing to the Window.LocationChanged event and in that event modify the position of the Popup. Another side effect is that when the parent Window loses focus, the popup ends up on top of other applications. Again this can be remedied by subscribing to the proper focus events, both of these issues are beyond the scope of this writing.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Animation&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Note that the video preview Grid (videoCaptureGrid which also contains the Popup) are not part of the animated videoWindow Grid. I found that trying to animate an element that contained the video rendered through interop performed poorly and drew improperly, so I simply hid videoCaptureGrid until the videoWindow Grid finished fading and animating in.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Possible Exercises&lt;/B&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Try to get a Thumbnail of a video. I spent some time on trying to do this and ended up falling back to having a media element display the video for lack of time. Two potential ways to do this are: Use RenderTargetBitmap or grab the Thumbnail that Windows itself generates. The code for using RenderTargetBitmap is in the project in the RasterizeVisualAt96dpi method, but is not used at present. I found that it was tricky to grab the thumb of the video since the first frame(s) of the video tend to be black. Grabbing a video thumbnail from Windows will require the use of interop. I’m not sure if this is possible or feasible.&lt;/LI&gt;
&lt;LI&gt;WME9 is able to capture the desktop of your computer. Create a WPF application that runs in your systray that captures your desktop to a WMV file.&lt;/LI&gt;
&lt;LI&gt;Calibrate the audio levels. Right now the Audio levels are cosmetic and gratuitous. They seem to be a bit delayed and levels seem higher than they should appear. Experiment to get the indicators working properly.&lt;/LI&gt;
&lt;LI&gt;Modify the Popup position when the application is moved or loses focus.&lt;/LI&gt;&lt;/OL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8340416" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/uberdemo/archive/tags/.NET+3.0/default.aspx">.NET 3.0</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/Windows+Media+Encoder/default.aspx">Windows Media Encoder</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/MIX08/default.aspx">MIX08</category><category domain="http://blogs.msdn.com/uberdemo/archive/tags/Interop/default.aspx">Interop</category></item></channel></rss>