Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #define WIDTH 400
- #define HEIGHT 300
- #define X_START 0
- #define Y_START 0
- #define X_END 399
- #define Y_END 149
- HINSTANCE hInst;
- LPCWSTR szAppTitle = L"GDI example";
- LPCWSTR szMainWindow = L"Main";
- LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- HDC hDC;
- PAINTSTRUCT ps;
- POINT pos;
- switch (uMsg)
- {
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- case WM_PAINT:
- hDC = BeginPaint(hWnd, &ps);
- if (hDC)
- {
- MoveToEx(hDC, X_START, Y_START, &pos);
- LineTo(hDC, X_END, Y_END);
- EndPaint(hWnd, &ps);
- }
- break;
- default:
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- }
- return 0L;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
- {
- WNDCLASSEXW wc;
- HWND hWnd;
- MSG Msg;
- hInst = hInstance;
- ZeroMemory(&wc, sizeof(wc));
- wc.cbSize = sizeof(wc);
- wc.lpszClassName = szMainWindow;
- wc.style = CS_HREDRAW|CS_VREDRAW;
- wc.hInstance = hInst;
- wc.lpfnWndProc = (WNDPROC)MainWindowProc;
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- if (!RegisterClassExW(&wc))
- {
- MessageBoxW(0, L"Cannot register window class!", szAppTitle, MB_OK);
- return 0;
- }
- hWnd = CreateWindowExW(0,
- szMainWindow, szAppTitle,
- WS_OVERLAPPEDWINDOW,
- GetSystemMetrics(SM_CXSCREEN) / 2 - WIDTH / 2,
- GetSystemMetrics(SM_CYSCREEN) / 2 - HEIGHT / 2,
- WIDTH, HEIGHT,
- NULL, NULL, hInst, NULL);
- if (!hWnd)
- {
- MessageBoxW(0, L"Cannot create main window!", szAppTitle, MB_OK);
- return 0;
- }
- ShowWindow(hWnd, nShowCmd);
- UpdateWindow(hWnd);
- while (GetMessage(&Msg, NULL, 0, 0))
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return Msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement