C#中调用WIN32 API实现对光驱的操作

Q:C#中调用WIN32 API实现对光驱的操作
A:
using System;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
class CDRomControler:Form
{
[DllImport( "winmm.dll", EntryPoint="mciSendStringA", CharSet=CharSet.Ansi )]
public static extern int mciSendString( string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, IntPtr hwndCallback );
private Button openButton;
private Button closeButton;
public CDRomControler()
{
this.AutoScaleBaseSize=new Size(5,13);
this.ClientSize=new Size(400,200);
this.Text="C#操作光驱";

this.openButton=new Button();
openButton.Location=new Point(50,100);
openButton.Size=new Size(100,20);
openButton.TabIndex=1;
openButton.Anchor=AnchorStyles.Bottom|AnchorStyles.Left;
openButton.Text="打开光驱";
openButton.Click+=new EventHandler(this.openButton_Click);
this.Controls.Add(this.openButton);

this.closeButton=new Button();
closeButton.Location=new Point(250,100);
closeButton.Size=new Size(100,20);
closeButton.TabIndex=2;
closeButton.Anchor=AnchorStyles.Bottom|AnchorStyles.Right;
closeButton.Text="关闭光驱";
closeButton.Click+=new EventHandler(this.closeButton_Click);
this.Controls.Add(this.closeButton);
}

private void openButton_Click(object sender, System.EventArgs e)
{
int ret = mciSendString( "set cdaudio door open", null, 0, IntPtr.Zero );
}

private void closeButton_Click(object sender, System.EventArgs e)
{
int ret = mciSendString( "set cdaudio door closed", null, 0, IntPtr.Zero );
}
public static void Main()
{
Application.Run(new CDRomControler()); ;
}
}

转载于:https://www.cnblogs.com/leewy/archive/2004/10/14/52298.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值