Control bandeja
Publicado por Meta (14 intervenciones) el 16/11/2017 01:49:49
Hola:
Hice en C#, C++ CLR y VB .net este formulario para abrir y cerrar la bandeja de discos sea IDE o SATA.

Quiero hacer lo mismo para Dephi Tokyo 10.2.
Así sigo haciendo cositas con Delphi y no dejarlo en el limbo. Quiero traducir de C# a Delphi o hacer lo mismo, es decir, que se pueda abrir y cerrar la bandeja del lector. Seguiré haciendo documentos o tutoriales para Delphi tal como se ha hecho antes.
Código C#:

Con Delphi acabo de lograr abrir y cerrar la bandeja. Cuando pulso el botón de Abrir, aparec elmensaje diciendo Abierto. La idea en el momento que está abriendo la bandeja del disco, aparezca el m ensaje "Abriendo...", cuando ya esté del toto abierto, aque aparezca el mensaje "Abierto.". Tal como si lo hace en C# arriba.
¿Cómo se hace en Delphi?
Dejo el código abajo de Delphi pero no muestra los mensajes "Abirendo..." y "Cerrando...".
Código Delphi:
Un cordial saludos.
Hice en C#, C++ CLR y VB .net este formulario para abrir y cerrar la bandeja de discos sea IDE o SATA.
Quiero hacer lo mismo para Dephi Tokyo 10.2.
Así sigo haciendo cositas con Delphi y no dejarlo en el limbo. Quiero traducir de C# a Delphi o hacer lo mismo, es decir, que se pueda abrir y cerrar la bandeja del lector. Seguiré haciendo documentos o tutoriales para Delphi tal como se ha hecho antes.
Código C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Runtime.InteropServices; // No olvidar.
using System.Text;
using System.Windows.Forms;
namespace Lector_discos_cs
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("winmm.dll")]
public static extern Int32 mciSendString(string lpstrCommand, StringBuilder lpstrReturnString,
int uReturnLength, IntPtr hwndCallback);
StringBuilder rt = new StringBuilder(127);
private void button_Abrir_Click(object sender, EventArgs e)
{
label_Mensaje.Text = "Abriendo...";
Application.DoEvents();
mciSendString("set CDAudio door open", rt, 127, IntPtr.Zero);
label_Mensaje.Text = "Abierto.";
}
private void button_Cerrar_Click(object sender, EventArgs e)
{
label_Mensaje.Text = "Cerrando...";
Application.DoEvents();
mciSendString("set CDAudio door closed", rt, 127, IntPtr.Zero);
label_Mensaje.Text = "Cerrado.";
}
}
}
Con Delphi acabo de lograr abrir y cerrar la bandeja. Cuando pulso el botón de Abrir, aparec elmensaje diciendo Abierto. La idea en el momento que está abriendo la bandeja del disco, aparezca el m ensaje "Abriendo...", cuando ya esté del toto abierto, aque aparezca el mensaje "Abierto.". Tal como si lo hace en C# arriba.
¿Cómo se hace en Delphi?
Dejo el código abajo de Delphi pero no muestra los mensajes "Abirendo..." y "Cerrando...".
Código Delphi:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
unit Lector_bandeja;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, MMSystem;
// No olvidar añadir en uses MMSystem arriba.
type
TForm1 = class(TForm)
RadioGroup_Bandeja: TRadioGroup;
Button_Abrir: TButton;
Button_Cerrar: TButton;
Label_Mensaje: TLabel;
procedure Button_AbrirClick(Sender: TObject);
procedure Button_CerrarClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure OpenCd(AOpen:Boolean);
const
DoPlay : array[Boolean] of string = ('Set cdaudio door closed wait',
'Set cdaudio door open wait');
var
MyError : LongInt;
MyErrorString : array[0..MAXERRORLENGTH - 1] of char;
begin
MyError := mciSendString(pChar(DoPlay[AOpen]), nil, 0, 0);
if MyError <> 0 then
begin
MciGetErrorString(MyError,MyErrorString,MAXERRORLENGTH - 1);
Showmessage(MyErrorString);
Exit;
end;
end;
procedure TForm1.Button_AbrirClick(Sender: TObject);
begin
Label_Mensaje.Caption := 'Abriendo...';
OpenCd(TRUE);
Label_Mensaje.Caption := 'Abierto.';
end;
procedure TForm1.Button_CerrarClick(Sender: TObject);
begin
Label_Mensaje.Caption := 'Cerrando...';
OpenCd(FALSE);
Label_Mensaje.Caption := 'Cerrado.';
end;
end.
Un cordial saludos.
Valora esta pregunta


0