Click here to Skip to main content
15,895,709 members
Articles / Desktop Programming / MFC

Target Eye Revealed: Part 2 - Target Eye's Screen Capturing

Rate me:
Please Sign up or sign in to vote.
4.96/5 (51 votes)
12 Jun 2014CPOL10 min read 112.9K   3.7K   85  
How Target Eye's screen capturing mechanism works
This article is the second one in the Target Eye Revealed series, and discusses the screen capturing mechanism. After taking a look at the purpose of screen capturing, we will see a few screenshot files followed by steps in capturing the screen. We will also get to learn how to use the source code.
// ScreenCapturePOC : Defines the entry point for the applicat//

#include "stdafx.h"
#include "ScreenCapturePOC.h"

int screens_count=0;
// Global Variables:

#define TIMETOWAIT 60000
UINT TimmerID = 909;


HINSTANCE hInst;								// current instance
HANDLE RESUME_COPY_EVENT;
WCHAR PCID[256];


BOOL APP_RUNNING = TRUE;

// Forward declarations of functions included in this code module:
void				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);



CString ComposeFileName(int i)
{

	CString result;
	result.Format(L"%s%d%s",(CString)L"screen",i,(CString)L".jpg");
	return result;
}



int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);


	MyRegisterClass(hInstance);


	// Perform application initialization:
	if(!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}
	
	MSG msg;
	// Main message loop:
	while(GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return (int) msg.wParam;
}


void MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex = {sizeof(wcex)};
	wcex.style          = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc    = WndProc;
	wcex.hInstance      = hInstance;
	wcex.hIcon          = NULL;
	wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName   = NULL;
	wcex.lpszClassName  = L"screencapturepoc";
	RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) {
	HWND hWnd;

	hInst = hInstance; // Store instance handle in our global variable

	hWnd = CreateWindow(L"ScreenCapturePOC", L"", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

	if (!hWnd)
	{
		return FALSE;
	}

	return TRUE;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

	static HDEVNOTIFY hDeviceNotify;

	switch (message)
	{
	case WM_CREATE:
		SetTimer(hWnd,TimmerID,TIMETOWAIT,NULL);
		break;
	case WM_TIMER:
		screens_count++;
		CaptureScreen(ComposeFileName(screens_count),screens_count,"test");
		break;
	case WM_DESTROY:
		APP_RUNNING = FALSE;
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Secured Globe, Inc.
United States United States
Michael Haephrati is a music composer, an inventor and an expert specializes in software development and information security, who has built a unique perspective which combines technology and the end user experience. He is the author of a the book Learning C++ , which teaches C++ 20, and was published in August 2022.

He is the CEO of Secured Globe, Inc., and also active at Stack Overflow.

Read our Corporate blog or read my Personal blog.





Comments and Discussions