Hilfe wie kann man in c++ einen taschenrechner in MFC und dazu eine Stopp Uhr machen ??

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Hab mal schnell was Just4Fun zussamengeschrieben.
    Gibt die verstrichene Zeit seit dem letzten Aufruf der Funktion in Microsekunden zurück.
    (Die verwendeten Funktionen sind Hardware abhängig und von daher unterschiedlich genau und unter umständen auch gar nicht verfügbar)

    Quellcode

    1. #include <windows.h>
    2. ...
    3. double GetPerformanceMicroTime()
    4. {
    5. static LARGE_INTEGER lastcall = {0};
    6. static LARGE_INTEGER frequency = {0};
    7. if (!frequency.QuadPart)
    8. QueryPerformanceFrequency(&frequency);
    9. LARGE_INTEGER currcall, diff;
    10. QueryPerformanceCounter(&currcall);
    11. diff.QuadPart = currcall.QuadPart - lastcall.QuadPart;
    12. lastcall = currcall;
    13. return double(diff.QuadPart)*1000000.0/double(frequency.QuadPart);
    14. }
    Alles anzeigen


    Beispiel:

    Quellcode

    1. GetPerformanceMicroTime();
    2. Sleep(1);
    3. ...
    4. double time = GetPerformanceMicroTime();
    5. ...


    Mfg Rushh0ur
  • ich geb jetzt mal ne eher unkonventionelle lösung:

    Du schreibst dir dein eigenes Mini-OS
    dort kannst du den PIT (Programmierbarer Interval Timer) selbst einstellen.
    Damit kannst du schonmal wesentlich kleinere Abtastraten machen
    Daher du dann Programme auch in Mono-Tasking machen kannst stresst schonmal das Hin- und herwechseln der Tasks nicht, was ja auch Zeit braucht.
    Dann speichert du die Zeit wie es grad ist, machst die Berechnung sagen wir mal 100.000 mal, schaust dir die Zeit nochmal an und teilst die differenz durch 100.000
    Ich behaupte mal genauer wirst du es an einem x86_* nicht bekommen. Ist aber keine sehr leichte Aufgabe, aber definitiv in 1-2 Tagen schaffbar wenn man ETWAS erfahrung in C (ohne ++) hat.
  • Danke an euch aber leider weiß ich nicht wie man die eigentlich macht ich hab halt den Taschenrechner selbst in c++ geschrieben in Windows form und wollte nur wissen wie man die stopp Uhr in den Taschenrechner einprogrammiert und nicht irgendwie mit Mini-OS was das auch immer ist?? Aber danke die Antwort pocky.
    Kann man das nicht einfacher programmieren ??
    Und wie kann man das von Rushh0ur einprogrammieren ???
    Könnte jemand bitte helfen??
  • Hi
    ich hab mal den ganzen code von Form1.h
    so meine frage ist kann man das nicht mit QueryPerformanceCounter machen ??
    Wo müsste ich es hier in den code einfügen wenn es gehen würde ??

    Quellcode

    1. #pragma once
    2. namespace CCalculator {
    3. using namespace System;
    4. using namespace System::ComponentModel;
    5. using namespace System::Collections;
    6. using namespace System::Windows::Forms;
    7. using namespace System::Data;
    8. using namespace System::Drawing;
    9. using namespace System::Diagnostics;
    10. /// <summary>
    11. /// Summary for Form1
    12. ///
    13. /// WARNING: If you change the name of this class, you will need to change the
    14. /// 'Resource File Name' property for the managed resource compiler tool
    15. /// associated with all .resx files this class depends on. Otherwise,
    16. /// the designers will not be able to interact properly with localized
    17. /// resources associated with this form.
    18. /// </summary>
    19. public ref class Form1 : public System::Windows::Forms::Form
    20. {
    21. public:
    22. Form1(void)
    23. {
    24. InitializeComponent();
    25. //
    26. //TODO: Add the constructor code here
    27. //
    28. }
    29. protected:
    30. /// <summary>
    31. /// Clean up any resources being used.
    32. /// </summary>
    33. ~Form1()
    34. {
    35. if (components)
    36. {
    37. delete components;
    38. }
    39. }
    40. private: System::Windows::Forms::Button^ button1;
    41. protected:
    42. private: System::Windows::Forms::TextBox^ textBox1;
    43. private: System::Windows::Forms::TextBox^ textBox2;
    44. private: System::Windows::Forms::Label^ label1;
    45. private: System::Windows::Forms::TextBox^ textBox3;
    46. private: System::Windows::Forms::TextBox^ textBox4;
    47. private: System::Windows::Forms::Label^ label2;
    48. private: System::Windows::Forms::Button^ button2;
    49. private: System::Windows::Forms::TextBox^ textBox5;
    50. private: System::Windows::Forms::TextBox^ textBox6;
    51. private: System::Windows::Forms::Label^ label3;
    52. private: System::Windows::Forms::Button^ button3;
    53. private: System::Windows::Forms::Button^ button4;
    54. private: System::Windows::Forms::TextBox^ textBox7;
    55. private: System::Windows::Forms::TextBox^ textBox8;
    56. private: System::Windows::Forms::Label^ label4;
    57. private:
    58. /// <summary>
    59. /// Required designer variable.
    60. /// </summary>
    61. System::ComponentModel::Container ^components;
    62. #pragma region Windows Form Designer generated code
    63. /// <summary>
    64. /// Required method for Designer support - do not modify
    65. /// the contents of this method with the code editor.
    66. /// </summary>
    67. void InitializeComponent(void)
    68. {
    69. this->button1 = (gcnew System::Windows::Forms::Button());
    70. this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    71. this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    72. this->label1 = (gcnew System::Windows::Forms::Label());
    73. this->textBox3 = (gcnew System::Windows::Forms::TextBox());
    74. this->textBox4 = (gcnew System::Windows::Forms::TextBox());
    75. this->label2 = (gcnew System::Windows::Forms::Label());
    76. this->button2 = (gcnew System::Windows::Forms::Button());
    77. this->textBox5 = (gcnew System::Windows::Forms::TextBox());
    78. this->textBox6 = (gcnew System::Windows::Forms::TextBox());
    79. this->label3 = (gcnew System::Windows::Forms::Label());
    80. this->button3 = (gcnew System::Windows::Forms::Button());
    81. this->button4 = (gcnew System::Windows::Forms::Button());
    82. this->textBox7 = (gcnew System::Windows::Forms::TextBox());
    83. this->textBox8 = (gcnew System::Windows::Forms::TextBox());
    84. this->label4 = (gcnew System::Windows::Forms::Label());
    85. this->SuspendLayout();
    86. //
    87. // button1
    88. //
    89. this->button1->Location = System::Drawing::Point(251, 10);
    90. this->button1->Name = L"button1";
    91. this->button1->Size = System::Drawing::Size(139, 23);
    92. this->button1->TabIndex = 0;
    93. this->button1->Text = L"Ergebnis";
    94. this->button1->UseVisualStyleBackColor = true;
    95. this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    96. //
    97. // textBox1
    98. //
    99. this->textBox1->Location = System::Drawing::Point(13, 12);
    100. this->textBox1->Name = L"textBox1";
    101. this->textBox1->Size = System::Drawing::Size(100, 20);
    102. this->textBox1->TabIndex = 1;
    103. //
    104. // textBox2
    105. //
    106. this->textBox2->Location = System::Drawing::Point(140, 12);
    107. this->textBox2->Name = L"textBox2";
    108. this->textBox2->Size = System::Drawing::Size(100, 20);
    109. this->textBox2->TabIndex = 2;
    110. //
    111. // label1
    112. //
    113. this->label1->AutoSize = true;
    114. this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 10.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
    115. static_cast<System::Byte>(0)));
    116. this->label1->Location = System::Drawing::Point(120, 15);
    117. this->label1->Name = L"label1";
    118. this->label1->Size = System::Drawing::Size(17, 17);
    119. this->label1->TabIndex = 3;
    120. this->label1->Text = L"X";
    121. this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
    122. //
    123. // textBox3
    124. //
    125. this->textBox3->Location = System::Drawing::Point(13, 65);
    126. this->textBox3->Name = L"textBox3";
    127. this->textBox3->Size = System::Drawing::Size(100, 20);
    128. this->textBox3->TabIndex = 4;
    129. //
    130. // textBox4
    131. //
    132. this->textBox4->Location = System::Drawing::Point(140, 65);
    133. this->textBox4->Name = L"textBox4";
    134. this->textBox4->Size = System::Drawing::Size(100, 20);
    135. this->textBox4->TabIndex = 5;
    136. //
    137. // label2
    138. //
    139. this->label2->AutoSize = true;
    140. this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
    141. static_cast<System::Byte>(0)));
    142. this->label2->Location = System::Drawing::Point(117, 61);
    143. this->label2->Name = L"label2";
    144. this->label2->Size = System::Drawing::Size(23, 31);
    145. this->label2->TabIndex = 6;
    146. this->label2->Text = L"-";
    147. //
    148. // button2
    149. //
    150. this->button2->Location = System::Drawing::Point(251, 61);
    151. this->button2->Name = L"button2";
    152. this->button2->Size = System::Drawing::Size(139, 23);
    153. this->button2->TabIndex = 7;
    154. this->button2->Text = L"Ergebnis";
    155. this->button2->UseVisualStyleBackColor = true;
    156. this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
    157. //
    158. // textBox5
    159. //
    160. this->textBox5->Location = System::Drawing::Point(13, 122);
    161. this->textBox5->Name = L"textBox5";
    162. this->textBox5->Size = System::Drawing::Size(100, 20);
    163. this->textBox5->TabIndex = 8;
    164. //
    165. // textBox6
    166. //
    167. this->textBox6->Location = System::Drawing::Point(140, 121);
    168. this->textBox6->Name = L"textBox6";
    169. this->textBox6->Size = System::Drawing::Size(100, 20);
    170. this->textBox6->TabIndex = 9;
    171. //
    172. // label3
    173. //
    174. this->label3->AutoSize = true;
    175. this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
    176. static_cast<System::Byte>(0)));
    177. this->label3->Location = System::Drawing::Point(116, 121);
    178. this->label3->Name = L"label3";
    179. this->label3->Size = System::Drawing::Size(24, 25);
    180. this->label3->TabIndex = 10;
    181. this->label3->Text = L"÷";
    182. //
    183. // button3
    184. //
    185. this->button3->Location = System::Drawing::Point(251, 121);
    186. this->button3->Name = L"button3";
    187. this->button3->Size = System::Drawing::Size(139, 23);
    188. this->button3->TabIndex = 11;
    189. this->button3->Text = L"Ergebnis";
    190. this->button3->UseVisualStyleBackColor = true;
    191. this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
    192. //
    193. // button4
    194. //
    195. this->button4->Location = System::Drawing::Point(251, 165);
    196. this->button4->Name = L"button4";
    197. this->button4->Size = System::Drawing::Size(139, 23);
    198. this->button4->TabIndex = 12;
    199. this->button4->Text = L"Ergebnis";
    200. this->button4->UseVisualStyleBackColor = true;
    201. this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
    202. //
    203. // textBox7
    204. //
    205. this->textBox7->Location = System::Drawing::Point(13, 170);
    206. this->textBox7->Name = L"textBox7";
    207. this->textBox7->Size = System::Drawing::Size(100, 20);
    208. this->textBox7->TabIndex = 13;
    209. //
    210. // textBox8
    211. //
    212. this->textBox8->Location = System::Drawing::Point(140, 170);
    213. this->textBox8->Name = L"textBox8";
    214. this->textBox8->Size = System::Drawing::Size(100, 20);
    215. this->textBox8->TabIndex = 14;
    216. //
    217. // label4
    218. //
    219. this->label4->AutoSize = true;
    220. this->label4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
    221. static_cast<System::Byte>(0)));
    222. this->label4->Location = System::Drawing::Point(118, 163);
    223. this->label4->Name = L"label4";
    224. this->label4->Size = System::Drawing::Size(24, 25);
    225. this->label4->TabIndex = 15;
    226. this->label4->Text = L"+";
    227. //
    228. // Form1
    229. //
    230. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    231. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    232. this->BackColor = System::Drawing::Color::White;
    233. this->ClientSize = System::Drawing::Size(402, 245);
    234. this->Controls->Add(this->label4);
    235. this->Controls->Add(this->textBox8);
    236. this->Controls->Add(this->textBox7);
    237. this->Controls->Add(this->button4);
    238. this->Controls->Add(this->button3);
    239. this->Controls->Add(this->label3);
    240. this->Controls->Add(this->textBox6);
    241. this->Controls->Add(this->textBox5);
    242. this->Controls->Add(this->button2);
    243. this->Controls->Add(this->label2);
    244. this->Controls->Add(this->textBox4);
    245. this->Controls->Add(this->textBox3);
    246. this->Controls->Add(this->label1);
    247. this->Controls->Add(this->textBox2);
    248. this->Controls->Add(this->textBox1);
    249. this->Controls->Add(this->button1);
    250. this->Name = L"Form1";
    251. this->Text = L"Taschenrechner";
    252. this->ResumeLayout(false);
    253. this->PerformLayout();
    254. }
    255. #pragma endregion
    256. private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    257. float a, b;
    258. if (float::TryParse(textBox1->Text, a) && float::TryParse(textBox2->Text, b))
    259. MessageBox::Show((a * b).ToString());
    260. }
    261. private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
    262. }
    263. private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
    264. float a, b;
    265. if (float::TryParse(textBox3->Text, a) && float::TryParse(textBox4->Text, b))
    266. MessageBox::Show((a - b).ToString());
    267. }
    268. private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
    269. float a, b;
    270. if (float::TryParse(textBox5->Text, a) && float::TryParse(textBox6->Text, b))
    271. MessageBox::Show((a / b).ToString());
    272. }
    273. private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
    274. float a, b;
    275. if (float::TryParse(textBox7->Text, a) && float::TryParse(textBox8->Text, b))
    276. MessageBox::Show((a + b).ToString());
    277. }
    278. };
    279. }
    Alles anzeigen
  • Pseudo:

    Quellcode

    1. #include <Windows.h>
    2. ...
    3. unsigned int beginTime = ::GetTickCount();
    4. ...Deine If-Bedingung...
    5. unsigned int endTime = ::GetTickCount();
    6. TotalTime = endTime-beginTime;
    7. ...


    Zum Ausgeben irgendwo ein Label und da den Text entfernen. Diesen dann nach der Berechnung von TotalTime den eigentlichen Sinn des Labels geben, den Text und zwar TotalTime nach LWSTR konvertieren und dann ausgeben. So würde ich das tun.

    MfG
    Check

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Checkmateing ()

  • Kann mir jemand sagen wo man den

    Quellcode

    1. #include <Windows.h>
    2. ...
    3. unsigned int beginTime = ::GetTickCount();
    4. ...Deine If-Bedingung...
    5. unsigned int endTime = ::GetTickCount();
    6. TotalTime = endTime-beginTime;
    7. ...


    einfügen muss bitte?? Ich hab keine Ahnung wo ich das einfügen muss in meine taschenrechner????