Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <GdiPlus.h>
- #include <sstream>
- LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_DESTROY:
- {
- PostQuitMessage(0);
- return 0;
- break;
- }
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(hwnd, &ps);
- Gdiplus::Graphics graphics(hdc);
- RECT clientRect;
- GetClientRect(hwnd, &clientRect);
- Gdiplus::LinearGradientBrush brush(Gdiplus::PointF(clientRect.left, clientRect.top),
- Gdiplus::PointF(clientRect.left, clientRect.bottom),
- Gdiplus::Color(0, 0, 0),
- Gdiplus::Color(80, 160, 240));
- __int64 before, after, freq;
- QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
- QueryPerformanceCounter((LARGE_INTEGER *)&before);
- graphics.FillRectangle(&brush, clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
- QueryPerformanceCounter((LARGE_INTEGER *)&after);
- std::stringstream s;
- s << "Wypełnienie gradientem: " << (((after - before) * 1000) / freq) << "\n";
- OutputDebugStringA(s.str().c_str());
- EndPaint(hwnd, &ps);
- return 0L;
- }
- default:
- {
- return DefWindowProc(hwnd, message, wParam, lParam);
- }
- }
- }
- int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- // *** GDI+ ***
- ULONG_PTR gdiPlusToken;
- Gdiplus::Status result;
- Gdiplus::GdiplusStartupInput gdiplusStartupInput;
- result = Gdiplus::GdiplusStartup(&gdiPlusToken, &gdiplusStartupInput, NULL);
- // *** Koniec GDI+ ***
- // Rejestracja klasy okna
- WNDCLASSEX winClass;
- winClass.cbClsExtra = 0;
- winClass.cbSize = sizeof(WNDCLASSEX);
- winClass.cbWndExtra = 0;
- winClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
- winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
- winClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
- winClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
- winClass.hInstance = hInstance;
- winClass.lpfnWndProc = WindowProc;
- winClass.lpszClassName = L"MainWindowClass";
- winClass.lpszMenuName = NULL;
- winClass.style = CS_HREDRAW | CS_VREDRAW;
- if (!RegisterClassEx(&winClass))
- return -1;
- // Tworzenie okna
- HWND mainWinHWND = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,
- L"MainWindowClass",
- L"WinAPI window",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 640,
- 480,
- NULL,
- NULL,
- hInstance,
- NULL);
- if (!mainWinHWND)
- return -1;
- ShowWindow(mainWinHWND, SW_SHOW);
- // Obsługa kolejki komunikatów
- MSG message;
- BOOL getMsgResult;
- while ((getMsgResult = GetMessage(&message, NULL, 0, 0)) != 0 && getMsgResult != -1)
- {
- TranslateMessage(&message);
- DispatchMessage(&message);
- }
- // *** GDI+ ***
- Gdiplus::GdiplusShutdown(gdiPlusToken);
- // *** GDI+ ***
- return message.lParam;
- }
Add Comment
Please, Sign In to add comment