Click here to Skip to main content
11,640,521 members (60,312 online)
Click here to Skip to main content

Transparent Desktop Video

, 26 May 2005 188.7K 2.2K 145
Rate this:
Please Sign up or sign in to vote.
Transparent video overlay over the Windows desktop.

Sample screenshot

Introduction

This simple C# WinForms project allows you to playback video from a live capture device or from an existing video file and blend the video using transparency with the existing Windows desktop. The user can still interact with all other application windows "through" the playing video stream.

Background

A while ago, a group from the University of North Carolina published a paper detailing a system they called FaceTop that makes use of transparent video streams for use in collaboration environments. By using transparent video over the desktop, the participant can view a video stream of the other participant while at the same time being able to read the contents of their desktop and look at items on their desktop that the other participant is referring to.

FaceTop makes use of MacOS X's Quartz composition engine to compose the video stream with the other desktop windows and apply the relevant transparency during composition. Windows has offered support for transparent top-level windows since the release of Windows 2000 using layered windows. For more details on this support for layered windows, see the following MSDN article.

At the time that the FaceTop paper was published, I was working on a video capture and playback system for aerial surveillance work. So my plan was to see how easy it would be to implement some of the basic features of FaceTop, i.e., transparent video playback that would allow you to watch the video and still allow you to see and interact with your desktop at the same time.

Code Overview

The basic setup consists of a C# WinForms application hosting the Windows Media Player control with a couple of specific properties set on the main form and the Media Player control.

To start off the Windows Media Player, the Primary Interop Assembly needs to be installed and referenced. See this MSDN article for details on downloading and installing the Windows Media Player's PIA.

After inserting the Windows Media Player control onto the form, the following three properties need to be set on the control:

  • uiMode - None since we don't want the Media Player's controls visible, we only want to see the video stream.
  • windowlessVideo - true since we want the Media Player to use the control host's (our main form's) window and not create its own child window in which to render the video. The reason for this is that the layered windows transparency support in the OS that we're making use of only works for top-level windows and not for child windows. See the MSDN article for more details.
  • URL - source of the video. This can refer to an existing video, e.g. file:///c:/somevideo.wmv or to a video being streamed, e.g. http://somehost/.

Then the following properties need to be set on the form:

  • FormBorderStyle - None
  • Topmost - true
  • WindowState - Maximized
  • Opacity - 0.55 or whatever amount of transparency you'd like to use.

In the Form's Load event we need to add the WS_EX_TRANSPARENT extended window style to our form's window in order for input events from the mouse and keyboard to be passed through to the underlying windows.

        [DllImport("user32.dll", SetLastError=true)]
        static extern int GetWindowLong(IntPtr hWnd, int nIndex);
        [DllImport("user32.dll", SetLastError=true)]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        private const int  GWL_EXSTYLE = -20;
        private const int  WS_EX_TRANSPARENT = 0x20;

        private void VideoPlayer_Load(object sender, System.EventArgs e)
        {
            // Add WS_EX_TRANSPARENT style so that mouse, keyboard etc. events pass
            // thru us.
            int exstyle = GetWindowLong(this.Handle, GWL_EXSTYLE);
            exstyle |= WS_EX_TRANSPARENT;
            SetWindowLong(this.Handle, GWL_EXSTYLE, exstyle);
        }

Summary

The sample screenshot at the top of the article shows a live video stream being captured by a DV camera attached to my system which is then being encoded to WMV using Microsoft's Media Encoder software and then being displayed as a transparent video over the desktop using my application by pointing the Media Player to http://localhost:8080/ to pick up the video stream.

Overall there was very little effort required to enable basic transparent video playback over the desktop.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Sean McLeod
Web Developer
South Africa South Africa
Software developer.

You may also be interested in...

