Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdafx.h>
- #include <windows.h>
- #include <objidl.h>
- #include <gdiplus.h>
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <ctime>
- using namespace Gdiplus;
- #pragma comment (lib,"Gdiplus.lib")
- HWND hWnd;
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow)
- {
- MSG msg;
- WNDCLASS wndClass;
- GdiplusStartupInput gdiplusStartupInput;
- ULONG_PTR gdiplusToken;
- // Initialize GDI+.
- GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
- wndClass.style = CS_HREDRAW | CS_VREDRAW;
- wndClass.lpfnWndProc = WndProc;
- wndClass.cbClsExtra = 0;
- wndClass.cbWndExtra = 0;
- wndClass.hInstance = hInstance;
- wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
- wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- wndClass.lpszMenuName = NULL;
- wndClass.lpszClassName = TEXT("GettingStarted");
- RegisterClass(&wndClass);
- hWnd = CreateWindow(
- TEXT("GettingStarted"), // window class name
- TEXT("Getting Started"), // window caption
- WS_OVERLAPPEDWINDOW, // window style
- CW_USEDEFAULT, // initial x position
- CW_USEDEFAULT, // initial y position
- CW_USEDEFAULT, // initial x size
- CW_USEDEFAULT, // initial y size
- NULL, // parent window handle
- NULL, // window menu handle
- hInstance, // program instance handle
- NULL); // creation parameters
- ShowWindow(hWnd, iCmdShow);
- UpdateWindow(hWnd);
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- GdiplusShutdown(gdiplusToken);
- return msg.wParam;
- srand(time(0));
- } // WinMain
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam)
- {
- PAINTSTRUCT ps;
- HDC hdc;
- const int n = 256;
- switch (message)
- {
- case WM_PAINT:
- return 0;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- case WM_KEYDOWN: //Собственно массив
- RGBQUAD RGB_n[n * n];
- //В этой структуре хранятся параметры DIB
- tagBITMAPINFO bif;
- ZeroMemory(&bif, sizeof(bif));
- bif.bmiHeader.biSize = sizeof(bif);
- bif.bmiHeader.biWidth = n; //ширина
- bif.bmiHeader.biHeight = -n; //выста (если взять положительную, то рисунок будет перевурнут)
- bif.bmiHeader.biBitCount = 24;//Глубина цвета, поскольку размер структуры RGBQUAD, 3 байта, то глубина цвета 3*8бита
- bif.bmiHeader.biPlanes = 1;
- for (int i = 0; i < n * n; i++) {
- RGB_n[i].rgbBlue = rand() % 256;
- RGB_n[i].rgbGreen = rand() % 256;
- RGB_n[i].rgbRed = rand() % 256;
- }
- tagPAINTSTRUCT ps;
- BeginPaint(hWnd, &ps);
- SetDIBitsToDevice(ps.hdc,
- 0, //DestX
- 0, //DestY
- n, //Width
- n, //Height
- 0, //SrcX
- 0, //SrcY
- 0, //StartScan
- n, //NumScans
- &RGB_n,//Bits
- &bif, //BitsInfo
- 0 //Usage
- );
- InvalidateRect(hWnd, NULL, 0);
- EndPaint(hWnd, &ps);
- return 0;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- } // WndProc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement