Где находится основной цикл программы Windows Forms CLR c++
Мне нужно создать небольшое десктоп приложение на c++. Написал программу, используя Windows Forms. Проблема заключается в том, что мне нужно анализировать клавиши, нажимаемые пользователем в процессе работы (а точнее при нажатии esc должна выполнятся функция ClearAll(), а при Enter – ShowResult), а я не знаю как.
MyForm.h
#pragma once
#include <cmath>
#include <conio.h>
#include <stdlib.h>
const double PI = 3.141592653589793;
namespace ADMCalc {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Сводка для MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
protected:
private:
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(118, 91);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(19, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"d1";
this->label1->Click += gcnew System::EventHandler(this, &MyForm::label1_Click);
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(118, 143);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(19, 13);
this->label2->TabIndex = 1;
this->label2->Text = L"d2";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(143, 88);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(150, 20);
this->textBox1->TabIndex = 2;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(143, 136);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(150, 20);
this->textBox2->TabIndex = 3;
this->textBox2->TextChanged += gcnew System::EventHandler(this, &MyForm::textBox2_TextChanged);
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(380, 88);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::Drawing::Size(150, 20);
this->textBox3->TabIndex = 4;
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(362, 95);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(19, 13);
this->label3->TabIndex = 5;
this->label3->Text = L"Δx";
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(362, 143);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(19, 13);
this->label4->TabIndex = 7;
this->label4->Text = L"Δz";
//
// textBox4
//
this->textBox4->Location = System::Drawing::Point(380, 136);
this->textBox4->Name = L"textBox4";
this->textBox4->Size = System::Drawing::Size(150, 20);
this->textBox4->TabIndex = 6;
//
// button1
//
this->button1->Location = System::Drawing::Point(204, 257);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(107, 40);
this->button1->TabIndex = 8;
this->button1->Text = L"Enter";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(343, 257);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(107, 40);
this->button2->TabIndex = 9;
this->button2->Text = L"Clear";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(668, 390);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->label4);
this->Controls->Add(this->textBox4);
this->Controls->Add(this->label3);
this->Controls->Add(this->textBox3);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Name = L"MyForm";
this->Text = L"ADM";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
bool protect() {
if ((textBox1->Text->Length == 0) || (textBox2->Text->Length == 0)) return false;
for (int i = 0; i < textBox1->Text->Length; i++)
if (!(('0' <= textBox1->Text[i]) && ('9' >= textBox1->Text[i]) || (textBox1->Text[i] == '-') || (textBox1->Text[i] == ','))) return false;
for (int i = 0; i < textBox2->Text->Length; i++)
if (!(('0' <= textBox2->Text[i]) && ('9' >= textBox2->Text[i]) || (textBox2->Text[i] == '-') || (textBox2->Text[i] == ','))) return false;
return true;
}
void ClearAll() {
textBox1->Text = "";
textBox2->Text = "";
textBox3->Text = "";
textBox4->Text = "";
}
void ShowAll() {
double d1, d2, dx, dz, sinn, coss;
d1 = System::Convert::ToDouble(textBox1->Text);
d2 = System::Convert::ToDouble(textBox2->Text);
sinn = sin(20 * PI / 180);
coss = cos(20 * PI / 180);
dx = (d2 - d1) / (2 * sinn);
dz = (d2 + d1) / (2 * (coss - 1));
textBox3->Text = System::Convert::ToString(dx);
textBox4->Text = System::Convert::ToString(dz);
}
private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if (protect()) ShowAll();
else MessageBox::Show("Ошибка ввода", "Ошибка");
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
ClearAll();
}
private: System::Void textBox2_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
};
}
MyForm.cpp
#include "MyForm.h"
#include <Windows.h>
using namespace ADMCalc
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew MyForm);
return 0;
}
Где находится основной цикл выполнения программы и можно ли его изменять(добавить анализ клавиш)? Или мне нужно вообще не так делать? В таком случае, скажите, пожалуйста, где и что почитать, чтобы понять что и как делать.
