Guest User

Untitled

a guest
Feb 6th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.61 KB | None | 0 0
  1. // Poorly done code by Atton Risk 2015
  2. #include <string>
  3. #include <windows.h>
  4. #include <stdexcept>
  5. #include <sstream>
  6. #include <iomanip>
  7. #include <bitset>
  8. #include <iostream>
  9. #include <limits>
  10. #include <process.h>
  11. #include <msclr\marshal_cppstd.h>
  12. #include "bin.h"
  13. #pragma once
  14.  
  15. namespace PingPhuckersGUI {
  16. using namespace std;
  17. using namespace System;
  18. using namespace System::ComponentModel;
  19. using namespace System::Collections;
  20. using namespace System::Windows::Forms;
  21. using namespace System::Data;
  22. using namespace System::Drawing;
  23.  
  24. /// <summary>
  25. /// Summary for mainGUI
  26. /// </summary>
  27. public ref class mainGUI : public System::Windows::Forms::Form
  28. {
  29. public:
  30. mainGUI(void)
  31. {
  32. InitializeComponent();
  33. //
  34. //TODO: Add the constructor code here
  35. //
  36. }
  37. protected:
  38. /// <summary>
  39. /// Clean up any resources being used.
  40. /// </summary>
  41. ~mainGUI()
  42. {
  43. if (components)
  44. {
  45. delete components;
  46. }
  47. }
  48. private: System::Windows::Forms::Button^ goButton;
  49. protected:
  50.  
  51. protected:
  52. private: System::Windows::Forms::TextBox^ pingAddressBox;
  53. private: System::Windows::Forms::TextBox^ pingOutbox;
  54. private: System::Windows::Forms::TextBox^ pingDelayBox;
  55.  
  56. private: System::Windows::Forms::Label^ pingL;
  57. private: System::Windows::Forms::Label^ pingServerDelay;
  58. private: System::ComponentModel::BackgroundWorker^ backgroundWorker1;
  59.  
  60. private: System::Windows::Forms::PictureBox^ pictureBox1;
  61.  
  62. private:
  63. bool sysActive;
  64. void setText(int data)
  65. {
  66. pingOutbox->Text = Convert::ToString(data);
  67. pingOutbox->Refresh();
  68. cout << data << endl;
  69. }
  70.  
  71. void mainPingThing()
  72. {
  73. int speed(0);
  74. setText(runPing());
  75. Sleep(2500);
  76. }
  77. /// <summary>
  78. /// Required designer variable.
  79. /// </summary>
  80. System::ComponentModel::Container ^components;
  81.  
  82. #pragma region Windows Form Designer generated code
  83. /// <summary>
  84. /// Required method for Designer support - do not modify
  85. /// the contents of this method with the code editor.
  86. /// </summary>
  87. void InitializeComponent(void)
  88. {
  89. System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(mainGUI::typeid));
  90. this->goButton = (gcnew System::Windows::Forms::Button());
  91. this->pingAddressBox = (gcnew System::Windows::Forms::TextBox());
  92. this->pingOutbox = (gcnew System::Windows::Forms::TextBox());
  93. this->pingDelayBox = (gcnew System::Windows::Forms::TextBox());
  94. this->pingL = (gcnew System::Windows::Forms::Label());
  95. this->pingServerDelay = (gcnew System::Windows::Forms::Label());
  96. this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
  97. this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());
  98. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
  99. this->SuspendLayout();
  100. //
  101. // goButton
  102. //
  103. this->goButton->Location = System::Drawing::Point(3, 110);
  104. this->goButton->Name = L"goButton";
  105. this->goButton->Size = System::Drawing::Size(85, 31);
  106. this->goButton->TabIndex = 0;
  107. this->goButton->Text = L"Go";
  108. this->goButton->UseVisualStyleBackColor = true;
  109. this->goButton->Click += gcnew System::EventHandler(this, &mainGUI::goButton_Click);
  110. //
  111. // pingAddressBox
  112. //
  113. this->pingAddressBox->Location = System::Drawing::Point(94, 110);
  114. this->pingAddressBox->Multiline = true;
  115. this->pingAddressBox->Name = L"pingAddressBox";
  116. this->pingAddressBox->Size = System::Drawing::Size(229, 35);
  117. this->pingAddressBox->TabIndex = 1;
  118. this->pingAddressBox->Text = L"google.com";
  119. this->pingAddressBox->TextChanged += gcnew System::EventHandler(this, &mainGUI::pingAddressBox_TextChanged);
  120. //
  121. // pingOutbox
  122. //
  123. this->pingOutbox->Location = System::Drawing::Point(3, 25);
  124. this->pingOutbox->MaxLength = 8;
  125. this->pingOutbox->Name = L"pingOutbox";
  126. this->pingOutbox->ReadOnly = true;
  127. this->pingOutbox->Size = System::Drawing::Size(85, 20);
  128. this->pingOutbox->TabIndex = 2;
  129. this->pingOutbox->Text = L"0";
  130. this->pingOutbox->TextChanged += gcnew System::EventHandler(this, &mainGUI::pingOutbox_TextChanged);
  131. //
  132. // pingDelayBox
  133. //
  134. this->pingDelayBox->Enabled = false;
  135. this->pingDelayBox->Location = System::Drawing::Point(3, 77);
  136. this->pingDelayBox->Name = L"pingDelayBox";
  137. this->pingDelayBox->Size = System::Drawing::Size(92, 20);
  138. this->pingDelayBox->TabIndex = 3;
  139. this->pingDelayBox->Text = L"2";
  140. this->pingDelayBox->Visible = false;
  141. this->pingDelayBox->TextChanged += gcnew System::EventHandler(this, &mainGUI::pingDelayBox_TextChanged);
  142. //
  143. // pingL
  144. //
  145. this->pingL->AutoSize = true;
  146. this->pingL->Location = System::Drawing::Point(0, 9);
  147. this->pingL->Name = L"pingL";
  148. this->pingL->Size = System::Drawing::Size(88, 13);
  149. this->pingL->TabIndex = 4;
  150. this->pingL->Text = L"Ping Milliseconds";
  151. //
  152. // pingServerDelay
  153. //
  154. this->pingServerDelay->AutoSize = true;
  155. this->pingServerDelay->Enabled = false;
  156. this->pingServerDelay->Location = System::Drawing::Point(0, 61);
  157. this->pingServerDelay->Name = L"pingServerDelay";
  158. this->pingServerDelay->Size = System::Drawing::Size(95, 13);
  159. this->pingServerDelay->TabIndex = 5;
  160. this->pingServerDelay->Text = L"Ping Server Delay ";
  161. this->pingServerDelay->Visible = false;
  162. //
  163. // pictureBox1
  164. //
  165. this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pictureBox1.Image")));
  166. this->pictureBox1->Location = System::Drawing::Point(112, 12);
  167. this->pictureBox1->Name = L"pictureBox1";
  168. this->pictureBox1->Size = System::Drawing::Size(196, 85);
  169. this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::CenterImage;
  170. this->pictureBox1->TabIndex = 6;
  171. this->pictureBox1->TabStop = false;
  172. //
  173. // backgroundWorker1
  174. //
  175. this->backgroundWorker1->WorkerReportsProgress = true;
  176. this->backgroundWorker1->WorkerSupportsCancellation = true;
  177. this->backgroundWorker1->DoWork += gcnew System::ComponentModel::DoWorkEventHandler(this, &mainGUI::backgroundWorker1_DoWork_1);
  178. //
  179. // mainGUI
  180. //
  181. this->AutoScaleDimensions = System::Drawing::SizeF(96, 96);
  182. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Dpi;
  183. this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"$this.BackgroundImage")));
  184. this->ClientSize = System::Drawing::Size(329, 149);
  185. this->Controls->Add(this->pictureBox1);
  186. this->Controls->Add(this->pingServerDelay);
  187. this->Controls->Add(this->pingL);
  188. this->Controls->Add(this->pingDelayBox);
  189. this->Controls->Add(this->pingOutbox);
  190. this->Controls->Add(this->pingAddressBox);
  191. this->Controls->Add(this->goButton);
  192. this->ForeColor = System::Drawing::Color::Black;
  193. this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
  194. this->Location = System::Drawing::Point(90, 90);
  195. this->MaximizeBox = false;
  196. this->MinimizeBox = false;
  197. this->Name = L"mainGUI";
  198. this->ShowIcon = false;
  199. this->ShowInTaskbar = false;
  200. this->StartPosition = System::Windows::Forms::FormStartPosition::Manual;
  201. this->Text = L"PingPhuckers";
  202. this->TopMost = true;
  203. this->Load += gcnew System::EventHandler(this, &mainGUI::mainGUI_Load);
  204. (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
  205. this->ResumeLayout(false);
  206. this->PerformLayout();
  207.  
  208. }
  209. #pragma endregion
  210.  
  211. private: System::Void mainGUI_Load(System::Object^ sender, System::EventArgs^ e)
  212. {
  213. // This is when the gui loads lol
  214. cout << "GUI OPEN" << std::endl;
  215. sysActive = false;
  216. load();
  217. }
  218. private: System::Void goButton_Click(System::Object^ sender, System::EventArgs^ e)
  219. {
  220. String ^ Delay = pingDelayBox->Text;
  221. String ^ Site = pingAddressBox->Text;
  222. string theDelay(msclr::interop::marshal_as<std::string>(Delay));
  223. string theSite(msclr::interop::marshal_as<std::string>(Site));
  224. int intDelay(atoi(theDelay.c_str()));
  225. setData(theSite,intDelay);
  226.  
  227. if (!sysActive)
  228. {
  229. backgroundWorker1->RunWorkerAsync(1);
  230. Sleep(1000);
  231. sysActive = true;
  232. cout << "Go" << endl;
  233. }
  234. else if (sysActive)
  235. {
  236. backgroundWorker1->CancelAsync();
  237. Sleep(1000);
  238. sysActive = false;
  239. cout << "Stop" << endl;
  240. }
  241.  
  242. //TimerTime->Stop;
  243. }
  244. // Holders
  245. private: System::Void pingAddressBox_TextChanged(System::Object^ sender, System::EventArgs^ e) {}
  246. private: System::Void pingOutbox_TextChanged(System::Object^ sender, System::EventArgs^ e) {}
  247. private: System::Void pingDelayBox_TextChanged(System::Object^ sender, System::EventArgs^ e) {}
  248. /*
  249. private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e)
  250. {
  251.  
  252. }
  253.  
  254. */
  255. private: System::Void backgroundWorker1_DoWork_1(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e)
  256. {
  257. while (sysActive)
  258. {
  259. if (backgroundWorker1->CancellationPending) //if it was cancelled
  260. {
  261. e->Cancel = true;
  262. break;
  263. }
  264. if (!sysActive) //if the progress bar value reached maximum
  265. {
  266. break;
  267. }
  268.  
  269. int data = runPing();
  270. //backgroundWorker1->ReportProgress(0, Convert::ToString(data));
  271. backgroundWorker1->ReportProgress(0,data.ToString());
  272. Sleep(1000);
  273. }
  274. }
  275. void backgroundWorker1_ProgressChanged(Object^ sender,ProgressChangedEventArgs^ e)
  276. {
  277. auto textData = e->UserState;
  278. pingOutbox->Text = textData.ToString();
  279.  
  280.  
  281. // Not necessary. The UI will update itself if the main thread is responding.
  282. pingOutbox->Refresh();
  283. cout << "MEEP" << endl;
  284. }
  285. };
  286. }
Add Comment
Please, Sign In to add comment