Comments and Discussions

 
QuestionThanks Pin
KOUKKILLER15-Sep-12 22:12
memberKOUKKILLER15-Sep-12 22:12 
GeneralThanks Pin
MarkJoel6029-Mar-10 4:22
memberMarkJoel6029-Mar-10 4:22 
GeneralHi Guys Pin
dansaliveagain9-Feb-10 18:49
memberdansaliveagain9-Feb-10 18:49 
Generalen... Pin
josmoi29-Apr-09 20:43
memberjosmoi29-Apr-09 20:43 
QuestionWorking on VS 2005 / 2008? Pin
myspaceebay0014-Dec-08 12:43
membermyspaceebay0014-Dec-08 12:43 
GeneralDual Monitors Pin
dbbtvlzfpz10-Sep-08 6:03
memberdbbtvlzfpz10-Sep-08 6:03 
GeneralActivex problem Pin
myceng21-Aug-07 22:21
membermyceng21-Aug-07 22:21 
GeneralRe: Activex problem Pin
myspaceebay0014-Dec-08 11:45
membermyspaceebay0014-Dec-08 11:45 
Questionproblems with transfer to a different computer Pin
nomism4-Nov-06 4:56
membernomism4-Nov-06 4:56 
AnswerRe: problems with transfer to a different computer Pin
Sean McLeod6-Nov-06 5:11
memberSean McLeod6-Nov-06 5:11 
GeneralRe: problems with transfer to a different computer Pin
nomism4-Dec-06 22:46
membernomism4-Dec-06 22:46 
QuestionSound But No Video Pin
centrex8j12-Oct-06 21:34
membercentrex8j12-Oct-06 21:34 
AnswerRe: Sound But No Video Pin
Zaraken25-Mar-07 12:52
memberZaraken25-Mar-07 12:52 
GeneralLive video lags Pin
jackyjak6-Sep-06 23:19
memberjackyjak6-Sep-06 23:19 
GeneralRe: Live video lags Pin
Sean McLeod7-Sep-06 3:22
memberSean McLeod7-Sep-06 3:22 
QuestionOther Video Formats [modified] Pin
Peter_Bate21-May-06 20:29
memberPeter_Bate21-May-06 20:29 
AnswerRe: Other Video Formats [modified] Pin
Sean McLeod22-May-06 0:57
memberSean McLeod22-May-06 0:57 
GeneralRe: Other Video Formats [modified] Pin
Peter_Bate30-May-06 20:51
memberPeter_Bate30-May-06 20:51 
GeneralRe: Other Video Formats [modified] Pin
Sean McLeod30-May-06 22:59
memberSean McLeod30-May-06 22:59 
GeneralRe: Other Video Formats [modified] Pin
Peter_Bate8-Jun-06 14:50
memberPeter_Bate8-Jun-06 14:50 
GeneralRe: Other Video Formats Pin
KienNT7825-May-08 18:43
memberKienNT7825-May-08 18:43 
Questionwhy you havn`t used COM component? Pin
Ahmed.mb15-May-06 9:30
memberAhmed.mb15-May-06 9:30 
AnswerRe: why you havn`t used COM component? Pin
Sean McLeod15-May-06 9:35
memberSean McLeod15-May-06 9:35 
GeneralRe: why you havn`t used COM component? Pin
Ahmed.mb15-May-06 17:42
memberAhmed.mb15-May-06 17:42 
Generalbinary/exe Pin
djlippz25-Apr-06 17:44
memberdjlippz25-Apr-06 17:44 
QuestionRe: binary/exe Pin
iggzorn7-Jul-06 10:38
memberiggzorn7-Jul-06 10:38 
GeneralYou've done it Pin
jpslater12-Apr-06 20:00
memberjpslater12-Apr-06 20:00 
GeneralRe: You've done it Pin
Sean McLeod12-Apr-06 20:16
memberSean McLeod12-Apr-06 20:16 
GeneralRe: You've done it Pin
jpslater13-Apr-06 5:29
memberjpslater13-Apr-06 5:29 
GeneralRe: You've done it Pin
Sean McLeod13-Apr-06 6:08
memberSean McLeod13-Apr-06 6:08 
GeneralRe: You've done it Pin
jpslater13-Apr-06 6:20
memberjpslater13-Apr-06 6:20 
GeneralInput Video card in background my some buttons Pin
youssef25-Mar-06 10:19
memberyoussef25-Mar-06 10:19 
Generalmov codec available Pin
GraceNetwork5-Feb-06 4:20
memberGraceNetwork5-Feb-06 4:20 
GeneralRe: mov codec available Pin
Sean McLeod5-Feb-06 5:50
memberSean McLeod5-Feb-06 5:50 
Generalcommand line arguement video file Pin
GraceNetwork5-Feb-06 4:04
memberGraceNetwork5-Feb-06 4:04 
GeneralRe: command line arguement video file Pin
Sean McLeod5-Feb-06 5:47
memberSean McLeod5-Feb-06 5:47 
GeneralTransparent Desktop Video Pin
raorepalle4-Jan-06 19:10
memberraorepalle4-Jan-06 19:10 
GeneralRe: Transparent Desktop Video Pin
Sean McLeod4-Jan-06 19:20
memberSean McLeod4-Jan-06 19:20 
GeneralNeed help... Pin
relient29-Dec-05 11:53
memberrelient29-Dec-05 11:53 
GeneralRe: Need help... Pin
Sean McLeod29-Dec-05 21:36
memberSean McLeod29-Dec-05 21:36 
GeneralRe: Need help... Pin
jackyjak6-Sep-06 6:04
memberjackyjak6-Sep-06 6:04 
GeneralNicer event handling Pin
mtwilson9-Sep-05 5:35
membermtwilson9-Sep-05 5:35 
GeneralRe: Nicer event handling Pin
Sean McLeod9-Sep-05 5:56
memberSean McLeod9-Sep-05 5:56 
Generalwriting into video frame Pin
prosagar25-Aug-05 19:37
memberprosagar25-Aug-05 19:37 
GeneralRe: writing into video frame Pin
Sean McLeod27-Aug-05 20:51
memberSean McLeod27-Aug-05 20:51 
QuestionHow can I compile this project by SharpDevelop Pin
Writeoh20-Aug-05 3:14
sussWriteoh20-Aug-05 3:14 
AnswerRe: How can I compile this project by SharpDevelop Pin
Sean McLeod27-Aug-05 20:53
memberSean McLeod27-Aug-05 20:53 
Questionis this available pre-compiled/built? Pin
buzzbuzz28-Jul-05 16:24
memberbuzzbuzz28-Jul-05 16:24 
AnswerRe: is this available pre-compiled/built? Pin
Sean McLeod29-Jul-05 3:02
memberSean McLeod29-Jul-05 3:02 
GeneralRe: is this available pre-compiled/built? Pin
buzzbuzz30-Jul-05 4:28
memberbuzzbuzz30-Jul-05 4:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150731.1 | Last Updated 26 May 2005
Article Copyright 2005 by Sean McLeod
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid