Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. #include <stdafx.h>
  2. #include <windows.h>
  3. #include <objidl.h>
  4. #include <gdiplus.h>
  5. #include <iostream>
  6. #include <vector>
  7. #include <cmath>
  8. #include <ctime>
  9.  
  10. using namespace Gdiplus;
  11.  
  12. #pragma comment (lib,"Gdiplus.lib")
  13.  
  14. HWND hWnd;
  15.  
  16. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  17.  
  18. INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow)
  19. {
  20. MSG msg;
  21. WNDCLASS wndClass;
  22. GdiplusStartupInput gdiplusStartupInput;
  23. ULONG_PTR gdiplusToken;
  24.  
  25. // Initialize GDI+.
  26. GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  27.  
  28. wndClass.style = CS_HREDRAW | CS_VREDRAW;
  29. wndClass.lpfnWndProc = WndProc;
  30. wndClass.cbClsExtra = 0;
  31. wndClass.cbWndExtra = 0;
  32. wndClass.hInstance = hInstance;
  33. wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  34. wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  35. wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  36. wndClass.lpszMenuName = NULL;
  37. wndClass.lpszClassName = TEXT("GettingStarted");
  38.  
  39. RegisterClass(&wndClass);
  40.  
  41. hWnd = CreateWindow(
  42. TEXT("GettingStarted"), // window class name
  43. TEXT("Getting Started"), // window caption
  44. WS_OVERLAPPEDWINDOW, // window style
  45. CW_USEDEFAULT, // initial x position
  46. CW_USEDEFAULT, // initial y position
  47. CW_USEDEFAULT, // initial x size
  48. CW_USEDEFAULT, // initial y size
  49. NULL, // parent window handle
  50. NULL, // window menu handle
  51. hInstance, // program instance handle
  52. NULL); // creation parameters
  53.  
  54. ShowWindow(hWnd, iCmdShow);
  55. UpdateWindow(hWnd);
  56.  
  57. while (GetMessage(&msg, NULL, 0, 0))
  58. {
  59. TranslateMessage(&msg);
  60. DispatchMessage(&msg);
  61. }
  62.  
  63. GdiplusShutdown(gdiplusToken);
  64. return msg.wParam;
  65. srand(time(0));
  66. } // WinMain
  67.  
  68. LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
  69. WPARAM wParam, LPARAM lParam)
  70. {
  71. PAINTSTRUCT ps;
  72. HDC hdc;
  73.  
  74. const int n = 256;
  75. switch (message)
  76. {
  77. case WM_PAINT:
  78.  
  79.  
  80. return 0;
  81. case WM_DESTROY:
  82. PostQuitMessage(0);
  83. return 0;
  84. case WM_KEYDOWN: //Собственно массив
  85. RGBQUAD RGB_n[n * n];
  86. //В этой структуре хранятся параметры DIB
  87. tagBITMAPINFO bif;
  88. ZeroMemory(&bif, sizeof(bif));
  89. bif.bmiHeader.biSize = sizeof(bif);
  90. bif.bmiHeader.biWidth = n; //ширина
  91. bif.bmiHeader.biHeight = -n; //выста (если взять положительную, то рисунок будет перевурнут)
  92. bif.bmiHeader.biBitCount = 24;//Глубина цвета, поскольку размер структуры RGBQUAD, 3 байта, то глубина цвета 3*8бита
  93. bif.bmiHeader.biPlanes = 1;
  94.  
  95. for (int i = 0; i < n * n; i++) {
  96. RGB_n[i].rgbBlue = rand() % 256;
  97. RGB_n[i].rgbGreen = rand() % 256;
  98. RGB_n[i].rgbRed = rand() % 256;
  99. }
  100.  
  101. tagPAINTSTRUCT ps;
  102.  
  103. BeginPaint(hWnd, &ps);
  104.  
  105. SetDIBitsToDevice(ps.hdc,
  106. 0, //DestX
  107. 0, //DestY
  108. n, //Width
  109. n, //Height
  110. 0, //SrcX
  111. 0, //SrcY
  112. 0, //StartScan
  113. n, //NumScans
  114. &RGB_n,//Bits
  115. &bif, //BitsInfo
  116. 0 //Usage
  117. );
  118.  
  119.  
  120. InvalidateRect(hWnd, NULL, 0);
  121. EndPaint(hWnd, &ps);
  122. return 0;
  123. default:
  124. return DefWindowProc(hWnd, message, wParam, lParam);
  125. }
  126. } // WndProc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement