Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.48 KB | None | 0 0
  1. #define __DEFINE_VSTUB_CONSTS__
  2. #include "vstub.h"
  3. #include <math.h>
  4.  
  5. namespace std{
  6.  
  7. HWND hWndMAIN;
  8. HWND hWndC;
  9. HWND hWndG;
  10. HDC hdcBufC;
  11. HDC hdcScbC;
  12. HDC hdcBufG;
  13. HBITMAP hbmC;
  14. HBITMAP hsbC;
  15. HBITMAP hbmG;
  16.  
  17. DWORD StartMainThreadId;
  18. HANDLE StartMainHandle;
  19.  
  20. vcstreambuf vcsb;
  21. ostream vc (&vcsb);
  22.  
  23. int CEHeight;
  24. int KeyPressed;
  25.  
  26. void printchar (char c);
  27. void print_n ();
  28. void print_r ();
  29. void print_c (char c);
  30. LONG WINAPI wndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  31. int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow);
  32.  
  33. int vcstreambuf::sync ()
  34. {
  35. char *s;
  36. int i;
  37. s = str();
  38. for (i = 0; i < pcount();/*out_waiting();*/ i++) {
  39. printchar (s[i]);
  40. }
  41. freeze(0);
  42. vc.clear ();
  43. vc.seekp (0);
  44. RedrawWindow (hWndC, NULL, NULL, RDW_INVALIDATE);
  45. return i;
  46. }
  47.  
  48. void print_n ()
  49. {
  50. POINT cp;
  51. GetCurrentPositionEx (hdcBufC, &cp);
  52. if (cp.y >= CEHeight-vstubCellH) {
  53. BitBlt (hdcScbC, 0, 0, vstubWidthC, CEHeight-vstubCellH, hdcBufC, 0, vstubCellH, SRCCOPY);
  54. BitBlt (hdcBufC, 0, 0, vstubWidthC, vstubHeightC, hdcScbC, 0, 0, SRCCOPY);
  55. MoveToEx (hdcBufC, 1, cp.y, NULL);
  56. }
  57. else {
  58. MoveToEx (hdcBufC, 1, cp.y+vstubCellH, NULL);
  59. }
  60. }
  61.  
  62. void print_r ()
  63. {
  64. POINT cp;
  65. GetCurrentPositionEx (hdcBufC, &cp);
  66. MoveToEx (hdcBufC, 1, cp.y, NULL);
  67. }
  68.  
  69. void print_c (char c)
  70. {
  71. POINT cp;
  72. GetCurrentPositionEx (hdcBufC, &cp);
  73. if (cp.x >= vstubWidthC-8) {
  74. print_n ();
  75. }
  76. TextOut (hdcBufC, 0, 0, &c, 1);
  77. }
  78.  
  79. void printchar (char c)
  80. {
  81. if (c == 0) return;
  82. else if (c == '\n') print_n ();
  83. else if (c == '\r') print_r ();
  84. else print_c (c);
  85. }
  86.  
  87. void drawgrid ()
  88. {
  89. int i;
  90. setcolor (64,64,64);
  91. for (i = 10; i < vstubWidthG; i+=10) {
  92. putline (i, 0, i, vstubHeightG);
  93. }
  94. for (i = 10; i < vstubHeightG; i+=10) {
  95. putline (0, i, vstubWidthG, i);
  96. }
  97. setcolor (96,96,96);
  98. putline (vstubWidthG/2,0,vstubWidthG/2,vstubHeightG);
  99. drawline (0,vstubHeightG/2,vstubWidthG,vstubHeightG/2);
  100. }
  101.  
  102. void setcolor (unsigned char r, unsigned char g, unsigned char b)
  103. {
  104. HPEN hpen;
  105. hpen = CreatePen (PS_SOLID, 0, RGB(r,g,b));
  106. hpen = (HPEN) SelectObject (hdcBufG, hpen);
  107. if (hpen != NULL)
  108. DeleteObject (hpen);
  109. }
  110.  
  111. void putline (int x1, int y1, int x2, int y2)
  112. {
  113. MoveToEx (hdcBufG, x1, y1, NULL);
  114. LineTo (hdcBufG, x2, y2);
  115. }
  116. void drawline (int x1, int y1, int x2, int y2)
  117. {
  118. putline(x1,y1,x2,y2);
  119. RedrawWindow (hWndG, NULL, NULL, RDW_INVALIDATE);
  120. }
  121.  
  122. void putpixel (int x, int y)
  123. {
  124. MoveToEx (hdcBufG, x, y, NULL);
  125. LineTo (hdcBufG, x+1, y);
  126. }
  127. void drawpixel (int x, int y){
  128. putpixel(x,y);
  129. RedrawWindow (hWndG, NULL, NULL, RDW_INVALIDATE);
  130. }
  131.  
  132. void putarc (int x, int y, int radius, float StartAngle, float SweepAngle)
  133. {
  134. if (SweepAngle > 2*3.141592654-0.00001) {
  135. Arc (hdcBufG, x-radius, y-radius, x+radius, y+radius, 1, 0, 1, 0);
  136. }
  137. else {
  138. Arc (hdcBufG, x-radius, y-radius, x+radius, y+radius, (int)(50000.0*cos(StartAngle)), -(int)(50000.0*sin(StartAngle)), (int)(50000.0*cos(StartAngle+SweepAngle)), -(int)(50000.0*sin(StartAngle+SweepAngle)));
  139. }
  140. RedrawWindow (hWndG, NULL, NULL, RDW_INVALIDATE);
  141. }
  142. void drawarc (int x, int y, int radius, float StartAngle, float SweepAngle)
  143. {
  144. putarc(x,y,radius,StartAngle,SweepAngle);
  145. RedrawWindow (hWndG, NULL, NULL, RDW_INVALIDATE);
  146. }
  147.  
  148. void TFlush(void)
  149. {
  150. // cout.flush();
  151. vc.flush();
  152. // RedrawWindow (hWndC, NULL, NULL, RDW_INVALIDATE);
  153. }
  154. void GFlush(void)
  155. {
  156. RedrawWindow (hWndG, NULL, NULL, RDW_INVALIDATE);
  157. }
  158.  
  159. int vgetchar ()
  160. {
  161. int t;
  162. while (!KeyPressed);
  163. t = KeyPressed;
  164. KeyPressed = 0;
  165. return t;
  166. }
  167.  
  168. DWORD WINAPI StartMain (LPVOID lpParameter)
  169. {
  170. int t;
  171. t = main ();
  172. ExitThread (t);
  173. return (t);
  174. }
  175.  
  176.  
  177.  
  178. LONG WINAPI wndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  179. {
  180. HDC hdc;
  181. PAINTSTRUCT ps;
  182. switch (msg) {
  183. case WM_DESTROY:
  184. PostQuitMessage (0);
  185. return 0;
  186. case WM_PAINT:
  187. if (hWnd == hWndC) {
  188. hdc = BeginPaint (hWnd, &ps);
  189. BitBlt (hdc, 0, 0, vstubWidthC, vstubHeightC, hdcBufC, 0, 0, SRCCOPY);
  190. EndPaint (hWnd, &ps);
  191. }
  192. else if (hWnd == hWndG) {
  193. hdc = BeginPaint (hWnd, &ps);
  194. BitBlt (hdc, 0, 0, vstubWidthG, vstubHeightG, hdcBufG, 0, 0, SRCCOPY);
  195. EndPaint (hWnd, &ps);
  196. }
  197. else
  198. break;
  199. return 0;
  200. case WM_KEYDOWN:
  201. KeyPressed = wParam;
  202. return 0;
  203. }
  204. return DefWindowProc (hWnd, msg, wParam, lParam);
  205. }
  206. }
  207.  
  208. //int WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow)
  209. int APIENTRY WinMain(HINSTANCE hInstance,
  210. HINSTANCE hPrevInstance,
  211. LPTSTR lpCmdLine,
  212. int cmdShow)
  213. {
  214.  
  215. static char winMName [] = "Task6";
  216. static char win1Name [] = "Console";
  217. static char win2Name [] = "Graphic";
  218. WNDCLASS wc;
  219. MSG msg;
  220. HDC hdc;
  221. HFONT hfnt;
  222. DWORD ThreadExitCode;
  223.  
  224. wc.style = 0;
  225. wc.lpfnWndProc = (WNDPROC) std::wndProc;
  226. wc.cbClsExtra = 0;
  227. wc.cbWndExtra = 0;
  228. wc.hInstance = hInstance;
  229. wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  230. wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  231. wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  232. wc.lpszMenuName = NULL;
  233. wc.lpszClassName = winMName;
  234.  
  235. RegisterClass (&wc);
  236. std::hWndMAIN = CreateWindowEx (0, winMName, winMName, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, std::vstubWidth+12, std::vstubHeight+36, HWND_DESKTOP, NULL, hInstance, NULL);
  237. ShowWindow (std::hWndMAIN, cmdShow);
  238. UpdateWindow (std::hWndMAIN);
  239.  
  240. wc.style = 0;
  241. wc.lpfnWndProc = (WNDPROC) std::wndProc;
  242. wc.cbClsExtra = 0;
  243. wc.cbWndExtra = 0;
  244. wc.hInstance = hInstance;
  245. wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  246. wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  247. wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  248. wc.lpszMenuName = NULL;
  249. wc.lpszClassName = win1Name;
  250.  
  251. RegisterClass (&wc);
  252. std::hWndC = CreateWindowEx (0, win1Name, win1Name, WS_CHILD | WS_CLIPSIBLINGS, 2, 2, std::vstubWidthC, std::vstubHeightC, std::hWndMAIN, NULL, hInstance, NULL);
  253. hdc = GetDC (std::hWndC);
  254. std::hdcBufC = CreateCompatibleDC (hdc);
  255. std::hdcScbC = CreateCompatibleDC (hdc);
  256. std::hbmC = CreateCompatibleBitmap (hdc, std::vstubWidthC, std::vstubHeightC);
  257. std::hsbC = CreateCompatibleBitmap (hdc, std::vstubWidthC, std::vstubHeightC);
  258. SelectObject (std::hdcBufC, std::hbmC);
  259. SelectObject (std::hdcScbC, std::hsbC);
  260. ReleaseDC (std::hWndC, hdc);
  261. ShowWindow (std::hWndC, cmdShow);
  262. UpdateWindow (std::hWndC);
  263.  
  264. wc.style = 0;
  265. wc.lpfnWndProc = (WNDPROC) std::wndProc;
  266. wc.cbClsExtra = 0;
  267. wc.cbWndExtra = 0;
  268. wc.hInstance = hInstance;
  269. wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  270. wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  271. wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  272. wc.lpszMenuName = NULL;
  273. wc.lpszClassName = win2Name;
  274.  
  275. RegisterClass (&wc);
  276. std::hWndG = CreateWindowEx (0, win2Name, win2Name, WS_CHILD | WS_CLIPSIBLINGS, std::vstubWidthC+4, 2, std::vstubWidthG, std::vstubHeightG, std::hWndMAIN, NULL, hInstance, NULL);
  277. hdc = GetDC (std::hWndG);
  278. std::hdcBufG = CreateCompatibleDC (hdc);
  279. std::hbmG = CreateCompatibleBitmap (hdc, std::vstubWidthG, std::vstubHeightG);
  280. SelectObject (std::hdcBufG, std::hbmG);
  281. ReleaseDC (std::hWndG, hdc);
  282. ShowWindow (std::hWndG, cmdShow);
  283. UpdateWindow (std::hWndG);
  284.  
  285. std::CEHeight = std::vstubHeightC-(std::vstubHeightC%std::vstubCellH);
  286.  
  287. SetMapMode (std::hdcBufC, MM_TEXT);
  288. SetBkColor (std::hdcBufC, RGB(0,0,0));
  289. SetTextColor (std::hdcBufC, std::vstubTextColor);
  290. hfnt = (HFONT) GetStockObject (OEM_FIXED_FONT);
  291. SelectObject (std::hdcBufC, hfnt);
  292. SetTextAlign (std::hdcBufC, TA_UPDATECP);
  293. MoveToEx (std::hdcBufC, 1, 1, NULL);
  294.  
  295. // cout = vc;
  296. std::setcolor (255,255,0);
  297. std::KeyPressed = 0;
  298.  
  299. std::StartMainHandle = CreateThread (NULL, 0, std::StartMain, NULL, 0, &std::StartMainThreadId);
  300. if (std::StartMainHandle == NULL)
  301. return 66;
  302. SetThreadPriority (std::StartMainHandle, THREAD_PRIORITY_BELOW_NORMAL);
  303.  
  304. while (GetMessage (&msg, NULL, 0, 0)) {
  305. TranslateMessage (&msg);
  306. DispatchMessage (&msg);
  307. GetExitCodeThread (std::StartMainHandle, &ThreadExitCode);
  308. if (ThreadExitCode != STILL_ACTIVE) {
  309. CloseHandle (std::StartMainHandle);
  310. return (ThreadExitCode);
  311. }
  312. }
  313. TerminateThread (std::StartMainHandle, 0);
  314. CloseHandle (std::StartMainHandle);
  315. return msg.wParam;
  316.  
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement