ByteScout Screen Capturing SDK - C++ (unmanaged) - Capture From Given Window - ByteScout

ByteScout Screen Capturing SDK – C++ (unmanaged) – Capture From Given Window

  • Home
  • /
  • Articles
  • /
  • ByteScout Screen Capturing SDK – C++ (unmanaged) – Capture From Given Window

ByteScout Screen Capturing SDK – C++ (unmanaged) – Capture From Given Window


// CaptureFromEntireScreen.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#import "BytescoutScreenCapturing.dll"

using namespace BytescoutScreenCapturingLib;
using namespace std;

void usage(ICapturer* capturer);
void setParams(int argc, _TCHAR* argv[], ICapturer* capturer);

int _tmain(int argc, _TCHAR* argv[])

	// Create Capturer instance

	CLSID clsid_ScreenCapturer;
	CLSIDFromProgID(OLESTR("BytescoutScreenCapturing.Capturer"), &clsid_ScreenCapturer);

	ICapturer* capturer = NULL;
	::CoCreateInstance(clsid_ScreenCapturer, NULL, CLSCTX_ALL, __uuidof(ICapturer), (LPVOID*) &capturer);

	if (!capturer)
		_ftprintf(stdout, _T("Screen Capturer is not installed properly."));
		return 1;


	// Set capturing type

	// Specify window to capture by its title.
	// Capturer will take the first window containing "Internet Explorer" in its title.
	capturer->put_WindowToCapture(_T("Internet Explorer"));

	// You can also capture only a part of the window by specifying capturing rectangle

	// Set output video width and height

	    // WMV and WEBM output use WMVVideoBitrate property to control output video bitrate
   	    // so try to increase it by x2 or x3 times if you think the output video are you are getting is laggy
	    // capturer->put_WMVVideoBitrate(capturer->WMVVideoBitrate * 2);

        // uncomment to enable recording of semitransparent or layered windows (Warning: may cause mouse cursor flickering)
        // capturer->CaptureTransparentControls = true;

	// set border style
        ?apturer.CaptureAreaBorderType = cabtDashed;

	// Set output file name
	capturer->OutputFileName = _T("Output.wmv");

	// Start capturing
	HRESULT hr = capturer->Run();

	// IMPORTANT: if you want to check for some code if need to stop the recording then make sure you are 
	// using Thread.Sleep(1) inside the checking loop, so you have the loop like
	// Do 
	// Thread.Sleep(1) 
	// While StopButtonNotClicked

	if (FAILED(hr))
		// Error handling
		CComBSTR s;
		_ftprintf(stdout, _T("Capture failed: %s\n"), CString(s));
		_tprintf(_T("Starting capture - Hit a key to stop ...\n"));

		int i = 0;
		TCHAR *spin = _T("|/-\\");

		// Show some progress
		while (!_kbhit())
			_tprintf(_T("\rEncoding %c"), spin[i++]);
			i %= 4;

		// Stop after key press


	// Release Capturer
	capturer = NULL;


	return 0;


// stdafx.cpp : source file that includes just the standard includes
// CaptureFromEntireScreen.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

  Click here to get your Free Trial version of the SDK