7

I'm looking for a SDK, plugin or code that will videorecord a specific window (hwnd). If possible in C# or Java. Does anyone know if this exists? I've been googling, but haven't come across anything.

Hogan
  • 69,564
  • 10
  • 76
  • 117
Jochen
  • 1,853
  • 3
  • 20
  • 28
  • 5
    possible duplicate of [Record Video of Screen using .NET technologies](http://stackoverflow.com/questions/397754/record-video-of-screen-using-net-technologies) – Nasreddine Nov 26 '11 at 19:58
  • 1
    Question appears similar; but is not a duplicate. The link in question refers to screen capture in general; this question refers specifically to capturing a portion of the screen given an HWND for a particular window. – bbosak Nov 28 '11 at 04:21
  • 1
    No, this is Not a duplicate. Here's why: This question asks how to record a single window whether or not the window is shown on the desktop or minimized (he mentioned HWND). Therefore, screen capture methods will not be the answer here. The answer should have something to do with how to capture the window given a window handle. –  Dec 20 '11 at 07:21

1 Answers1

5

Install Microsoft Expression Encoder 4 with Service Pack 2 (SP2).

Here's a sample program to use it. A fuller sample comes with the SDK, which is included in the download.

using System;
using System.Drawing;
using Microsoft.Expression.Encoder.ScreenCapture;

// Added references to:
// Microsoft.Expression.Encoder
// Microsoft.Expression.Encoder.Types
// Microsoft.Expression.Encoder.Utilities
// WindowsBase
// System.Drawing (for Rectangle)

namespace scrcap
{
    class Program
    {
        static void Main(string[] args)
        {
            ScreenCaptureJob job = new ScreenCaptureJob();

            // You can capture a window by setting its coordinates here
            job.CaptureRectangle = new Rectangle(100, 100, 200, 200);

            // Include the mouse pointer in the captured video
            job.CaptureMouseCursor = true;

            // Output file; you can transcode the xesc file to something else later.
            // Note that this silently does nothing if the file already exists.
            job.OutputScreenCaptureFileName = @"C:\Users\arx\scrcap\capture.xesc";

            // Do some capture
            job.Start();
            // Wait for a keypress
            Console.ReadKey();
            // And stop
            job.Stop();
        }
    }
}
arx
  • 16,686
  • 2
  • 44
  • 61