Witam!
Niedawno zacząłem uczyć się Visual C++. Jednak jak na razie znam marne podstawy. Jest to mój drugi program w Visual C++ więc prosiłbym o pomoc. A mianowicie, chodzi mi o to aby program zamykał system po określonym czasie ( ale czas ma być stały - bez możliwości ingerencja na niego tak jak np. przy shutdown) i dobrze by było gdyby wyświetlał jakiś komunikat. Jak na razie wymyśliłem coś takiego:
#pragma once
namespace siedem {
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 for Form1
///
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
///
/// Clean up any resources being used.
///
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::CheckBox^ checkBox1;
protected:
private: System::Windows::Forms::CheckBox^ checkBox2;
private: System::Windows::Forms::CheckBox^ checkBox3;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::Button^ button5;
private:
///
/// Required designer variable.
///
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
void InitializeComponent(void)
{
this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
this->checkBox2 = (gcnew System::Windows::Forms::CheckBox());
this->checkBox3 = (gcnew System::Windows::Forms::CheckBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->button4 = (gcnew System::Windows::Forms::Button());
this->button5 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// checkBox1
//
this->checkBox1->AutoSize = true;
this->checkBox1->Location = System::Drawing::Point(26, 16);
this->checkBox1->Name = L"checkBox1";
this->checkBox1->Size = System::Drawing::Size(63, 17);
this->checkBox1->TabIndex = 0;
this->checkBox1->Text = L"Wybór1";
this->checkBox1->UseVisualStyleBackColor = true;
this->checkBox1->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox1_CheckedChanged);
//
// checkBox2
//
this->checkBox2->AutoSize = true;
this->checkBox2->Location = System::Drawing::Point(26, 52);
this->checkBox2->Name = L"checkBox2";
this->checkBox2->Size = System::Drawing::Size(63, 17);
this->checkBox2->TabIndex = 1;
this->checkBox2->Text = L"Wybór2";
this->checkBox2->UseVisualStyleBackColor = true;
//
// checkBox3
//
this->checkBox3->AutoSize = true;
this->checkBox3->Location = System::Drawing::Point(26, 90);
this->checkBox3->Name = L"checkBox3";
this->checkBox3->Size = System::Drawing::Size(63, 17);
this->checkBox3->TabIndex = 2;
this->checkBox3->Text = L"Wybór3";
this->checkBox3->UseVisualStyleBackColor = true;
//
// button1
//
this->button1->Location = System::Drawing::Point(26, 131);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 3;
this->button1->Text = L"Wybierz";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(161, 131);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 21);
this->button2->TabIndex = 4;
this->button2->Text = L"Zakończ";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// button3
//
this->button3->Location = System::Drawing::Point(161, 52);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(75, 23);
this->button3->TabIndex = 5;
this->button3->Text = L"nic";
this->button3->UseVisualStyleBackColor = true;
//
// button4
//
this->button4->Location = System::Drawing::Point(161, 16);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(75, 23);
this->button4->TabIndex = 6;
this->button4->Text = L"pokaż";
this->button4->UseVisualStyleBackColor = true;
this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
//
// button5
//
this->button5->Location = System::Drawing::Point(161, 81);
this->button5->Name = L"button5";
this->button5->Size = System::Drawing::Size(75, 35);
this->button5->TabIndex = 7;
this->button5->Text = L"Wyłącz komputer";
this->button5->UseVisualStyleBackColor = true;
this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(262, 168);
this->Controls->Add(this->button5);
this->Controls->Add(this->button4);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->checkBox3);
this->Controls->Add(this->checkBox2);
this->Controls->Add(this->checkBox1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::Fixed3D;
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"if";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
if(checkBox1->Checked==true)
{
MessageBox::Show("1 - Zaznaczone");
}
else
{
MessageBox::Show("Opcja 1 - Odznaczone");
};
if(checkBox2->Checked==true)
{
MessageBox::Show("2 - Zaznaczone");
}
else
{
MessageBox::Show("2 - Odznaczona");
};
if(checkBox3->Checked==true)
{
MessageBox::Show("3 -Zaznacozne");
}
else
{
MessageBox::Show("3 - Odznaczone");
};
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
{
Close();
}
private: System::Void progressBar1_Click(System::Object^ sender, System::EventArgs^ e)
{
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e)
{
MessageBox::Show("Nic", "Nic");
}
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e)
{
system("shutdown -s -t 300");
}
};
}
Z tym, że pojawia się błąd “error C3861: ‘system’: identifier not found”. Wydaje mi się że brakuje jakiejś biblioteki. Jednak jestem bardzo początkujący, więc zwracam się z prośba do was. W zwykłym C++ w console application to działało poprawnie jednak tutaj nie chce działać. Słyszałem też o bardziej uniwersalnej opcji “ExitWindowsEx();” jednak z nią też miałem problemy. Byłbym niezmiernie wdzięczny gdybyście pomogli mi w obu przypadkach.
Pozdrawiam,
mati199537