Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have written this code to capture screen, it works 100% but it does not capture the mouse pointer

i wanted it to capture the mouse pointer as well

My code looks like this

#include "stdafx.h"
#include "screenshot2.h"
#include <Windows.h>
#include <stdio.h>

void ScreenShot() {
	int x1, y1, x2, y2, w, h;

	// get screen dimensions
	x1 = GetSystemMetrics(SM_XVIRTUALSCREEN);
	y1 = GetSystemMetrics(SM_YVIRTUALSCREEN);
	x2 = GetSystemMetrics(SM_CXVIRTUALSCREEN);
	y2 = GetSystemMetrics(SM_CYVIRTUALSCREEN);
	w = x2 - x1;
	h = y2 - y1;

	// copy screen to bitmap
	HDC     hScreen = GetDC(NULL);
	HDC     hDC = CreateCompatibleDC(hScreen);
	HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, w, h);
	HGDIOBJ old_obj = SelectObject(hDC, hBitmap);
	BOOL    bRet = BitBlt(hDC, 0, 0, w, h, hScreen, x1, y1, SRCCOPY);

	// save bitmap to clipboard
	OpenClipboard(NULL);
	EmptyClipboard();
	SetClipboardData(CF_BITMAP, hBitmap);
	CloseClipboard();

	// clean up
	SelectObject(hDC, old_obj);
	DeleteDC(hDC);
	ReleaseDC(NULL, hScreen);
	DeleteObject(hBitmap);

}

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
	_In_opt_ HINSTANCE hPrevInstance,
	_In_ LPWSTR    lpCmdLine,
	_In_ int       nCmdShow) 
{
	ScreenShot();
	return 0;
}


What I have tried:

Tried using GetCusorPos() only i dont know the actual method to have it implemented
Posted
Updated 27-Oct-18 23:13pm
Comments
Member 14075717 2-Aug-19 2:10am    
could you please provide the screenshot2.h file .
Thank in advance

1 solution

 
Share this answer
 
Comments
Member 14075717 2-Aug-19 2:12am    
could you please provide the screenshot2.h file .
Thank in advance

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900