Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.76 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include "Unit1.h"
  6. #include "Unit2.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. //---------------------------------------------------------------------------
  12. __fastcall TForm1::TForm1(TComponent* Owner)
  13. : TForm(Owner)
  14. {
  15. }
  16. //---------------------------------------------------------------------------
  17.  
  18. void __fastcall TForm1::N2Click(TObject *Sender)
  19. {
  20. Form1->Close();
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::N1Click(TObject *Sender)
  24. {
  25. Form2->Top=300;
  26. Form2->Left=300;
  27. Form2->Show();
  28. }
  29. //---------------------------------------------------------------------------
  30.  
  31. void __fastcall TForm1::Button1Click(TObject *Sender)
  32. {
  33. if(PriznakPr==0)
  34. {
  35. PriznakPr=1;
  36. Button1->Caption="Çóïèíèòè";
  37.  
  38. hThreads[0]=0;
  39. hThreads[1]=0;
  40. hThreads[2]=0;
  41. PriznKPr1=0;
  42. PriznKPr2=0;
  43. PriznKPr3=0;
  44.  
  45. Edit2->Text = 0;
  46. Edit4->Text = 0;
  47. Edit6->Text = 0;
  48. }
  49. else
  50. {
  51. PriznakPr=0;
  52. Button1->Caption="Ñòàðòóâàòè";
  53. CheckBox1->Checked=false;
  54. CheckBox2->Checked=false;
  55. CheckBox3->Checked=false;
  56. PriznakPr1=0;
  57. PriznakPr2=0;
  58. PriznakPr3=0;
  59. }
  60.  
  61. if(PriznakPr==1)
  62. {
  63. ///////////////////////////////////////////////////
  64. TStartupInfo si;
  65. TProcessInformation pi;
  66. AnsiString cmdline;
  67. ZeroMemory(&si,sizeof (si));
  68. si.cb = sizeof(si);
  69. DWORD vpr1=NORMAL_PRIORITY_CLASS;
  70. DWORD vpr2=NORMAL_PRIORITY_CLASS;
  71. DWORD vpr3=NORMAL_PRIORITY_CLASS;
  72. ///////////////////////////////////////////////////
  73. //DateTimePr=Time();
  74. if(PriznakPr1==1)
  75. {
  76. cmdline = "proces1.exe "+Edit1->Text; // çàïóñêàåì ýòó ïðîãðàììó
  77. DateTimePr1=Time();
  78. if(!CreateProcess(NULL, // No module name (use command line).
  79. cmdline.c_str(), // Command line.
  80. NULL, // Process handle not inheritable.
  81. NULL, // Thread handle not inheritable.
  82. false, // Set handle inheritance to FALSE.
  83. 0, // No creation flags.
  84. NULL, // Use parent's environment block.
  85. NULL, // Use parent's starting directory.
  86. &si, // Pointer to STARTUPINFO structure.
  87. &pi)) // Pointer to PROCESS_INFORMATION structure.
  88. {
  89. ShowMessage("CreateProcess failed.");
  90. }
  91. else
  92. {
  93. hProces1=pi.hProcess;
  94.  
  95. switch (ComboBox1->ItemIndex)
  96. {
  97. case 0 : vpr1=REALTIME_PRIORITY_CLASS;
  98. break;
  99. case 1 : vpr1=HIGH_PRIORITY_CLASS;
  100. break;
  101. case 2 : vpr1=NORMAL_PRIORITY_CLASS;
  102. break;
  103. case 3 : vpr1=IDLE_PRIORITY_CLASS;
  104. break;
  105. default :
  106. vpr1=NORMAL_PRIORITY_CLASS;
  107. }
  108. SetPriorityClass(hProces1,vpr1);
  109. ProcesCode1=0;
  110. hThreads[0]=hProces1;
  111. if(CheckBox1->Checked==true)
  112. {
  113. WaitForMultipleObjects(1, &hThreads[0], TRUE, INFINITE);
  114. DateTimePr1=Time()-DateTimePr1;
  115. Edit2->Text=DateTimePr1;
  116. TerminateProcess(hProces1,100);
  117. }
  118. }
  119. } // if(PriznakPr1==1)
  120. else
  121. {
  122. PriznKPr1=1;
  123. //DateTimePr1=0;
  124. }
  125. //////////////////////////////////////////////////
  126.  
  127. ///////////////////////////////////////////////////
  128. if(PriznakPr2==1)
  129. {
  130. cmdline = "proces2.exe "+Edit3->Text; // çàïóñêàåì ýòó ïðîãðàììó
  131. DateTimePr2=Time();
  132. if (!CreateProcess( NULL, // No module name (use command line).
  133. cmdline.c_str(), // Command line.
  134. NULL, // Process handle not inheritable.
  135. NULL, // Thread handle not inheritable.
  136. false, // Set handle inheritance to FALSE.
  137. 0, // No creation flags.
  138. NULL, // Use parent's environment block.
  139. NULL, // Use parent's starting directory.
  140. &si, // Pointer to STARTUPINFO structure.
  141. &pi )) // Pointer to PROCESS_INFORMATION structure.
  142. {
  143. ShowMessage("CreateProcess failed.");
  144. }
  145. else
  146. {
  147. hProces2=pi.hProcess;
  148. switch (ComboBox2->ItemIndex)
  149. {
  150. case 0 : vpr2=REALTIME_PRIORITY_CLASS;
  151. break;
  152. case 1 : vpr2=HIGH_PRIORITY_CLASS;
  153. break;
  154. case 2 : vpr2=NORMAL_PRIORITY_CLASS;
  155. break;
  156. case 3 : vpr2=IDLE_PRIORITY_CLASS;
  157. break;
  158. default :
  159. vpr2=NORMAL_PRIORITY_CLASS;
  160. }
  161. SetPriorityClass(hProces2,vpr2);
  162. hThreads[1]=hProces2;
  163. if(CheckBox2->Checked==true)
  164. {
  165. WaitForMultipleObjects(1, &hThreads[1], TRUE, INFINITE);
  166. DateTimePr2 = Time() - DateTimePr2;
  167. Edit4->Text = DateTimePr2;
  168. TerminateProcess(hProces2,100);
  169. }
  170. }
  171. } // if(PriznakPr2==1)
  172. else
  173. {
  174. PriznKPr2=1;
  175. DateTimePr2=0;
  176. }
  177. //////////////////////////////////////////////////
  178.  
  179. ///////////////////////////////////////////////////
  180. if(PriznakPr3==1)
  181. {
  182. cmdline = "proces3.exe "+Edit5->Text; // çàïóñêàåì ýòó ïðîãðàììó
  183. DateTimePr3=Time();
  184. if (!CreateProcess( NULL, // No module name (use command line).
  185. cmdline.c_str(), // Command line.
  186. NULL, // Process handle not inheritable.
  187. NULL, // Thread handle not inheritable.
  188. false, // Set handle inheritance to FALSE.
  189. 0, // No creation flags.
  190. NULL, // Use parent's environment block.
  191. NULL, // Use parent's starting directory.
  192. &si, // Pointer to STARTUPINFO structure.
  193. &pi )) // Pointer to PROCESS_INFORMATION structure.
  194. {
  195. ShowMessage("CreateProcess failed.");
  196. }
  197. else
  198. {
  199. hProces3=pi.hProcess;
  200. switch (ComboBox3->ItemIndex)
  201. {
  202. case 0 : vpr3=REALTIME_PRIORITY_CLASS;
  203. break;
  204. case 1 : vpr3=HIGH_PRIORITY_CLASS;
  205. break;
  206. case 2 : vpr3=NORMAL_PRIORITY_CLASS;
  207. break;
  208. case 3 : vpr3=IDLE_PRIORITY_CLASS;
  209. break;
  210. default :
  211. vpr3=NORMAL_PRIORITY_CLASS;
  212. }
  213. SetPriorityClass(hProces3,vpr3);
  214. hThreads[2]=hProces3;
  215. if(CheckBox3->Checked==true)
  216. {
  217. WaitForMultipleObjects(1, &hThreads[2], TRUE, INFINITE);
  218. DateTimePr3 = Time() - DateTimePr3;
  219. Edit6->Text = DateTimePr3;
  220. TerminateProcess(hProces3,100);
  221. }
  222. }
  223. } // if(PriznakPr3==1)
  224. else
  225. {
  226. PriznKPr3=1;
  227. DateTimePr3=0;
  228. }
  229. //////////////////////////////////////////////////
  230. } // if(PriznakPr==1)
  231. else
  232. {
  233. TerminateProcess(hProces1,100);
  234. TerminateProcess(hProces2,100);
  235. TerminateProcess(hProces3,100);
  236.  
  237. } // else if(PriznakPpr==1)
  238. /* if(PriznakPr1==1 || PriznakPr2==1 || PriznakPr3==1)
  239. {
  240. if(CheckBox7->Checked==true)
  241. Edit11->Text = DateTimePr1 + DateTimePr2 + DateTimePr3;
  242. else
  243. {
  244. int pp=PriznakPr1+PriznakPr2+PriznakPr3;
  245. if(pp==1)
  246. {
  247. if(PriznakPr2==1) hThreads[0]=hThreads[1];
  248. else if(PriznakPr3==1) hThreads[0]=hThreads[2];
  249. } // if(pp==1)
  250. else if(pp==2)
  251. {
  252. if(PriznakPr2==1 && PriznakPr3==1)
  253. {
  254. hThreads[0]=hThreads[1];
  255. hThreads[1]=hThreads[2];
  256. } // if(PriznakPr2==1 && PriznakPr3==1)
  257. else
  258. if(PriznakPr1==1 && PriznakPr3==1) hThreads[1]=hThreads[2];
  259. } // else if(pp==2)
  260. WaitForMultipleObjects(pp, hThreads, TRUE, INFINITE);
  261. Edit11->Text= Time() - DateTimePr;
  262. } // else
  263. */
  264. PriznakPr=0;
  265. Form1->Button1->Caption="Ñòàðòóâàòè";
  266. TerminateProcess(hProces1,100);
  267. TerminateProcess(hProces2,100);
  268. TerminateProcess(hProces3,100);
  269. }
  270.  
  271.  
  272. //---------------------------------------------------------------------------
  273.  
  274. void __fastcall TForm1::CheckBox1Click(TObject *Sender)
  275. {
  276. if(CheckBox1->Checked==true)
  277. {
  278. Edit1->Text=1000;
  279. ComboBox1->ItemIndex=2;
  280. Edit2->Text=0;
  281. //Edit11->Text=0;
  282. PriznakPr1=1;
  283. if(Button1->Enabled==false)
  284. Button1->Enabled=true;
  285. }
  286. else
  287. {
  288. //Edit12->Text=0;
  289. Edit1->Text=0;
  290. //Edit11->Text=0;
  291. PriznakPr1=0;
  292. if(CheckBox2->Checked==false && CheckBox3->Checked==false)
  293. Button1->Enabled=false;
  294. }
  295. }
  296. //---------------------------------------------------------------------------
  297.  
  298. void __fastcall TForm1::CheckBox2Click(TObject *Sender)
  299. {
  300. if(CheckBox2->Checked==true)
  301. {
  302. Edit3->Text=1000;
  303. ComboBox2->ItemIndex=2;
  304. Edit4->Text=0;
  305. //Edit11->Text=0;
  306. PriznakPr2=1;
  307. if(Button1->Enabled==false)
  308. Button1->Enabled=true;
  309. }
  310. else
  311. {
  312. //Edit12->Text=0;
  313. Edit3->Text=0;
  314. //Edit11->Text=0;
  315. PriznakPr2=0;
  316. if(CheckBox1->Checked==false && CheckBox3->Checked==false)
  317. Button1->Enabled=false;
  318. }
  319. }
  320. //---------------------------------------------------------------------------
  321.  
  322. void __fastcall TForm1::CheckBox3Click(TObject *Sender)
  323. {
  324. if(CheckBox3->Checked==true)
  325. {
  326. Edit5->Text=1000;
  327. ComboBox3->ItemIndex=2;
  328. Edit6->Text=0;
  329. //Edit11->Text=0;
  330. PriznakPr3=1;
  331. if(Button1->Enabled==false)
  332. Button1->Enabled=true;
  333. }
  334. else
  335. {
  336. //Edit12->Text=0;
  337. Edit5->Text=0;
  338. //Edit11->Text=0;
  339. PriznakPr3=0;
  340. if(CheckBox1->Checked==false && CheckBox2->Checked==false)
  341. Button1->Enabled=false;
  342. }
  343. }
  344. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement