Hola:
Quiero adaptar este código de C++ CLR a C++ Win32. Antes que nada, quiero saber si es posible o hay que complicarse mucho la vida para hacer lo mismo. El código lo que hace es abrir y cerrar la bandeja de cualquier lector de discos sea IDE o SATA.
Código C++ CLR:
#include "stdafx.h"
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Text;
[DllImport("winmm.dll")]
extern Int32 mciSendString(String^ lpstrCommand, StringBuilder^ lpstrReturnString,
int uReturnLength, IntPtr hwndCallback);
static void DoEvents()
{
Console::SetCursorPosition(0, 6);
Console::Write("Abriendo...");
}
static void DoEvents2()
{
Console::SetCursorPosition(0, 6);
Console::Write("Cerrando...");
}
int main(array<System::String ^> ^args)
{
StringBuilder^ rt = gcnew StringBuilder(127);
// Título de la ventana.
Console::Title = "Control lector de bandeja. C++ CLR";
// Tamaño ventana consola.
Console::WindowWidth = 29; // X. Ancho.
Console::WindowHeight = 8; // Y. Alto.
// Cursor invisible.
Console::CursorVisible = false;
// Posición del mansaje en la ventana.
Console::SetCursorPosition(0, 0);
Console::WriteLine("Control bandeja del lector : \n\n" +
"A - Abrir bandeja. \n" +
"C - Cerrar bandeja. \n" +
"========================== \n");
//Console::WriteLine("A - Abrir bandeja.");
//Console::WriteLine("C - Cerrar bandeja.");
//Console::Write("==========================");
ConsoleKey key;
//Console::CursorVisible = false;
do
{
key = Console::ReadKey(true).Key;
String^ mensaje = "";
//Asignamos la tecla presionada por el usuario
switch (key)
{
case ConsoleKey::A:
mensaje = "Abriendo...";
Console::SetCursorPosition(0, 6);
DoEvents();
mciSendString("set CDAudio door open", rt, 127, IntPtr::Zero);
mensaje = "Abierto.";
break;
case ConsoleKey::C:
mensaje = "Cerrando...";
Console::SetCursorPosition(0, 6);
DoEvents2();
mciSendString("set CDAudio door closed", rt, 127, IntPtr::Zero);
mensaje = "Cerrado.";
break;
}
Console::SetCursorPosition(0, 6);
Console::Write(" ");
Console::SetCursorPosition(0, 6);
Console::Write(mensaje);
} while (key != ConsoleKey::Escape);
return 0;
}
Saludos.