截屏工具(C++)API

前阵子在搞一个Agent的监控功能,每隔几秒传回一张图,用Java编写。但发现有以下两个问题:

(1) 鼠标闪,当刷新屏幕设置为3秒以下时,发现鼠标闪的非常厉害,严重影响Agent机的使用。
(2) 当屏幕Lock,或者远程登录Agent最小化登录窗口时,将截不到图。

后来搜索发现,用Java是没办法解决这个问题的,必须使用C/C++跟操作系统底层打交道才行,放在这里的话就是GDI。

程序下载:

ScreenCapture.zip

用法:

ScreenCapture.exe [filePath.jpg] [sleepTime]

(1) 无参数 ———-保存图片于相同目录,文件名screen.jpg
(2) 1个参数 —–保存图片于filePath.jpg
(3) 2个参数 —–循环截图,间隔时间为sleepTime(毫秒),保存图片于filePath.jpg

程序源码:

Blow is the content of ScreenCapture.cpp

#include "screen_shooter.h"
int main (int argc, char* argv[]){
	ScreenShooter screen_shooter;
	Screenshot* screenshot;
	int sleepTime;
	char* filePath;
	if (argc == 1) {
		filePath = "screen.jpg";
		screenshot = screen_shooter.take_screenshot();
		screenshot->write_jpeg(filePath);
	}
	if (argc == 2) {
		filePath = argv[1];
		screenshot = screen_shooter.take_screenshot();
		screenshot->write_jpeg(filePath);
	}
 
	if (argc == 3) {
		filePath = argv[1];
		sscanf(argv[2],"%d",&sleepTime);
		while(true){
			  screenshot = screen_shooter.take_screenshot();
			  screenshot->write_jpeg(filePath);
			  Sleep(sleepTime);
		  }
	}
 
	delete screenshot;
	return 0;
}
1 week ago, this page was being read.

,

Subscribe to Comments