Hilfe wie kann man in c++ einen taschenrechner in MFC und dazu eine Stopp Uhr machen ??
-
-
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
- #include <windows.h>
- ...
- double GetPerformanceMicroTime()
- {
- static LARGE_INTEGER lastcall = {0};
- static LARGE_INTEGER frequency = {0};
- if (!frequency.QuadPart)
- QueryPerformanceFrequency(&frequency);
- LARGE_INTEGER currcall, diff;
- QueryPerformanceCounter(&currcall);
- diff.QuadPart = currcall.QuadPart - lastcall.QuadPart;
- lastcall = currcall;
- return double(diff.QuadPart)*1000000.0/double(frequency.QuadPart);
- }
Beispiel:
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?? -
OS=Betriebssystem.
Du misst die Zeit die zwischen Funktionsstart und zwischen Funktionsende vergangen ist.
Also im Prinzip als Pseudo-Code:
Ich denke so ist das von Rushhour gemeint.
MfG
Check -
Hi kann mir jemand sagen wo ich windows.h herbekomme ???
-
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
- #pragma once
- namespace CCalculator {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- using namespace System::Diagnostics;
- /// <summary>
- /// Summary for Form1
- ///
- /// WARNING: If you change the name of this class, you will need to change the
- /// 'Resource File Name' property for the managed resource compiler tool
- /// associated with all .resx files this class depends on. Otherwise,
- /// the designers will not be able to interact properly with localized
- /// resources associated with this form.
- /// </summary>
- public ref class Form1 : public System::Windows::Forms::Form
- {
- public:
- Form1(void)
- {
- InitializeComponent();
- //
- //TODO: Add the constructor code here
- //
- }
- protected:
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- ~Form1()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::Button^ button1;
- protected:
- private: System::Windows::Forms::TextBox^ textBox1;
- private: System::Windows::Forms::TextBox^ textBox2;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::TextBox^ textBox3;
- private: System::Windows::Forms::TextBox^ textBox4;
- private: System::Windows::Forms::Label^ label2;
- private: System::Windows::Forms::Button^ button2;
- private: System::Windows::Forms::TextBox^ textBox5;
- private: System::Windows::Forms::TextBox^ textBox6;
- private: System::Windows::Forms::Label^ label3;
- private: System::Windows::Forms::Button^ button3;
- private: System::Windows::Forms::Button^ button4;
- private: System::Windows::Forms::TextBox^ textBox7;
- private: System::Windows::Forms::TextBox^ textBox8;
- private: System::Windows::Forms::Label^ label4;
- private:
- /// <summary>
- /// Required designer variable.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- void InitializeComponent(void)
- {
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->textBox1 = (gcnew System::Windows::Forms::TextBox());
- this->textBox2 = (gcnew System::Windows::Forms::TextBox());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->textBox3 = (gcnew System::Windows::Forms::TextBox());
- this->textBox4 = (gcnew System::Windows::Forms::TextBox());
- this->label2 = (gcnew System::Windows::Forms::Label());
- this->button2 = (gcnew System::Windows::Forms::Button());
- this->textBox5 = (gcnew System::Windows::Forms::TextBox());
- this->textBox6 = (gcnew System::Windows::Forms::TextBox());
- this->label3 = (gcnew System::Windows::Forms::Label());
- this->button3 = (gcnew System::Windows::Forms::Button());
- this->button4 = (gcnew System::Windows::Forms::Button());
- this->textBox7 = (gcnew System::Windows::Forms::TextBox());
- this->textBox8 = (gcnew System::Windows::Forms::TextBox());
- this->label4 = (gcnew System::Windows::Forms::Label());
- this->SuspendLayout();
- //
- // button1
- //
- this->button1->Location = System::Drawing::Point(251, 10);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(139, 23);
- this->button1->TabIndex = 0;
- this->button1->Text = L"Ergebnis";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
- //
- // textBox1
- //
- this->textBox1->Location = System::Drawing::Point(13, 12);
- this->textBox1->Name = L"textBox1";
- this->textBox1->Size = System::Drawing::Size(100, 20);
- this->textBox1->TabIndex = 1;
- //
- // textBox2
- //
- this->textBox2->Location = System::Drawing::Point(140, 12);
- this->textBox2->Name = L"textBox2";
- this->textBox2->Size = System::Drawing::Size(100, 20);
- this->textBox2->TabIndex = 2;
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 10.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->label1->Location = System::Drawing::Point(120, 15);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(17, 17);
- this->label1->TabIndex = 3;
- this->label1->Text = L"X";
- this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
- //
- // textBox3
- //
- this->textBox3->Location = System::Drawing::Point(13, 65);
- this->textBox3->Name = L"textBox3";
- this->textBox3->Size = System::Drawing::Size(100, 20);
- this->textBox3->TabIndex = 4;
- //
- // textBox4
- //
- this->textBox4->Location = System::Drawing::Point(140, 65);
- this->textBox4->Name = L"textBox4";
- this->textBox4->Size = System::Drawing::Size(100, 20);
- this->textBox4->TabIndex = 5;
- //
- // label2
- //
- this->label2->AutoSize = true;
- this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->label2->Location = System::Drawing::Point(117, 61);
- this->label2->Name = L"label2";
- this->label2->Size = System::Drawing::Size(23, 31);
- this->label2->TabIndex = 6;
- this->label2->Text = L"-";
- //
- // button2
- //
- this->button2->Location = System::Drawing::Point(251, 61);
- this->button2->Name = L"button2";
- this->button2->Size = System::Drawing::Size(139, 23);
- this->button2->TabIndex = 7;
- this->button2->Text = L"Ergebnis";
- this->button2->UseVisualStyleBackColor = true;
- this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
- //
- // textBox5
- //
- this->textBox5->Location = System::Drawing::Point(13, 122);
- this->textBox5->Name = L"textBox5";
- this->textBox5->Size = System::Drawing::Size(100, 20);
- this->textBox5->TabIndex = 8;
- //
- // textBox6
- //
- this->textBox6->Location = System::Drawing::Point(140, 121);
- this->textBox6->Name = L"textBox6";
- this->textBox6->Size = System::Drawing::Size(100, 20);
- this->textBox6->TabIndex = 9;
- //
- // label3
- //
- this->label3->AutoSize = true;
- this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->label3->Location = System::Drawing::Point(116, 121);
- this->label3->Name = L"label3";
- this->label3->Size = System::Drawing::Size(24, 25);
- this->label3->TabIndex = 10;
- this->label3->Text = L"÷";
- //
- // button3
- //
- this->button3->Location = System::Drawing::Point(251, 121);
- this->button3->Name = L"button3";
- this->button3->Size = System::Drawing::Size(139, 23);
- this->button3->TabIndex = 11;
- this->button3->Text = L"Ergebnis";
- this->button3->UseVisualStyleBackColor = true;
- this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
- //
- // button4
- //
- this->button4->Location = System::Drawing::Point(251, 165);
- this->button4->Name = L"button4";
- this->button4->Size = System::Drawing::Size(139, 23);
- this->button4->TabIndex = 12;
- this->button4->Text = L"Ergebnis";
- this->button4->UseVisualStyleBackColor = true;
- this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
- //
- // textBox7
- //
- this->textBox7->Location = System::Drawing::Point(13, 170);
- this->textBox7->Name = L"textBox7";
- this->textBox7->Size = System::Drawing::Size(100, 20);
- this->textBox7->TabIndex = 13;
- //
- // textBox8
- //
- this->textBox8->Location = System::Drawing::Point(140, 170);
- this->textBox8->Name = L"textBox8";
- this->textBox8->Size = System::Drawing::Size(100, 20);
- this->textBox8->TabIndex = 14;
- //
- // label4
- //
- this->label4->AutoSize = true;
- this->label4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->label4->Location = System::Drawing::Point(118, 163);
- this->label4->Name = L"label4";
- this->label4->Size = System::Drawing::Size(24, 25);
- this->label4->TabIndex = 15;
- this->label4->Text = L"+";
- //
- // Form1
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->BackColor = System::Drawing::Color::White;
- this->ClientSize = System::Drawing::Size(402, 245);
- this->Controls->Add(this->label4);
- this->Controls->Add(this->textBox8);
- this->Controls->Add(this->textBox7);
- this->Controls->Add(this->button4);
- this->Controls->Add(this->button3);
- this->Controls->Add(this->label3);
- this->Controls->Add(this->textBox6);
- this->Controls->Add(this->textBox5);
- this->Controls->Add(this->button2);
- this->Controls->Add(this->label2);
- this->Controls->Add(this->textBox4);
- this->Controls->Add(this->textBox3);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->textBox2);
- this->Controls->Add(this->textBox1);
- this->Controls->Add(this->button1);
- this->Name = L"Form1";
- this->Text = L"Taschenrechner";
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- float a, b;
- if (float::TryParse(textBox1->Text, a) && float::TryParse(textBox2->Text, b))
- MessageBox::Show((a * b).ToString());
- }
- private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
- float a, b;
- if (float::TryParse(textBox3->Text, a) && float::TryParse(textBox4->Text, b))
- MessageBox::Show((a - b).ToString());
- }
- private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
- float a, b;
- if (float::TryParse(textBox5->Text, a) && float::TryParse(textBox6->Text, b))
- MessageBox::Show((a / b).ToString());
- }
- private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
- float a, b;
- if (float::TryParse(textBox7->Text, a) && float::TryParse(textBox8->Text, b))
- MessageBox::Show((a + b).ToString());
- }
- };
- }
-
Ist die weg oder was? Dann lade es dir runter.
Falls nicht solltest du dich nicht an Mikrosekunden wagen, wenn überhaupt.
MfG
Check
EDIT: Vor und nach den if-Bedingungen. -
Leider geht der link nicht.
-
Jetzt schon.
MfG
Check -
thx
-
Hi
Es kann auch in Millisec. gehen .
Vielleicht hat da ja jemand eine Idee. -
Pseudo:
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
CheckDieser Beitrag wurde bereits 1 mal editiert, zuletzt von Checkmateing ()
-
Hi danke für deine Antwort werde es gleich ausprobieren .
-
Hi kannst du mir mal ein Beispiel geben damit ich es auch verstehe ??
Wäre nett. -
Was fehlt dir denn? Offensichtlicher geht es kaum ohne den ganzen Code zu posten.
MfG
Check -
Könntes du mir sagen wo ich es einfügen muss bitte??
-
Wo genau liegt das Problem?
Die Windows-Header-Datei solltest du schon im System haben.
Was für Fehler kommt wenn du die Datei einbindest, an welcher stelle bindest du diese ein?
Mfg Rushh0ur -
Kann mir jemand sagen wo man den
einfügen muss bitte?? Ich hab keine Ahnung wo ich das einfügen muss in meine taschenrechner???? -
Ich habe es deutlich genug dargestellt!
MfG
Check