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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
#include <iostream>
#include <windows.h>
#include <string>
#include <ctime>
using namespace std;
HANDLE hProcess;
BOOL ResimAl(const CHAR* lpszFile)
{
HWND hWnd;
HDC hDC;
LPRECT lpRect;
RECT rect;
//masaüstünün ID'sini hWnd tutar
hWnd = GetDesktopWindow();
hDC = GetDC(hWnd);
//masaüstünün genişlik, yükseklik, kordinatını... rect'e atar
GetWindowRect(hWnd, &rect);
//işaretciyle rect adresi
lpRect = ▭
BITMAPINFO bmi = { 0 };
LPBYTE pBits = NULL;
//sizeof(BITMAPINFOHEADER) yapisi = 40 byte
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = lpRect->right - lpRect->left;
bmi.bmiHeader.biHeight = lpRect->bottom - lpRect->top;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
HBITMAP hBitmap = CreateDIBSection(hDC, &bmi,
DIB_RGB_COLORS, (LPVOID*)&pBits, NULL, 0);
HDC hMemDC = CreateCompatibleDC(hDC);
HGDIOBJ hOld = SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC, 0, 0,
lpRect->right - lpRect->left,
lpRect->bottom - lpRect->top,
hDC, lpRect->left, lpRect->top, SRCCOPY);
SelectObject(hMemDC, hOld);
DeleteDC(hMemDC);
DWORD nImageSize = ((((bmi.bmiHeader.biWidth *
bmi.bmiHeader.biBitCount)
+ 31) & ~31) >> 3)
* bmi.bmiHeader.biHeight;
BITMAPFILEHEADER header = { 0 };
header.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) +
(DWORD)sizeof(BITMAPINFOHEADER);
header.bfSize = nImageSize + sizeof(BITMAPFILEHEADER) +
sizeof(BITMAPINFOHEADER);
header.bfType = 0x4D42;
HANDLE hFile = CreateFile(lpszFile, GENERIC_WRITE,
0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD nWritten = 0;
WriteFile(hFile, (LPVOID)&header,
sizeof(BITMAPFILEHEADER),
&nWritten, NULL);
WriteFile(hFile, (LPVOID)&bmi,
sizeof(BITMAPINFOHEADER),
&nWritten, NULL);
WriteFile(hFile, (LPVOID)pBits, nImageSize,
&nWritten, NULL);
CloseHandle(hFile);
}
return TRUE;
}
string zaman()
{
time_t dilim = time(0);
struct tm tYapi;
char tam[80];
tYapi = *localtime(&dilim);
strftime(tam, sizeof(tam), "%d_%m_%Y-%H_%M_%S", &tYapi);
return tam;
}
int main()
{
int i = 1;
while(i <= 10)
{
char dene[100] = { 0 };
string vakit = zaman();
sprintf(dene, "C:\\Users\\ROOT\\Desktop\\DENE\\%s.sysLavaraImg_%i.bmp", vakit.c_str(), i);
Sleep(1000);
ResimAl(dene);
i++;
}
system("PAUSE");
return 0;
}
|