ChameL1oN

ОС_Лаба3

Oct 12th, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 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.  
  8. void OpenTxte() //функция открытия блокнота
  9. {
  10. // Create empty process startup info.
  11. STARTUPINFO sInfo;
  12. ZeroMemory(&sInfo, sizeof(STARTUPINFO));
  13.  
  14. // Reserve memoryt for process information.
  15. PROCESS_INFORMATION pInfo;
  16.  
  17. // Create process.
  18. CreateProcess(L"C:\\Windows\\Notepad.exe",
  19. NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &sInfo, &pInfo);
  20. }
  21.  
  22.  
  23. LRESULT CALLBACK myWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  24. {
  25. switch (uMsg)
  26. {
  27. case WM_CLOSE: //Выход из программы
  28. PostQuitMessage(0);
  29. return 0;
  30. case WM_PAINT: //Смена цвета окна на рандомное
  31. if (GetAsyncKeyState(VK_RETURN)){
  32. HDC hdc;
  33. PAINTSTRUCT ps;
  34. RECT rc;
  35. HBRUSH hBrush;
  36. int a = rand()%256, b = rand()%256, c = rand()%256;
  37. hdc = BeginPaint(hWnd, &ps); //начинаем рисовать
  38. GetClientRect(hWnd, &rc); //получаем координаты окна
  39. hBrush = CreateSolidBrush(RGB(a, b, c)); //создаём новую кисть
  40. FillRect(hdc, &rc, hBrush); //рисуем
  41. EndPaint(hWnd, &ps); //заканчиваем рисовать
  42. }
  43. return 0;
  44. }
  45.  
  46. return DefWindowProc(hWnd, uMsg, wParam, lParam);
  47. }
  48.  
  49. void main()
  50. {
  51. srand(time(NULL));
  52. // Get the handler of module that will be associated with a window.
  53. // In this case it will be handler of the executable file of current process.
  54. HINSTANCE hInstance = GetModuleHandle(NULL);
  55.  
  56. // Create brush that will fill the background of the window.
  57. HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 255));
  58.  
  59. // Create window class.
  60. WNDCLASS winClass;
  61. winClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  62. winClass.lpfnWndProc = (WNDPROC)myWndProc;
  63. winClass.cbClsExtra = 0;
  64. winClass.cbWndExtra = 0;
  65. winClass.hInstance = hInstance;
  66. winClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
  67. winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  68. winClass.hbrBackground = hBrush; //Цвет окна
  69. winClass.lpszMenuName = NULL;
  70. winClass.lpszClassName = L"MyWindowclass";
  71.  
  72. // Register class in the system.
  73. RegisterClass(&winClass);
  74.  
  75. // Create window.
  76. HWND hWnd = CreateWindow(L"MyWindowclass", L"Window by raw API",
  77. WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  78. 100, 100, 320, 240,
  79. NULL, NULL, hInstance, NULL);
  80.  
  81. // Show window.
  82. ShowWindow(hWnd, SW_SHOW);
  83.  
  84. // Loop while window is not closed.
  85. MSG message;
  86. while (true)
  87. {
  88. if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
  89. {
  90. if (message.message == WM_QUIT)
  91. break;
  92. else
  93. {
  94. TranslateMessage(&message);
  95. DispatchMessage(&message);
  96. }
  97. }
  98. if (GetAsyncKeyState(VK_CONTROL)){
  99. if (GetAsyncKeyState('Q')){ DestroyWindow(hWnd); UnregisterClass(L"MyWindowclass", hInstance); DeleteObject(hBrush); WM_QUIT; break; }
  100. }
  101. if (GetAsyncKeyState(VK_ESCAPE)){ DestroyWindow(hWnd); UnregisterClass(L"MyWindowclass", hInstance); DeleteObject(hBrush); WM_QUIT; break; }
  102. if (GetAsyncKeyState(VK_RETURN)){
  103. WM_PAINT;
  104. }
  105.  
  106. if (GetAsyncKeyState(VK_LSHIFT)){
  107. if (GetAsyncKeyState('C') && flag){
  108. flag = false;
  109. OpenTxte();
  110. }
  111. }
  112. }
  113. // Delete window.
  114. DestroyWindow(hWnd);
  115.  
  116. // Remove window class.
  117. UnregisterClass(L"MyWindowclass", hInstance);
  118.  
  119. // Delete brush.
  120. DeleteObject(hBrush);
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment