Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.79 KB | None | 0 0
  1. #include <Windows.h>
  2.  
  3. #define WIDTH  400
  4. #define HEIGHT 300
  5.  
  6. #define X_START 0
  7. #define Y_START 0
  8. #define X_END   399
  9. #define Y_END   149
  10.  
  11. HINSTANCE hInst;
  12. LPCWSTR szAppTitle = L"GDI example";
  13. LPCWSTR szMainWindow = L"Main";
  14.  
  15. LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  16. {
  17.     HDC hDC;
  18.     PAINTSTRUCT ps;
  19.     POINT pos;
  20.     switch (uMsg)
  21.     {
  22.     case WM_DESTROY:
  23.         PostQuitMessage(0);
  24.         break;
  25.     case WM_PAINT:
  26.         hDC = BeginPaint(hWnd, &ps);
  27.         if (hDC)
  28.         {
  29.             MoveToEx(hDC, X_START, Y_START, &pos);
  30.             LineTo(hDC, X_END, Y_END);
  31.             EndPaint(hWnd, &ps);
  32.         }
  33.         break;
  34.     default:
  35.         return DefWindowProc(hWnd, uMsg, wParam, lParam);
  36.     }
  37.     return 0L;
  38. }
  39.  
  40. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  41. {
  42.     WNDCLASSEXW wc;
  43.     HWND hWnd;
  44.     MSG Msg;
  45.     hInst = hInstance;
  46.     ZeroMemory(&wc, sizeof(wc));
  47.     wc.cbSize = sizeof(wc);
  48.     wc.lpszClassName = szMainWindow;
  49.     wc.style = CS_HREDRAW|CS_VREDRAW;
  50.     wc.hInstance = hInst;
  51.     wc.lpfnWndProc = (WNDPROC)MainWindowProc;
  52.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  53.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  54.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  55.     if (!RegisterClassExW(&wc))
  56.     {
  57.         MessageBoxW(0, L"Cannot register window class!", szAppTitle, MB_OK);
  58.         return 0;
  59.     }
  60.     hWnd = CreateWindowExW(0,
  61.         szMainWindow, szAppTitle,
  62.         WS_OVERLAPPEDWINDOW,
  63.         GetSystemMetrics(SM_CXSCREEN) / 2 - WIDTH / 2,
  64.         GetSystemMetrics(SM_CYSCREEN) / 2 - HEIGHT / 2,
  65.         WIDTH, HEIGHT,
  66.         NULL, NULL, hInst, NULL);
  67.     if (!hWnd)
  68.     {
  69.         MessageBoxW(0, L"Cannot create main window!", szAppTitle, MB_OK);
  70.         return 0;
  71.     }
  72.     ShowWindow(hWnd, nShowCmd);
  73.     UpdateWindow(hWnd);
  74.     while (GetMessage(&Msg, NULL, 0, 0))
  75.     {
  76.         TranslateMessage(&Msg);
  77.         DispatchMessage(&Msg);
  78.     }
  79.     return Msg.wParam;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement