C # Call Win32 API to perform operations on the optical drive

Source: Internet
Author: User

Q: C # Calls Win32 API to perform operations on the optical drive
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 # operating Optical Drive ";

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 = "enable Optical Drive ";
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 = "Disable the optical drive ";
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 ());;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.