tags:

views:

84

answers:

3

I am looking to make a simple application that will capture the video from a Skype window every few milliseconds.

My questions are:

  • How do I automatically locate the window handle? That is, which is the best strategy (by name or?) and how do I achieve that programatically?
  • How I keep track of the window location as the user resizes it/moves it?
+1  A: 

I have never used it but probably Skype4COM would help.

Skype4COM is an interface which represents the Skype API as objects, with properties, commands, and events and notifications. Use Skype4COM in any ActiveX environment, such as Visual Studio or Delphi, and use familiar scripting languages, such as Visual Basic, PHP, or Javascript.

you will find it at

https://developer.skype.com/Docs/Skype4COM

Kevin Boyd
+1 - I've used Skype4COM before with .NET and it works like a charm. Before your built app gets access to Skype, it shows a little confirmation to the user.
Jenko
+2  A: 

If skype is the active window you can use GetForegroundWindow. If not, using the process name is a good option. You can also combine them and see if you get the same window handle.

The following code will grab an image from a window handle and save it to disk as an image. If you call this code often and modify the code to create unique images you will get several images like you ask for. GetWindowRect is the key function to get the coordinates for the window. And ofcourse you can save the image in any format you like. The WPF functions for saving images are quicker than the winform code used here.

public void GrabActiveWindow()
{ 
 IntPtr handle = GetForegroundWindow(); // window handle of active application
 IntPtr handle = WindowsHandleFromProcess("skype.exe");

 RECT screenRect = new RECT();
 GetWindowRect(handle, out screenRect);
 long width = screenRect.Right - screenRect.Left;
 long height = screenRect.Bottom - screenRect.Top;

 Bitmap bmpScreenshot = new Bitmap( (int)width, (int)height, PixelFormat.Format32bppArgb);
 Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot);
 Size size = new Size((int)width, (int)height );
 gfxScreenshot.CopyFromScreen(screenRect.Left, screenRect.Top, 0, 0, size, CopyPixelOperation.SourceCopy);
 string path = @"c:\savepath.tiff";
 bmpScreenshot.Save(path, ImageFormat.Tiff);
}

public IntPtr WindowsHandleFromProcess(string processName)
{
 foreach (var process in Process.GetProcessesByName(processName))
 {
  return process.MainWindowHandle;
 }
 return IntPtr.Zero;
}

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
Mikael Svenson
Will this work with a Hardware Overlay? I found some similar code with Device Contexts and such but it gives me a black screen where the video is.How can I convert this to capture overlay'd video?
everwicked
It works, thanks!
everwicked
I was not sure if it would work on overlay.. thought about that this morning, but apparently it did ;)
Mikael Svenson
A: 

Page 3 of Automating applications using messages goes into detail about how to find a dialog box/window etc. I found some of the ideas useful when I had to get control of an application.

mikej