ChameL1oN

3

Nov 25th, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include <stdlib.h>
  4. #include <ctime>
  5.  
  6. bool flag = true;
  7. bool flag2 = true;
  8.  
  9. void OpenNotepad()
  10. {
  11. // Create empty process startup info.
  12. STARTUPINFO sInfo;
  13. ZeroMemory(&sInfo, sizeof(STARTUPINFO));
  14.  
  15. // Reserve memoryt for process information.
  16. PROCESS_INFORMATION pInfo;
  17.  
  18. // Create process.
  19. CreateProcess(L"C:\\Windows\\Notepad.exe",
  20. NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &sInfo, &pInfo);
  21. }
  22.  
  23.  
  24. LRESULT CALLBACK myWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  25. {
  26. switch (uMsg)
  27. {
  28. case WM_CLOSE:
  29. PostQuitMessage(0);
  30. return 0;
  31. case WM_PAINT:
  32. if (GetAsyncKeyState(VK_RETURN)){
  33. srand(time(NULL));
  34.  
  35. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 241, SWP_NOMOVE);
  36. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 240, SWP_NOMOVE);
  37. HDC hdc;
  38. hdc = GetDC(hWnd);
  39. PAINTSTRUCT ps;
  40. RECT rc;
  41. HBRUSH hBrush;
  42. int a = rand()%256, b = rand()%256, c = rand()%256;
  43. hdc = BeginPaint(hWnd, &ps);
  44. GetClientRect(hWnd, &rc);
  45. hBrush = CreateSolidBrush(RGB(a, b, c));
  46. FillRect(hdc, &rc, hBrush);
  47. EndPaint(hWnd, &ps);
  48. }
  49. return 0;
  50. case WM_LBUTTONDOWN:
  51. WORD xPos, yPos, nSize;
  52. TCHAR szBuf[80];
  53.  
  54. // Сохраняем координаты курсора мыши
  55. xPos = LOWORD(lParam);
  56. yPos = HIWORD(lParam);
  57. HDC hdc;
  58. hdc = GetDC(hWnd);
  59.  
  60. // Подготавливаем текстовую строку, содержащую
  61. // координаты курсора мыши
  62. nSize = wsprintf(szBuf, TEXT("(%d, %d)"), xPos, yPos);
  63.  
  64. // Выводим координаты курсора мыши
  65. // в точке, соответствующей положению
  66. // курсора мыши
  67. //TextOut(hdc, xPos, yPos, szBuf, nSize);
  68. if (xPos < 160 && yPos < 120){
  69. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 241, SWP_NOMOVE);
  70. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 240, SWP_NOMOVE);
  71. PAINTSTRUCT ps;
  72. RECT rc;
  73. HBRUSH hBrush;
  74. hdc = BeginPaint(hWnd, &ps);
  75. GetClientRect(hWnd, &rc);
  76. hBrush = CreateSolidBrush(RGB(255, 0, 0));
  77. FillRect(hdc, &rc, hBrush);
  78. EndPaint(hWnd, &ps);
  79. }
  80. if (xPos < 160 && yPos > 120){
  81. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 241, SWP_NOMOVE);
  82. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 240, SWP_NOMOVE);
  83. PAINTSTRUCT ps;
  84. RECT rc;
  85. HBRUSH hBrush;
  86. hdc = BeginPaint(hWnd, &ps);
  87. GetClientRect(hWnd, &rc);
  88. hBrush = CreateSolidBrush(RGB(0,255, 0));
  89. FillRect(hdc, &rc, hBrush);
  90. EndPaint(hWnd, &ps);
  91. }
  92. if (xPos > 160 && yPos < 120){
  93. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 241, SWP_NOMOVE);
  94. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 240, SWP_NOMOVE);
  95. PAINTSTRUCT ps;
  96. RECT rc;
  97. HBRUSH hBrush;
  98. hdc = BeginPaint(hWnd, &ps);
  99. GetClientRect(hWnd, &rc);
  100. hBrush = CreateSolidBrush(RGB(200, 200, 0));
  101. FillRect(hdc, &rc, hBrush);
  102. EndPaint(hWnd, &ps);
  103. }
  104. if (xPos > 160 && yPos > 120){
  105. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 241, SWP_NOMOVE);
  106. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 240, SWP_NOMOVE);
  107. PAINTSTRUCT ps;
  108. RECT rc;
  109. HBRUSH hBrush;
  110. hdc = BeginPaint(hWnd, &ps);
  111. GetClientRect(hWnd, &rc);
  112. hBrush = CreateSolidBrush(RGB(0, 0, 255));
  113. FillRect(hdc, &rc, hBrush);
  114. EndPaint(hWnd, &ps);
  115. }
  116. ReleaseDC(hWnd, hdc);
  117. return 0;
  118. }
  119.  
  120. return DefWindowProc(hWnd, uMsg, wParam, lParam);
  121. }
  122.  
  123. void main()
  124. {
  125.  
  126. // Get the handler of module that will be associated with a window.
  127. // In this case it will be handler of the executable file of current process.
  128. HINSTANCE hInstance = GetModuleHandle(NULL);
  129.  
  130. // Create brush that will fill the background of the window.
  131. HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 255));
  132.  
  133. // Create window class.
  134. WNDCLASS winClass;
  135. winClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  136. winClass.lpfnWndProc = (WNDPROC)myWndProc;
  137. winClass.cbClsExtra = 0;
  138. winClass.cbWndExtra = 0;
  139. winClass.hInstance = hInstance;
  140. winClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
  141. winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  142. winClass.hbrBackground = hBrush;
  143. winClass.lpszMenuName = NULL;
  144. winClass.lpszClassName = L"MyWindowclass";
  145.  
  146. // Register class in the system.
  147. RegisterClass(&winClass);
  148.  
  149. // Create window.
  150. HWND hWnd = CreateWindow(L"MyWindowclass", L"Window by raw API",
  151. WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  152. 100, 100, 320, 240,
  153. NULL, NULL, hInstance, NULL);
  154.  
  155. // Show window.
  156. ShowWindow(hWnd, SW_SHOW);
  157.  
  158. // Loop while window is not closed.
  159. MSG message;
  160. while (true)
  161. {
  162. if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
  163. {
  164. if (message.message == WM_QUIT)
  165. break;
  166. else
  167. {
  168. TranslateMessage(&message);
  169. DispatchMessage(&message);
  170. }
  171. }
  172. if (GetAsyncKeyState(VK_CONTROL)){
  173. if (GetAsyncKeyState('Q')){ DestroyWindow(hWnd); UnregisterClass(L"MyWindowclass", hInstance); DeleteObject(hBrush); WM_QUIT; break; }
  174. }
  175. if (GetAsyncKeyState(VK_ESCAPE)){ DestroyWindow(hWnd); UnregisterClass(L"MyWindowclass", hInstance); DeleteObject(hBrush); WM_QUIT; break; }
  176.  
  177. if (GetAsyncKeyState(VK_RETURN)){
  178. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 241, SWP_NOMOVE);
  179. SetWindowPos(hWnd, HWND_TOP, 100, 100, 320, 240, SWP_NOMOVE);
  180. flag2 = false;
  181. WM_PAINT;
  182. }
  183.  
  184. if (GetAsyncKeyState(VK_LSHIFT)){
  185. if (GetAsyncKeyState('C') && flag){
  186. flag = false;
  187. OpenNotepad();
  188. }
  189. }
  190. }
  191. // Delete window.
  192. DestroyWindow(hWnd);
  193.  
  194. // Remove window class.
  195. UnregisterClass(L"MyWindowclass", hInstance);
  196.  
  197. // Delete brush.
  198. DeleteObject(hBrush);
  199.  
  200. }
Advertisement
Add Comment
Please, Sign In to add comment