1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include "captureScreen.h"
#include <iostream>
#include <Windows.h>
#include <atlimage.h>
using namespace std;
captureScreen::captureScreen()
{
}
void captureScreen::takeNow(string fname) {
int screenW, screenH;
//GetScreenSize
screenW = GetSystemMetrics(SM_CXVIRTUALSCREEN);
screenH = GetSystemMetrics(SM_CYVIRTUALSCREEN);
HDC myScreen = GetDC(NULL);
HDC mySrnMemory = CreateCompatibleDC(myScreen);
HBITMAP hBitmap = CreateCompatibleBitmap(myScreen, screenW, screenH);
HGDIOBJ cobj = SelectObject(mySrnMemory, hBitmap);
BitBlt(mySrnMemory, 0, 0, screenW, screenH, myScreen, 0, 0, SRCCOPY);
CImage screenimg;
screenimg.Attach(hBitmap);
screenimg.Save(CA2W(fname.c_str()));
}
std::string captureScreen::saveLocal(){
std::string fname = "myscreen.png";
takeNow(fname);
return fname;
}
std::string captureScreen::saveTmp(){
string fname = "";
FILE *sysPipe = _popen("echo %temp%", "rt");
char cli[128];
while (fgets(cli, sizeof(cli), sysPipe)){
fname += cli;
}
//Remove lastchar (newline)
fname.erase(fname.end() - 1);
fname += "\\myScreen1000.png";
takeNow(fname);
return fname;
}
captureScreen::~captureScreen()
{
}
|