Quantcast
Channel: Error al pulsar un botón
Viewing all articles
Browse latest Browse all 6

Error al pulsar un botón

$
0
0

Hola:

Hice una aplicación gracias a los compañeros de este foro.

Está hecho con C++ CLR. En el botón abrir puse este código.

private: System::Void button_Abrir_Click(System::Object^  sender, System::EventArgs^  e) {
	label_Mensaje->Text = "Abriendo...";
	Application::DoEvents();
	mciSendString("set CDAudio door open", rt, 127, IntPtr::Zero);
	label_Mensaje->Text = "Abierto.";
}

Si ejecutas la aplicación, ejecuta bien, sin problemas. Al pulsar el botón si me sale un aviso.

¿Alguna idea?

El código completo lo dejo abajo.

#pragma once

namespace Lectordiscoscpp {

	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::Runtime::InteropServices; // No olvidar.
	using namespace System::Text;

	/// <summary>
	/// Resumen de Form_principal
	/// </summary>
	public ref class Form_principal : public System::Windows::Forms::Form
	{
	public:
		Form_principal(void)
		{
			InitializeComponent();
			//
			//TODO: agregar código de constructor aquí
			//
		}

		// ########################################################################
		[DllImport("winmm.dll")]
		Int32 mciSendString(String^ lpstrCommand, StringBuilder^ lpstrReturnString,
			int uReturnLength, IntPtr hwndCallback);

		static StringBuilder^ rt = gcnew StringBuilder(127);
		// ########################################################################

	protected:
		/// <summary>
		/// Limpiar los recursos que se estén usando.
		/// </summary>
		~Form_principal()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Label^  label_Mensaje;
	private: System::Windows::Forms::GroupBox^  groupBox_bandeja;
	private: System::Windows::Forms::Button^  button_Cerrar;
	private: System::Windows::Forms::Button^  button_Abrir;
	protected:

	protected:

	private:
		/// <summary>
		/// Variable del diseñador necesaria.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Método necesario para admitir el Diseñador. No se puede modificar
		/// el contenido de este método con el editor de código.
		/// </summary>
		void InitializeComponent(void)
		{
			this->label_Mensaje = (gcnew System::Windows::Forms::Label());
			this->groupBox_bandeja = (gcnew System::Windows::Forms::GroupBox());
			this->button_Cerrar = (gcnew System::Windows::Forms::Button());
			this->button_Abrir = (gcnew System::Windows::Forms::Button());
			this->groupBox_bandeja->SuspendLayout();
			this->SuspendLayout();
			// 
			// label_Mensaje
			// 
			this->label_Mensaje->AutoSize = true;
			this->label_Mensaje->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 36, System::Drawing::FontStyle::Bold));
			this->label_Mensaje->Location = System::Drawing::Point(12, 9);
			this->label_Mensaje->Name = L"label_Mensaje";
			this->label_Mensaje->Size = System::Drawing::Size(52, 55);
			this->label_Mensaje->TabIndex = 0;
			this->label_Mensaje->Text = L"\?";
			// 
			// groupBox_bandeja
			// 
			this->groupBox_bandeja->Controls->Add(this->button_Cerrar);
			this->groupBox_bandeja->Controls->Add(this->button_Abrir);
			this->groupBox_bandeja->Location = System::Drawing::Point(22, 118);
			this->groupBox_bandeja->Name = L"groupBox_bandeja";
			this->groupBox_bandeja->Size = System::Drawing::Size(227, 90);
			this->groupBox_bandeja->TabIndex = 1;
			this->groupBox_bandeja->TabStop = false;
			this->groupBox_bandeja->Text = L"Bandeja:";
			// 
			// button_Cerrar
			// 
			this->button_Cerrar->Location = System::Drawing::Point(126, 38);
			this->button_Cerrar->Name = L"button_Cerrar";
			this->button_Cerrar->Size = System::Drawing::Size(75, 23);
			this->button_Cerrar->TabIndex = 1;
			this->button_Cerrar->Text = L"&Cerrar";
			this->button_Cerrar->UseVisualStyleBackColor = true;
			this->button_Cerrar->Click += gcnew System::EventHandler(this, &Form_principal::button_Cerrar_Click);
			// 
			// button_Abrir
			// 
			this->button_Abrir->Location = System::Drawing::Point(24, 38);
			this->button_Abrir->Name = L"button_Abrir";
			this->button_Abrir->Size = System::Drawing::Size(75, 23);
			this->button_Abrir->TabIndex = 0;
			this->button_Abrir->Text = L"&Abrir";
			this->button_Abrir->UseVisualStyleBackColor = true;
			this->button_Abrir->Click += gcnew System::EventHandler(this, &Form_principal::button_Abrir_Click);
			// 
			// Form_principal
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 261);
			this->Controls->Add(this->groupBox_bandeja);
			this->Controls->Add(this->label_Mensaje);
			this->Name = L"Form_principal";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"Control lector disco C++ CLR";
			this->groupBox_bandeja->ResumeLayout(false);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
private: System::Void button_Abrir_Click(System::Object^  sender, System::EventArgs^  e) {
	label_Mensaje->Text = "Abriendo...";
	Application::DoEvents();
	mciSendString("set CDAudio door open", rt, 127, IntPtr::Zero);
	label_Mensaje->Text = "Abierto.";
}
private: System::Void button_Cerrar_Click(System::Object^  sender, System::EventArgs^  e) {
	label_Mensaje->Text = "Cerrando...";
	Application::DoEvents();
	mciSendString("set CDAudio door closed", rt, 127, IntPtr::Zero);
	label_Mensaje->Text = "Cerrado.";
}
};
}

Saludos.


http://electronica-pic.blogspot.com


Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images