CDドアの開閉(U)          <TOP>


mciSendCommand 指定されたMCI(メディアコントロールインターフェイス)デバイスへ、コマンドメッセージを送信
 

 
'================================================================
'= CDドアの開閉(U)
'=    (mciSendCommand.bas)
'================================================================
#include "Windows.bi"

#define MCI_OPEN &H803                  'デバイスまたはデバイス要素を初期化する
#define MCI_OPEN_TYPE &H2000            'lpParamパラメータに指定する構造体のlpstrDeviceTypeメンバを有効にする
#define MCI_OPEN_SHAREABLE &H100        'デバイスまたはファイルを共有可能としてオープン
#define MCI_SET &H80D                   'デバイス情報を設定する
#define MCI_SET_DOOR_OPEN &H100         'メディアトレイをオープン
#define MCI_SET_DOOR_CLOSED &H200       'メディアトレイをクローズ
#define MCI_CLOSE &H804                 'デバイスまたはデバイス要素へのアクセスを解放する

Type MCI_OPEN_PARMS
    dwCallback       As Long
    wDeviceID        As Long
    lpstrDeviceType  As Long
    lpstrElementName As Long
    lpstrAlias       As Long
End Type

' 指定されたMCI(メディアコントロールインターフェイス)デバイスへ、コマンドメッセージを送信
Declare Function Api_mciSendCommand& Lib "winmm" Alias "mciSendCommandA" (ByVal IDDevice&, ByVal uMsg&, ByVal fdwCommand&, ByRef dwParam As Any)

Var Shared Picture1 As Object
Var Shared Button1 As Object
Var Shared Button2 As Object
Var Shared Bitmap As Object

Picture1.Attach GetDlgItem("Picture1")
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14
Button2.Attach GetDlgItem("Button2") : Button2.SetFontSize 14
BitmapObject Bitmap

Var Shared mop As MCI_OPEN_PARMS
Var Shared flg As Integer

'================================================================
'=
'================================================================
Declare Sub OpenClose ()
Sub OpenClose()
    If flg = 0 Then
        Bitmap.LoadFile "PC1.bmp"
    Else
        Bitmap.LoadFile "PC2.bmp"
    End If
    Picture1.DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject
End Sub

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    flg = 0
    OpenClose
End Sub

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var Ret As Long

    flg = 1
    OpenClose

    '構造体初期化
    mop.wDeviceID = 0
    mop.lpstrDeviceType = StrAdr("cdaudio" & Chr$(0))

    'ID取得
    Ret = Api_mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_SHAREABLE, mop)

    'CD-ROMドアオープン
    Ret = Api_mciSendCommand(mop.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, ByVal 0)

    '解放
    Ret = Api_mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, ByVal 0)
End Sub

'================================================================
'=
'================================================================
Declare Sub Button2_on edecl ()
Sub Button2_on()
    Var Ret As Long

    flg = 0
    OpenClose

    '構造体初期化
    mop.wDeviceID = 0
    mop.lpstrDeviceType = StrAdr("cdaudio" & Chr$(0))

    'ID取得
    Ret = Api_mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_SHAREABLE, mop)

    'CD-ROMドアクローズ
    Ret = Api_mciSendCommand(mop.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, ByVal 0)

    '解放
    Ret = Api_mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, ByVal 0)
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End