Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.73 KB | None | 0 0
  1. // zadanie 1.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "zadanie 1.h"
  6. #include <cmath>
  7.  
  8. #define MAX_LOADSTRING 100
  9.  
  10. // Global Variables:
  11. HINSTANCE hInst; // current instance
  12. TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  13. TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
  14. int ak = 0;
  15.  
  16. // Forward declarations of functions included in this code module:
  17. ATOM MyRegisterClass(HINSTANCE hInstance);
  18. BOOL InitInstance(HINSTANCE, int);
  19. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  20. INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  21. VOID DRAW_TEST(HDC hdc, int ak, int xend, int yend);
  22. Gdiplus::PointF getpoc2(int angle,bool right,int x,int y,int length);
  23.  
  24. int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
  25. _In_opt_ HINSTANCE hPrevInstance,
  26. _In_ LPTSTR lpCmdLine,
  27. _In_ int nCmdShow)
  28. {
  29. UNREFERENCED_PARAMETER(hPrevInstance);
  30. UNREFERENCED_PARAMETER(lpCmdLine);
  31.  
  32. // TODO: Place code here.
  33. MSG msg;
  34. HACCEL hAccelTable;
  35. GdiplusStartupInput gdiplusStartupInput;
  36. ULONG_PTR gdiplusToken;
  37. GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  38.  
  39. // Initialize global strings
  40. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  41. LoadString(hInstance, IDC_ZADANIE1, szWindowClass, MAX_LOADSTRING);
  42. MyRegisterClass(hInstance);
  43.  
  44. // Perform application initialization:
  45. if (!InitInstance (hInstance, nCmdShow))
  46. {
  47. return FALSE;
  48. }
  49.  
  50. hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_ZADANIE1));
  51.  
  52. // Main message loop:
  53. while (GetMessage(&msg, NULL, 0, 0))
  54. {
  55. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  56. {
  57. TranslateMessage(&msg);
  58. DispatchMessage(&msg);
  59. }
  60. }
  61. GdiplusShutdown(gdiplusToken);
  62.  
  63. return (int) msg.wParam;
  64. }
  65.  
  66.  
  67.  
  68. //
  69. // FUNCTION: MyRegisterClass()
  70. //
  71. // PURPOSE: Registers the window class.
  72. //
  73. ATOM MyRegisterClass(HINSTANCE hInstance)
  74. {
  75. WNDCLASSEX wcex;
  76.  
  77. wcex.cbSize = sizeof(WNDCLASSEX);
  78.  
  79. wcex.style = CS_HREDRAW | CS_VREDRAW;
  80. wcex.lpfnWndProc = WndProc;
  81. wcex.cbClsExtra = 0;
  82. wcex.cbWndExtra = 0;
  83. wcex.hInstance = hInstance;
  84. wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ZADANIE1));
  85. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  86. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  87. wcex.lpszMenuName = MAKEINTRESOURCE(IDC_ZADANIE1);
  88. wcex.lpszClassName = szWindowClass;
  89. wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  90.  
  91. return RegisterClassEx(&wcex);
  92. }
  93.  
  94. //
  95. // FUNCTION: InitInstance(HINSTANCE, int)
  96. //
  97. // PURPOSE: Saves instance handle and creates main window
  98. //
  99. // COMMENTS:
  100. //
  101. // In this function, we save the instance handle in a global variable and
  102. // create and display the main program window.
  103. //
  104. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  105. {
  106. HWND hWnd;
  107.  
  108. hInst = hInstance; // Store instance handle in our global variable
  109.  
  110. hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  111. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  112.  
  113. if (!hWnd)
  114. {
  115. return FALSE;
  116. }
  117.  
  118. ShowWindow(hWnd, nCmdShow);
  119. UpdateWindow(hWnd);
  120.  
  121. return TRUE;
  122. }
  123.  
  124. //
  125. // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  126. //
  127. // PURPOSE: Processes messages for the main window.
  128. //
  129. // WM_COMMAND - process the application menu
  130. // WM_PAINT - Paint the main window
  131. // WM_DESTROY - post a quit message and return
  132. //
  133. //
  134. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  135. {
  136. int wmId, wmEvent;
  137. PAINTSTRUCT ps;
  138. HDC hdc;
  139.  
  140. switch (message)
  141. {
  142. case WM_RBUTTONDOWN:
  143. {
  144. InvalidateRect(hWnd, NULL, true);
  145. ak++; if (ak>1) ak = 0;
  146. ::UpdateWindow(hWnd);
  147. }
  148. break;
  149. case WM_COMMAND:
  150. wmId = LOWORD(wParam);
  151. wmEvent = HIWORD(wParam);
  152. // Parse the menu selections:
  153. switch (wmId)
  154. {
  155. case IDM_ABOUT:
  156. DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  157. break;
  158. case IDM_EXIT:
  159. DestroyWindow(hWnd);
  160. break;
  161. default:
  162. return DefWindowProc(hWnd, message, wParam, lParam);
  163. }
  164. break;
  165. case WM_PAINT:
  166. hdc = BeginPaint(hWnd, &ps);
  167. // TODO: Add any drawing code here...
  168. RECT rt;
  169. GetClientRect(hWnd, &rt);
  170. DRAW_TEST(hdc, ak, int(rt.right), int(rt.bottom));
  171. EndPaint(hWnd, &ps);
  172. break;
  173. case WM_DESTROY:
  174. PostQuitMessage(0);
  175. break;
  176. default:
  177. return DefWindowProc(hWnd, message, wParam, lParam);
  178. }
  179. return 0;
  180. }
  181.  
  182. // Message handler for about box.
  183. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  184. {
  185. UNREFERENCED_PARAMETER(lParam);
  186. switch (message)
  187. {
  188. case WM_INITDIALOG:
  189. return (INT_PTR)TRUE;
  190.  
  191. case WM_COMMAND:
  192. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  193. {
  194. EndDialog(hDlg, LOWORD(wParam));
  195. return (INT_PTR)TRUE;
  196. }
  197. break;
  198. }
  199. return (INT_PTR)FALSE;
  200. }
  201. VOID DRAW_TEST(HDC hdc, int ak, int xend, int yend)
  202. {
  203. int max = min(xend, yend);
  204.  
  205.  
  206. Graphics graphics(hdc); // инициация на графичен обект върху екрана
  207. Rect ellipseRect(xend / 2 - max / 2, yend / 2 - max / 2, max, max);// xend / 2+max/2, yend / 2+max/2); //дефиниране на елипса с горен ляв ъгъл
  208.  
  209.  
  210.  
  211. //на описващия правоъгълник в средата на растера и рамери ¼ растер
  212. Pen bluePen(Color(255, 0, 0, 255)); // дефиниране на син молив
  213. Pen redPen(Color(255, 255, 0, 0)); // дефиниране на червен молив
  214. Pen bpen(Color(0, 0, 0));
  215. Pen daga[7];
  216. daga[0] = bluePen;
  217. //if (ak == 1)
  218. graphics.DrawEllipse(&bpen, ellipseRect); //чертае елипса
  219. //else
  220. for (int i = 0; i < 2; i++)
  221. graphics.DrawLine(&daga[i], getpoc2(i * 10, true, xend / 2, yend / 2, max / 2),
  222. getpoc2(i * 10, false , xend / 2, yend / 2, max / 2)
  223. //Gdiplus::PointF(Gdiplus::REAL(xend/2),
  224. // Gdiplus::REAL(yend/2))
  225. ); //чертае отсечка
  226. }
  227. //Pen daga[2] = { Color(255, 0, 0),Color(255, 128, 0) };// , Color(255, 255, 0), Color(0, 255, 0), Color(0, 255, 255), Color(0, 0, 255), Color(255, 0, 255)};
  228.  
  229. Gdiplus::PointF getpoc2(int angle, bool right, int x, int y, int length)
  230. {
  231. if (right)
  232. {
  233. return Gdiplus::PointF(
  234. Gdiplus::REAL(_CMATH_::cos( 3.14*((float)angle)/180.0 )*((float)length)+(float)x),
  235. Gdiplus::REAL(_CMATH_::sin(3.14*((float)angle) / 180.0)*((float)length) + (float)y)
  236.  
  237. );
  238. }
  239. else
  240. {
  241. return Gdiplus::PointF(
  242. Gdiplus::REAL(_CMATH_::cos(3.14*((float)angle) / 180.0-3.14)*((float)length) + (float)x),
  243. Gdiplus::REAL(_CMATH_::sin(3.14*((float)angle) / 180.0-3.14)*((float)length) + (float)y)
  244.  
  245. );
  246. }
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement