написала сриншоп на С++

      

Код:
<ol>#include "stdafx.h"<br />#include <windows.h><br />#include <stdio.h><br />#include <iostream><br /><br />using namespace std;<br /><br />PBITMAPINFO CreateBitmapInfoStruct(HBITMAP hBmp){<br />    BITMAP bmp;<br />    PBITMAPINFO pbmi;<br />    WORD    cClrBits;<br /><br />    // Retrieve the bitmap color format, width, and height.<br />    GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp);<br /><br />    // Convert the color format to a count of bits.<br />    cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);<br />    if (cClrBits == 1)<br />        cClrBits = 1;<br />    else if (cClrBits <= 4)<br />        cClrBits = 4;<br />    else if (cClrBits <= 8)<br />        cClrBits = 8;<br />    else if (cClrBits <= 16)<br />        cClrBits = 16;<br />    else if (cClrBits <= 24)<br />        cClrBits = 24;<br />    else cClrBits = 32;<br /><br />    // Allocate memory for the BITMAPINFO structure. (This structure<br />    // contains a BITMAPINFOHEADER structure and an array of RGBQUAD<br />    // data structures.)<br /><br />     if (cClrBits != 24) pbmi = (PBITMAPINFO) LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * (1<< cClrBits));<br /><br />     // There is no RGBQUAD array for the 24-bit-per-pixel format.<br /><br />     else pbmi = (PBITMAPINFO) LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER));<br /><br />    // Initialize the fields in the BITMAPINFO structure.<br /><br /><br />    pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);<br />    pbmi->bmiHeader.biWidth = bmp.bmWidth;<br />    pbmi->bmiHeader.biHeight = bmp.bmHeight;<br />    pbmi->bmiHeader.biPlanes = bmp.bmPlanes;<br />    pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;<br />    if (cClrBits < 24) pbmi->bmiHeader.biClrUsed = (1<<cClrBits);<br /><br />    // If the bitmap is not compressed, set the BI_RGB flag.<br />    pbmi->bmiHeader.biCompression = BI_RGB;<br /><br />    // Compute the number of bytes in the array of color<br />    // indices and store the result in biSizeImage.<br />    // For Windows NT, the width must be DWORD aligned unless<br />    // the bitmap is RLE compressed. This example shows this.<br />    // For Windows 95/98/Me, the width must be WORD aligned unless the<br />    // bitmap is RLE compressed.<br />    pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8 * pbmi->bmiHeader.biHeight;<br />    // Set biClrImportant to 0, indicating that all of the<br />    // device colors are important.<br />     pbmi->bmiHeader.biClrImportant = 0;<br />     return pbmi;<br />}<br /><br />void CreateBMPFile(LPTSTR pszFile, PBITMAPINFO pbi, HBITMAP hBMP, HDC hDC){<br />     HANDLE hf;                 // file handle<br />    BITMAPFILEHEADER hdr;       // bitmap file-header<br />    PBITMAPINFOHEADER pbih;     // bitmap info-header<br />    LPBYTE lpBits;              // memory pointer<br />    DWORD dwTotal;              // total count of bytes<br />    DWORD cb;                   // incremental count of bytes<br />    BYTE *hp;                   // byte pointer<br />    DWORD dwTmp;<br /><br />    pbih = (PBITMAPINFOHEADER) pbi;<br />    lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);<br /><br />    // Retrieve the color table (RGBQUAD array) and the bits<br />    // (array of palette indices) from the DIB.<br />    GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, DIB_RGB_COLORS);<br /><br />// Create the .BMP file.<br />    hf = CreateFile(pszFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);<br />    hdr.bfType = 0x4d42;        // 0x42 = "B" 0x4d = "M"<br />    // Compute the size of the entire file.<br />    hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD) + pbih->biSizeImage);<br />    hdr.bfReserved1 = 0;<br />    hdr.bfReserved2 = 0;<br /><br />    // Compute the offset to the array of color indices.<br />    hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof (RGBQUAD);<br /><br />    // Copy the BITMAPFILEHEADER into the .BMP file.<br />    WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), (LPDWORD) &dwTmp,  NULL);<br /><br />    // Copy the BITMAPINFOHEADER and RGBQUAD array into the file.<br />    WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) + pbih->biClrUsed * sizeof (RGBQUAD), (LPDWORD) &dwTmp, NULL);<br /><br />    // Copy the array of color indices into the .BMP file.<br />    dwTotal = cb = pbih->biSizeImage;<br />    hp = lpBits;<br />    WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL);<br /><br />    // Close the .BMP file.<br />    CloseHandle(hf);<br /><br />    // Free memory.<br />    GlobalFree((HGLOBAL)lpBits);<br />}<br /><br /><br />void main(int argc, LPTSTR argv[]){<br />locale::global(locale("rus");<br />int sx = GetSystemMetrics(SM_CXSCREEN), sy = GetSystemMetrics(SM_CYSCREEN);<br />HDC hDC = GetDC(GetDesktopWindow());<br />HDC MyHDC = CreateCompatibleDC(hDC);<br />HBITMAP hBMP = CreateCompatibleBitmap(hDC, sx, sy);<br />SelectObject(MyHDC, hBMP);<br />LOGBRUSH MyBrush;<br />MyBrush.lbStyle = BS_SOLID;<br />MyBrush.lbColor = 0xFF0000;<br />HBRUSH hBrush = CreateBrushIndirect(&MyBrush);<br />RECT MyRect = {0, 0, sx, sy};<br />FillRect(MyHDC, &MyRect, hBrush);<br /><br />BitBlt(MyHDC, 0, 0, sx, sy, hDC, 0, 0, SRCCOPY);<br />if(argc==2) CreateBMPFile(argv[1], CreateBitmapInfoStruct(hBMP), hBMP, MyHDC);<br /><br />for(int i=0; i<argc; i++) printf("Argument #%d: %s\n", i, argv[i]);<br />printf("esktop DC = %d\nHBITMAP hBMP = %d", (int)hDC, (int)hBMP);<br />}<br /><br /></ol><pre>    :-   <br />
Обсудить у себя 0
Комментарии (2)
у меня не скомпилировалось
очень жаль
Чтобы комментировать надо зарегистрироваться или если вы уже регистрировались войти в свой аккаунт.
накрутить подписчиков в вк
Marina
Marina
Была на сайте никогда
тел: +380665011134
Читателей: 5 Опыт: 0 Карма: 1
Я в клубах
Фотографируем Пользователь клуба
Inks under the skin Пользователь клуба
все 1 Мои друзья