fork download
  1. #include <Windows.h>
  2. #include <math.h>
  3. #define ID_TIMER 1
  4.  
  5. LRESULT CALLBACK WndProc(HWND , UINT , WPARAM , LPARAM );
  6. void WINAPI Rotate(POINT arr[5]);
  7.  
  8. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int cmdShow)
  9. {
  10. TCHAR szAppName[] = TEXT("HelloWin32");
  11. HWND hWnd;
  12. MSG msg;
  13. WNDCLASS wndClass;
  14. wndClass.style = CS_HREDRAW | CS_VREDRAW;
  15. wndClass.lpfnWndProc = WndProc;
  16. wndClass.cbClsExtra = wndClass.cbWndExtra = 0;
  17. wndClass.hInstance = hInstance;
  18. wndClass.hIcon = LoadIcon(0, IDI_APPLICATION);
  19. wndClass.hCursor = LoadCursor(0, IDC_ARROW);
  20. wndClass.hbrBackground = (HBRUSH) GetStockObject(1);
  21. wndClass.lpszMenuName = 0;
  22. wndClass.lpszClassName = szAppName;
  23.  
  24. if (!RegisterClass(&wndClass))
  25. {
  26. MessageBox(0, TEXT("Failed to register window class"), TEXT("Error"), MB_OK | MB_DEFBUTTON1 | MB_ICONERROR);
  27. return 1;
  28. }
  29. hWnd = CreateWindow(szAppName, TEXT("Hello World Win32!!"), WS_OVERLAPPEDWINDOW,
  30. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  31. NULL, NULL, hInstance, NULL);
  32. if (!hWnd)
  33. {
  34. MessageBox(NULL, TEXT("Failed to create the window"), TEXT("Win32 Error"), MB_ICONERROR);
  35. return 1;
  36. }
  37. SetTimer(hWnd, ID_TIMER, 400, NULL);
  38.  
  39. ShowWindow(hWnd, cmdShow);
  40. UpdateWindow(hWnd);
  41.  
  42. while (GetMessage(&msg, NULL, 0, 0))
  43. {
  44. TranslateMessage(&msg);
  45. DispatchMessage(&msg);
  46. }
  47. return msg.wParam;
  48. }
  49.  
  50. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM w, LPARAM l)
  51. {
  52. static HDC hdc;
  53. static PAINTSTRUCT ps;
  54. static POINT arr[5];
  55. static int i;
  56. static RECT rect;
  57. switch (message)
  58. {
  59. case WM_CREATE:
  60. GetClientRect(hWnd, &rect);
  61. arr[0].x = 200;
  62. arr[0].y = 100;
  63. arr[1].x = 100;
  64. arr[1].y = 100;
  65. arr[2].x = 100;
  66. arr[2].y = 200;
  67. arr[3].x = 200;
  68. arr[3].y = 200;
  69. arr[4].x = arr[0].x;
  70. arr[4].y = arr[0].y;
  71. return 0;
  72. case WM_TIMER:
  73. Rotate(arr);
  74. InvalidateRect(hWnd, &rect, TRUE);
  75. return 0;
  76. case WM_DESTROY:
  77. KillTimer(hWnd, ID_TIMER);
  78. PostQuitMessage(0);
  79. return 0;
  80. case WM_PAINT:
  81. hdc = BeginPaint(hWnd, &ps);
  82. MoveToEx(hdc, arr[0].x, arr[0].y, NULL);
  83. for (i = 1; i < 5; ++i) LineTo(hdc, arr[i].x, arr[i].y);
  84. EndPaint(hWnd, &ps);
  85. return 0;
  86. case WM_SIZE:
  87. GetClientRect(hWnd, &rect);
  88. return 0;
  89. default:
  90. return DefWindowProc(hWnd, message, w, l);
  91. }
  92. }
  93.  
  94. void WINAPI Rotate(POINT arr[5])
  95. {
  96. static const POINT origin = { 150, 150 };
  97. static int i;
  98. static const double angle = 0.1;
  99. static const int direction = 1; // 1 or -1
  100. for (i = 0; i < 5; ++i)
  101. {
  102. arr[i].x -= origin.x;
  103. arr[i].y -= origin.y;
  104. arr[i].x = arr[i].x * cos(angle) - direction * arr[i].y * sin(angle);
  105. arr[i].y = direction * arr[i].x * sin(angle) + arr[i].y * cos(angle);
  106. arr[i].x += origin.x;
  107. arr[i].y += origin.y;
  108. }
  109. }
  110.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:21: error: Windows.h: No such file or directory
prog.cpp:5: error: ‘LRESULT’ does not name a type
prog.cpp:6: error: expected initializer before ‘Rotate’
prog.cpp:8: error: expected initializer before ‘WinMain’
stdout
Standard output is empty