Guest User

Untitled

a guest
Feb 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.74 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <GdiPlus.h>
  3. #include <sstream>
  4.  
  5. LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  6. {
  7.     switch (message)
  8.     {
  9.     case WM_DESTROY:
  10.         {
  11.             PostQuitMessage(0);
  12.  
  13.             return 0;
  14.             break;
  15.         }
  16.     case WM_PAINT:
  17.         {
  18.             PAINTSTRUCT ps;
  19.             HDC hdc = BeginPaint(hwnd, &ps);
  20.            
  21.             Gdiplus::Graphics graphics(hdc);
  22.  
  23.             RECT clientRect;
  24.             GetClientRect(hwnd, &clientRect);
  25.  
  26.             Gdiplus::LinearGradientBrush brush(Gdiplus::PointF(clientRect.left, clientRect.top),
  27.                 Gdiplus::PointF(clientRect.left, clientRect.bottom),
  28.                 Gdiplus::Color(0, 0, 0),
  29.                 Gdiplus::Color(80, 160, 240));
  30.  
  31.             __int64 before, after, freq;
  32.             QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
  33.             QueryPerformanceCounter((LARGE_INTEGER *)&before);
  34.  
  35.             graphics.FillRectangle(&brush, clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
  36.  
  37.             QueryPerformanceCounter((LARGE_INTEGER *)&after);
  38.  
  39.             std::stringstream s;
  40.             s << "Wypełnienie gradientem: " << (((after - before) * 1000) / freq) << "\n";
  41.             OutputDebugStringA(s.str().c_str());
  42.            
  43.             EndPaint(hwnd, &ps);
  44.             return 0L;
  45.         }
  46.     default:
  47.         {
  48.             return DefWindowProc(hwnd, message, wParam, lParam);
  49.         }
  50.     }
  51. }
  52.  
  53. int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  54. {
  55.     // *** GDI+ ***
  56.  
  57.     ULONG_PTR gdiPlusToken;
  58.     Gdiplus::Status result;
  59.        
  60.     Gdiplus::GdiplusStartupInput gdiplusStartupInput;
  61.     result = Gdiplus::GdiplusStartup(&gdiPlusToken, &gdiplusStartupInput, NULL);
  62.  
  63.     // *** Koniec GDI+ ***
  64.  
  65.     // Rejestracja klasy okna
  66.     WNDCLASSEX winClass;
  67.     winClass.cbClsExtra = 0;
  68.     winClass.cbSize = sizeof(WNDCLASSEX);
  69.     winClass.cbWndExtra = 0;
  70.     winClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  71.     winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  72.     winClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
  73.     winClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
  74.     winClass.hInstance = hInstance;
  75.     winClass.lpfnWndProc = WindowProc;
  76.     winClass.lpszClassName = L"MainWindowClass";
  77.     winClass.lpszMenuName = NULL;
  78.     winClass.style = CS_HREDRAW | CS_VREDRAW;
  79.  
  80.     if (!RegisterClassEx(&winClass))
  81.         return -1;
  82.  
  83.     // Tworzenie okna
  84.     HWND mainWinHWND = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,
  85.         L"MainWindowClass",
  86.         L"WinAPI window",
  87.         WS_OVERLAPPEDWINDOW,
  88.         CW_USEDEFAULT,
  89.         CW_USEDEFAULT,
  90.         640,
  91.         480,
  92.         NULL,
  93.         NULL,
  94.         hInstance,
  95.         NULL);
  96.  
  97.     if (!mainWinHWND)
  98.         return -1;
  99.  
  100.     ShowWindow(mainWinHWND, SW_SHOW);
  101.  
  102.     // Obsługa kolejki komunikatów
  103.     MSG message;
  104.     BOOL getMsgResult;
  105.  
  106.     while ((getMsgResult = GetMessage(&message, NULL, 0, 0)) != 0 && getMsgResult != -1)
  107.     {
  108.         TranslateMessage(&message);
  109.         DispatchMessage(&message);
  110.     }
  111.  
  112.     // *** GDI+ ***
  113.  
  114.     Gdiplus::GdiplusShutdown(gdiPlusToken);
  115.  
  116.     // *** GDI+ ***
  117.  
  118.     return message.lParam;
  119. }
Add Comment
Please, Sign In to add comment