Тема: Windows form C++/CLI Будильник
Допоможіть будь ласка пофіксити помилки
переписав програму, перечитав декілька разів текст
і не знаю як виправити ці помилки.
1.Не найдено визначення для функції "PlaySound".Музику з розширенням .wav помістив в папку Debug
2.занадто багато аргументів в виклику Функції.
пишу програму в IDE Vs 2017.
#pragma once
namespace Project4 {
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>
/// Сводка для MyForm14
/// </summary>
// Функция PlaySound, обеспечивающая воспроизведение wav-файлов,
// находится в библиотеке winmm.dll.
// Подключим эту библиотеку.
[System::Runtime::InteropServices::DllImport("winmm.dll")]
extern
bool PlaySound(String^ lpszName, int hModule, int dwFlags);
public ref class MyForm14 : public System::Windows::Forms::Form
{
public:
MyForm14(void)
{
InitializeComponent();
// настройка компонентов numericUpDown
numericUpDown1->Maximum = 23;
numericUpDown1->Minimum = 0;
numericUpDown2->Maximum = 59;
numericUpDown2->Minimum = 0;
numericUpDown1->Value = DateTime::Now.Hour;
numericUpDown2->Value = DateTime::Now.Minute + 5;
notifyIcon1->Visible = false;
isSet = false;
// настройка и запуск таймера
timer1->Interval = 1000;
timer1->Enabled = true;
label4->Text = DateTime::Now.ToLongTimeString();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~MyForm14()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Timer^ timer1;
protected:
private: System::Windows::Forms::ContextMenuStrip^ contextMenuStrip1;
private: System::Windows::Forms::NotifyIcon^ notifyIcon1;
private: System::Windows::Forms::GroupBox^ groupBox1;
private: System::Windows::Forms::CheckBox^ checkBox1;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::NumericUpDown^ numericUpDown1;
private: System::Windows::Forms::NumericUpDown^ numericUpDown2;
private: System::ComponentModel::IContainer^ components;
private: DateTime alarm; // время сигнала (отображения сообщения)
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::ToolStripMenuItem^ toolStripMenuItem1;
private: System::Windows::Forms::ToolStripMenuItem^ toolStripMenuItem2;
private: System::Windows::Forms::ToolStripMenuItem^ toolStripMenuItem3;
bool isSet; // true — будильник установлен (работает)
private:
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm14::typeid));
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->contextMenuStrip1 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
this->notifyIcon1 = (gcnew System::Windows::Forms::NotifyIcon(this->components));
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->numericUpDown1 = (gcnew System::Windows::Forms::NumericUpDown());
this->numericUpDown2 = (gcnew System::Windows::Forms::NumericUpDown());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->toolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripMenuItem2 = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripMenuItem3 = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->contextMenuStrip1->SuspendLayout();
this->groupBox1->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown2))->BeginInit();
this->SuspendLayout();
//
// timer1
//
this->timer1->Enabled = true;
this->timer1->Interval = 1000;
this->timer1->Tick += gcnew System::EventHandler(this, &MyForm14::timer1_Tick);
//
// contextMenuStrip1
//
this->contextMenuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {
this->toolStripMenuItem1,
this->toolStripMenuItem2, this->toolStripMenuItem3
});
this->contextMenuStrip1->Name = L"contextMenuStrip1";
this->contextMenuStrip1->Size = System::Drawing::Size(155, 70);
//
// notifyIcon1
//
this->notifyIcon1->ContextMenuStrip = this->contextMenuStrip1;
this->notifyIcon1->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"notifyIcon1.Icon")));
this->notifyIcon1->Text = L"notifyIcon1";
this->notifyIcon1->Click += gcnew System::EventHandler(this, &MyForm14::notifyIcon1_Click);
//
// groupBox1
//
this->groupBox1->Controls->Add(this->numericUpDown1);
this->groupBox1->Controls->Add(this->numericUpDown2);
this->groupBox1->Controls->Add(this->textBox1);
this->groupBox1->Controls->Add(this->label2);
this->groupBox1->Controls->Add(this->checkBox1);
this->groupBox1->Controls->Add(this->label1);
this->groupBox1->Location = System::Drawing::Point(12, 88);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::Drawing::Size(469, 200);
this->groupBox1->TabIndex = 1;
this->groupBox1->TabStop = false;
this->groupBox1->Text = L"Нагадування";
//
// numericUpDown1
//
this->numericUpDown1->Location = System::Drawing::Point(9, 116);
this->numericUpDown1->Name = L"numericUpDown1";
this->numericUpDown1->Size = System::Drawing::Size(42, 20);
this->numericUpDown1->TabIndex = 2;
//
// numericUpDown2
//
this->numericUpDown2->Location = System::Drawing::Point(105, 116);
this->numericUpDown2->Name = L"numericUpDown2";
this->numericUpDown2->Size = System::Drawing::Size(44, 20);
this->numericUpDown2->TabIndex = 3;
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(7, 151);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(427, 20);
this->textBox1->TabIndex = 1;
this->textBox1->Text = L"Не забуть...";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(155, 118);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(50, 13);
this->label2->TabIndex = 4;
this->label2->Text = L"Хвилина";
//
// checkBox1
//
this->checkBox1->AutoSize = true;
this->checkBox1->Location = System::Drawing::Point(7, 177);
this->checkBox1->Name = L"checkBox1";
this->checkBox1->Size = System::Drawing::Size(44, 17);
this->checkBox1->TabIndex = 0;
this->checkBox1->Text = L"звv";
this->checkBox1->UseVisualStyleBackColor = true;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(57, 118);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(43, 13);
this->label1->TabIndex = 3;
this->label1->Text = L"Година";
//
// button1
//
this->button1->Location = System::Drawing::Point(12, 294);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 2;
this->button1->Text = L"OK";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm14::button1_Click);
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(27, 33);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(38, 13);
this->label3->TabIndex = 5;
this->label3->Text = L"Зараз";
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(86, 33);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(35, 13);
this->label4->TabIndex = 6;
this->label4->Text = L"label4";
//
// toolStripMenuItem1
//
this->toolStripMenuItem1->Name = L"toolStripMenuItem1";
this->toolStripMenuItem1->Size = System::Drawing::Size(154, 22);
this->toolStripMenuItem1->Text = L"Показати";
//
// toolStripMenuItem2
//
this->toolStripMenuItem2->Name = L"toolStripMenuItem2";
this->toolStripMenuItem2->Size = System::Drawing::Size(154, 22);
this->toolStripMenuItem2->Text = L"Про програму";
//
// toolStripMenuItem3
//
this->toolStripMenuItem3->Name = L"toolStripMenuItem3";
this->toolStripMenuItem3->Size = System::Drawing::Size(154, 22);
this->toolStripMenuItem3->Text = L"Завершити";
//
// MyForm14
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(493, 329);
this->Controls->Add(this->label4);
this->Controls->Add(this->label3);
this->Controls->Add(this->button1);
this->Controls->Add(this->groupBox1);
this->Name = L"MyForm14";
this->Text = L"MyForm14";
this->contextMenuStrip1->ResumeLayout(false);
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown2))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void notifyIcon1_Click(System::Object^ sender, System::EventArgs^ e) {
// если нет контекстного меню, то открыть окно программы можно так:
/*
isSet = false;
this->Show();
notifyIcon1->Visible = false;
*/
}
private: System::Void toolStripMenuItem1_Click(System::Object^ sender, System::EventArgs^ e) {
isSet = false;
// остановить будильник
this->Show();
notifyIcon1->Visible = false;
}
private: System::Void toolStripMenuItem2_Click(System::Object^ sender, System::EventArgs^ e){
}
private: System::Void toolStripMenuItem3_Click(System::Object^ sender, System::EventArgs^ e)
{
this->Close();
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
label4->Text = DateTime::Now.ToLongTimeString();
// будильник установлен
if (isSet)
{
// время срабатывания будильника
if (DateTime::Compare(DateTime::Now, alarm) > 0)
{
isSet = false;
if (checkBox1->Checked)
{
PlaySound(Application::StartupPath + "\\ring.wav", 0, 1);
}
MyForm14^ frm; // окно сообщения
// см. конструктор формы MyForm14
frm = gcnew MyForm14(DateTime::Now.ToShortTimeString(), this->textBox1->Text);
frm->ShowDialog(); // показать окно сообщения
this->Show();
}
}
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
// установить время сигнала
alarm = DateTime(DateTime::Now.Year,
DateTime::Now.Month,
DateTime::Now.Day,
Convert::ToInt16(numericUpDown1->Value),
Convert::ToInt16(numericUpDown2->Value),
0, 0);
// Если установленное время будильника меньше текущего,
// нужно увеличить дату срабатывания на единицу (+1 день)
if (DateTime::Compare(DateTime::Now, alarm) > 0)
alarm = alarm.AddDays(1);
// Подсказка:
// будет отображаться при позиционировании
// указателя мыши на значке программы
notifyIcon1->Text = "Будильник — " + alarm.ToShortTimeString() +
"\n" + textBox1->Text;
}
};
}
125 сторінка
https://books.google.com.ua/books?id=xk … mp;f=false