コード: 全て選択
'-----------------------------------------------------------------------------
' イベント プロシージャ
'-----------------------------------------------------------------------------
' このファイルには、ウィンドウ [MainWnd] に関するイベントをコーディングします。
' ウィンドウ ハンドル: hMainWnd
' TODO: この位置にグローバルな変数、構造体、定数、関数を定義します。
'CD Player,MCI Audio==================================================
Const ID_TIMER = 100
'MCI_OPEN_PARMS構造体。MCIデバイスのオープンに関する情報が格納される
Dim mop As MCI_OPEN_PARMS
'現在演奏中のトラック番号(1,2,3,...)が格納される
Dim TrackNum As Long
Function OpenMciDevice() As Long
'MCIデバイスをオープンする
'(mop.wDeviceIDにデバイスIDが格納される)
Dim dwError As DWord
Dim buffer[255] As Byte
mop.dwCallback=hMainWnd
mop.lpstrDeviceType="cdaudio"
dwError=mciSendCommand(0,MCI_OPEN,MCI_WAIT or MCI_OPEN_TYPE,mop)
If dwError Then
mciGetErrorString(dwError,buffer,255)
MessageBox(hMainWnd,buffer,"Missed to open of device.",MB_OK)
OpenMciDevice=0
Else
OpenMciDevice=1
End If
End Function
Sub CloseMciDevice()
'MCIデバイスを閉じる
Dim dwDummy As DWord
mciSendCommand(mop.wDeviceID,MCI_CLOSE,MCI_WAIT,dwDummy)
mop.wDeviceID=0
End Sub
Sub GetTrackInfo()
Dim dwError As DWord
Dim buffer[255] As Byte
Dim NumberOfTracks As Long
If mop.wDeviceID Then
'再生中のときは停止
SendMessage(hMainWnd,WM_COMMAND,CDStopButton,0)
End If
'MCIデバイスをオープン
If OpenMciDevice()=0 Then Exit Sub
'トラック数を取得(取得したトラック数はNumberOfTracks変数にコピーする)
Dim msp As MCI_STATUS_PARMS
msp.dwItem=MCI_STATUS_NUMBER_OF_TRACKS
dwError=mciSendCommand(mop.wDeviceID,MCI_STATUS,MCI_STATUS_ITEM,msp)
If dwError Then
mciGetErrorString(dwError,buffer,255)
MessageBox(hMainWnd,buffer,"Missed to get of tracks info.",MB_OK)
'MCIデバイスを閉じる
CloseMciDevice()
Exit Sub
End If
NumberOfTracks=msp.dwReturn
'--------------------------------------
' リストボックスにトラック情報をセット
'--------------------------------------
Dim i As Long
Dim hList As DWord
hList=GetDlgItem(hMainWnd,TrackList)
'時刻形式にMFSを指定
Dim msep As MCI_SET_PARMS
msep.dwTimeFormat = MCI_FORMAT_MSF
mciSendCommand(mop.wDeviceID,MCI_SET,MCI_SET_TIME_FORMAT,msep)
'リストボックスの内容をリセット
SendMessage(hList,LB_RESETCONTENT,0,0)
For i=1 To NumberOfTracks
'トラック情報を取得する
msp.dwItem=MCI_STATUS_LENGTH
msp.dwTrack=i
mciSendCommand(mop.wDeviceID,MCI_STATUS,MCI_STATUS_ITEM or MCI_TRACK,msp)
'トラック情報を文字列に変換
wsprintf(buffer,"Track%02d - %02d:%02d",i,MCI_MSF_MINUTE(msp.dwReturn),MCI_MSF_SECOND(msp.dwReturn))
'リストボックスに追加
SendMessage(hList,LB_ADDSTRING,0,buffer)
Next
'MCIデバイスを閉じる
CloseMciDevice()
'再生ボタンを有効化し、一時停止・停止ボタンを無効化する
EnableWindow(GetDlgItem(hMainWnd,CDPlayButton),1)
EnableWindow(GetDlgItem(hMainWnd,CDPauseButton),0)
EnableWindow(GetDlgItem(hMainWnd,CDStopButton),0)
End Sub
'=====================================================================
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (lpstrCommand As BytePtr,lpstrReturnString As BytePtr,uReturnLength As DWord,hwndCallback As DWord) As DWord
declare function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes as VoidPtr, bInitialOwner as long, lpName as String) as long
declare function timeSetEvent Lib "winmm" (uDelay as DWord,uResolution as DWord,lpTimeProc as DWord,dwUser as DWordPtr,fuEvent as DWord) as DWord
declare function timeKillEvent Lib "winmm" (uTimerID as DWord) as DWord
dim uTimer as DWord
'SetWndCenter Function================================================
function SetWndCenter(hWnd as long,ByRef cpos as POINTAPI) as long
dim AppWnd as RECT
dim width as long,hight as long
GetWindowRect(hWnd,AppWnd)
with AppWnd
width=(.right - .left)
hight=(.bottom - .top)
.left=cpos.x - width/2
.top=cpos.y - hight/2
if .left<0 then .left=0
if .top<0 then .top=0
SetWndCenter=MoveWindow(hWnd,.left,.top,width,hight,TRUE)
End With
End Function
dim DeskTopCenter as POINTAPI
'=====================================================================
'Status Bar===========================================================
const ID_STATUS = 70
dim hStatusWnd as DWord
'=====================================================================
'MCI Video============================================================
Dim vop As MCI_DGV_OPEN_PARMS
Dim vpp AS MCI_DGV_PLAY_PARMS
Dim msp As MCI_SEEK_PARMS
Dim buffer[100] As Byte
Dim bErr As Long
Dim d As Long
d=0
Type MCI_DGV_OPEN_PARMS
dwCallback As DWord
wDeviceID As DWord
lpstrDeviceType As BytePtr
lpstrElementName As BytePtr
lpstrAlias As BytePtr
dwStyle As DWord
hWndParent As DWord
End Type
TYPE MCI_DGV_PLAY_PARMS
dwCallback As DWord
dwFrom As DWord
dwTo As DWord
dwSpeed As DWord
End Type
'=====================================================================
'-----------------------------------------------------------------------------
' ウィンドウメッセージを処理するためのコールバック関数
Function MainWndProc(hWnd As DWord, dwMsg As DWord, wParam As DWord, lParam As DWord) As DWord
' TODO: この位置にウィンドウメッセージを処理するためのコードを記述します。
dim mmi as *MINMAXINFO
select case dwMsg
case WM_GETMINMAXINFO
mmi=lParam
mmi->ptMinTrackSize.x=408
mmi->ptMinTrackSize.y=440
mmi->ptMaxTrackSize.x=408
mmi->ptMaxTrackSize.y=440
End Select
' イベントプロシージャの呼び出しを行います。
MainWndProc=EventCall_MainWnd(hWnd,dwMsg,wParam,lParam)
End Function
function TimeProc(uID as DWord,uMsg as DWord,dwUser as DWord,dw1 as DWord,dw2 as DWord) as DWord
uTimerID=timeSetEvent(100,0,AddressOf(TimeProc),0,1)
timeKillEvent(uTimerID)
End Function
'-----------------------------------------------------------------------------
' ここから下は、イベントプロシージャを記述するための領域になります。
Sub MainWnd_Destroy()
dim IsTopMost as long
if SendMessage(GetDlgItem(hMainWnd,CheckBox1),BM_GETCHECK,0,0) then
IsTopMost=1
Else
IsTopMost=0
End If
MCIPlayer_DestroyObjects()
PostQuitMessage(0)
End Sub
Sub MainWnd_Create(ByRef CreateStruct As CREATESTRUCT)
GetTrackInfo()
Dim rect As RECT
SystemParametersInfo(SPI_GETWORKAREA,0,VarPtr(rect),0)
With DeskTopCenter
.x = (rect.left + rect.right)/2
.y = (rect.top + rect.bottom)/2
Dim buf As String
buf=ZeroString(40)
wsprintf(buf,"xc=%4d, yc=%4d", .x, .y)
End With
If SetWndCenter(hMainWnd, DeskTopCenter) = FALSE Then
MessageBox(hMainWnd,"Missed to move.","erorr",MB_OK)
End If
dim IsTopMost as long
if IsTopMost then
SendDlgItemMessage(hMainWnd,CheckBox1,BM_SETCHECK,BST_CHECKED,0)
SetWindowPos(hMainWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE)
End If
dim ic as INITCOMMONCONTROLSEX
dim Statusbar_Sizes[1] as long
ic.dwSize=Len(ic)
ic.dwICC=ICC_BAR_CLASSES
InitCommonControlsEx(ic)
hStatusWnd=CreateStatusWindow(WS_CHILD or WS_VISIBLE or CCS_BOTTOM,_
NULL,hMainWnd,ID_STATUS)
Statusbar_Sizes[0]=204
Statusbar_Sizes[1]=408
SendMessage(hStatusWnd,SB_SETPARTS,2,Statusbar_Sizes)
SetTimer(hMainWnd,0,100,NULL)
End Sub
Sub MainWnd_ReloadButton_Click()
GetTrackInfo()
SetWindowText(hMainWnd,"MCI Audio Player")
End Sub
Sub MainWnd_EjectButton_Click()
If mop.wDeviceID Then
SendMessage(hMainWnd,WM_COMMAND,CDStopButton,0)
End If
If OpenMciDevice()=0 Then Exit Sub
mciSendCommand(mop.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, ByVal NULL)
CloseMciDevice()
EnableWindow(GetDlgItem(hMainWnd,CDPlayButton),0)
EnableWindow(GetDlgItem(hMainWnd,CDPauseButton),0)
EnableWindow(GetDlgItem(hMainWnd,CDStopButton),0)
End Sub
Sub MainWnd_CDPlayButton_Click()
SetWindowText(hMainWnd,"You pushed play button of Audio CD.")
Dim dwError As DWord
Dim buffer[255] As Byte
Dim msep As MCI_SET_PARMS
Dim mpp As MCI_PLAY_PARMS
Dim dwParms As DWord
If mop.wDeviceID=0 Then
TrackNum=SendDlgItemMessage(hMainWnd,TrackList,LB_GETCURSEL,0,0)
If TrackNum=LB_ERR Then Exit Sub
TrackNum=TrackNum+1
If OpenMciDevice()=0 Then Exit Sub
msep.dwTimeFormat = MCI_FORMAT_MSF
mciSendCommand(mop.wDeviceID,MCI_SET,MCI_SET_TIME_FORMAT,msep)
Dim msp As MCI_STATUS_PARMS
msp.dwItem=MCI_STATUS_LENGTH
msp.dwTrack=TrackNum
mciSendCommand(mop.wDeviceID,MCI_STATUS,MCI_STATUS_ITEM or MCI_TRACK,msp)
Dim nMax As Integer
Dim hTrackBar As DWord
hTrackBar=GetDlgItem(hMainWnd,TrackBar1)
nMax=(MCI_MSF_MINUTE(msp.dwReturn)*60 + MCI_MSF_SECOND(msp.dwReturn)) * 10
SendMessage(hTrackBar,TBM_SETRANGE,0,MAKELONG(0,nMax))
SendMessage(hTrackBar,TBM_SETPOS,1,0)
msep.dwTimeFormat = MCI_FORMAT_TMSF
mciSendCommand(mop.wDeviceID,MCI_SET,MCI_SET_TIME_FORMAT,msep)
mpp.dwCallback=hMainWnd
mpp.dwFrom=MCI_MAKE_TMSF(TrackNum,0,0,0)
if TrackNum=SendDlgItemMessage(hMainWnd,TrackList,LB_GETCOUNT,0,0) then
dwParms=MCI_FROM or MCI_NOTIFY
dim ReturnString[1024] As Byte
mciSendString("open cdaudio alias cda",ReturnString,1024,NULL)
mciSendString("set cda time format tmsf",ReturnString,1024,NULL)
mciSendString("play cda from SelectedTrack to LastTrack",ReturnString,1024,NULL)
Else
mpp.dwTo=MCI_MAKE_TMSF(TrackNum+1,0,0,0)
dwParms=MCI_FROM or MCI_TO or MCI_NOTIFY
mciSendString("stop cda",ReturnString,1024,NULL)
mciSendString("close cda",ReturnString,1024,NULL)
End If
dwError=mciSendCommand(mop.wDeviceID,MCI_PLAY,dwParms,mpp)
Else
mpp.dwCallback=hMainWnd
If TrackNum=SendDlgItemMessage(hMainWnd,TrackList,LB_GETCOUNT,0,0) Then
dwParms=MCI_NOTIFY
Else
mpp.dwTo=MCI_MAKE_TMSF(TrackNum+1,0,0,0)
dwParms=MCI_TO or MCI_NOTIFY
End If
dwError=mciSendCommand(mop.wDeviceID,MCI_PLAY,dwParms,mpp)
End If
If dwError Then
mciGetErrorString(dwError,buffer,255)
MessageBox(hMainWnd,buffer,"Missed to play of device.",MB_OK)
CloseMciDevice()
Exit Sub
End If
EnableWindow(GetDlgItem(hMainWnd,CDPlayButton),0)
EnableWindow(GetDlgItem(hMainWnd,CDPauseButton),1)
EnableWindow(GetDlgItem(hMainWnd,CDStopButton),1)
SetTimer(hMainWnd,ID_TIMER,100,0)
SetWindowText(hMainWnd,"MCI Audio Player")
End Sub
Sub MainWnd_CDPauseButton_Click()
mciSendCommand(mop.wDeviceID,MCI_PAUSE,0,ByVal 0)
EnableWindow(GetDlgItem(hMainWnd,CDPlayButton),1)
EnableWindow(GetDlgItem(hMainWnd,CDPauseButton),0)
EnableWindow(GetDlgItem(hMainWnd,CDStopButton),1)
SetWindowText(hMainWnd,"Audio CD is pausing now.")
KillTimer(hMainWnd,ID_TIMER)
End Sub
Sub MainWnd_CDStopButton_Click()
SetWindowText(hMainWnd,"You pushed stop button of Audio CD")
Dim bErr As Long
Dim dwCallback As DWord
bErr=mciSendCommand(mop.wDeviceID,MCI_STOP,MCI_WAIT,dwCallback)
If bErr Then
MessageBox(hMainWnd,"Missed to stop of device.","error",MB_OK)
Exit Sub
End If
CloseMciDevice()
EnableWindow(GetDlgItem(hMainWnd,CDPlayButton),1)
EnableWindow(GetDlgItem(hMainWnd,CDPauseButton),0)
EnableWindow(GetDlgItem(hMainWnd,CDStopButton),0)
KillTimer(hMainWnd,ID_TIMER)
SendMessage(GetDlgItem(hMainWnd,TrackBar1),TBM_SETPOS,1,0)
SetWindowText(hMainWnd,"MCI Audio Player")
End Sub
Sub MainWnd_MciNotify(flags As Long, DevID As Long)
If flags=MCI_NOTIFY_SUCCESSFUL Then
SendMessage(hMainWnd,WM_COMMAND,CDStopButton,0)
End If
Dim dwCallback As DWord
If flags=MCI_NOTIFY_SUCCESSFUL Then
mciSendCommand(DevID,MCI_CLOSE,MCI_WAIT,dwCallback)
mop.wDeviceID=0
End If
End Sub
Sub MainWnd_HScroll(nScrollCode As Long, nPos As Integer, hwndScrollBar As Long)
Dim sw As Long
If mop.wDeviceID<>0 and _
hwndScrollBar=GetDlgItem(hMainWnd,TrackBar1) and _
(nScrollCode=SB_ENDSCROLL or _
nScrollCode=SB_LEFT or _
nScrollCode=SB_RIGHT or _
nScrollCode=SB_LINELEFT or _
nScrollCode=SB_LINERIGHT or _
nScrollCode=SB_PAGELEFT or _
nScrollCode=SB_PAGERIGHT or _
nScrollCode=SB_THUMBPOSITION)Then
If IsWindowEnabled(GetDlgItem(hMainWnd,CDPlayButton))=0 Then
SendMessage(hMainWnd,WM_COMMAND,CDPauseButton,0)
sw=1
Else
sw=0
End If
Dim msep As MCI_SET_PARMS
msep.dwTimeFormat = MCI_FORMAT_TMSF
mciSendCommand(mop.wDeviceID,MCI_SET,MCI_SET_TIME_FORMAT,msep)
Dim bErr As Long
Dim mciSeekParms As MCI_SEEK_PARMS
Dim pos As Long
pos=SendMessage(GetDlgItem(hMainWnd,TrackBar1),TBM_GETPOS,0,0)\10
mciSeekParms.dwTo=MCI_MAKE_TMSF(TrackNum, pos\60, pos mod 60,0)
bErr=mciSendCommand(mop.wDeviceID,MCI_SEEK,MCI_TO,mciSeekParms)
If bErr Then
MessageBox(hMainWnd,"Missed to seek.","error",MB_OK)
Exit Sub
End If
If sw Then
SendMessage(hMainWnd,WM_COMMAND,CDPlayButton,0)
End If
End If
End Sub
Sub MainWnd_Timer(TimerID As Long)
Dim hTrackBar As DWord
Dim pos As Long
If TimerID=ID_TIMER Then
hTrackBar=GetDlgItem(hMainWnd,TrackBar1)
pos=SendMessage(hTrackBar,TBM_GETPOS,0,0)
pos=pos+1
SendMessage(hTrackBar,TBM_SETPOS,1,pos)
End If
dim buffer[225] as Byte
dim template[225] as Byte
GetDateFormat(LOCALE_USER_DEFAULT,DATE_LONGDATE,ByVal 0,0,buffer,225)
SendMessage(hStatusWnd,SB_SETTEXT,0,buffer)
lstrcpy(template,"HH : mm : ss")
GetTimeFormat(LOCALE_USER_DEFAULT,NULL,ByVal 0,template,buffer,225)
SendMessage(hStatusWnd,SB_SETTEXT,1,buffer)
End Sub
Sub MainWnd_OpenButton_Click()
dim ofn as OPENFILENAME
dim buffer[MAX_PATH-1] as Byte
dim hFile as long
dim dwFileSize as DWord
dim dwAccessByte as DWord
ofn.lStructSize=76
ofn.hwndOwner=hMainWnd
ofn.lpstrFilter=Ex"Wave Sound (*.wav)\0*.wav\0Windows Media Audio (*.wma)\0*.wma\0MPEG audio layer 3 (*.mp3)\0*.mp3\0MIDI Sequence (*.mid)\0*.mid\0ビデオファイル(*.avi;*.wmv;*.mpg)\0*.avi;*.wmv;*.mpg\0All Files (*.*)\0*\0\0"
ofn.nFilterIndex=1
ofn.nMaxFile=MAX_PATH
ofn.lpstrFile=buffer
GetOpenFileName(ofn)
SetWindowText(GetDlgItem(hMainWnd,PathBox),ofn.lpstrFile)
With vop
.dwCallback = hVideoPlayer
.lpstrElementName=buffer
.dwStyle = WS_CHILD
.hWndParent = hMainWnd
End With
bErr = mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT or _
MCI_DGV_OPEN_PARENT or MCI_DGV_OPEN_WS, vop)
End Sub
Sub MainWnd_ResetButton_Click()
dim hEdit as long
dim buf as String
hEdit=GetDlgItem(hMainWnd,PathBox)
SetWindowText(hEdit,"")
SetWindowText(hMainWnd,"MCI Audio Player")
End Sub
Sub MainWnd_MCIPlayButton_Click()
SetWindowText(hMainWnd,"You pushed play button of MCI")
Dim bErr As Long
Dim mpp As MCI_PLAY_PARMS
Dim buffer[MAX_PATH-1] As Byte
If mop.wDeviceID Then MainWnd_MCIStopButton_Click()
mop.lpstrElementName=buffer
GetWindowText(GetDlgItem(hMainWnd,PathBox),mop.lpstrElementName,260)
mop.dwCallback=hMainWnd
bErr=mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT,mop)
If bErr Then
MessageBox(hMainWnd,"Missed to open of device.","error",MB_OK)
Exit Sub
End If
if mpp.dwCallback=hMainWnd then
bErr=mciSendCommand(mop.wDeviceID,MCI_PLAY,MCI_NOTIFY,mpp)
Else
'MCI Video============================================================
msp.dwTo=0
bErr = mciSendCommand(vop.wDeviceID,MCI_PLAY,0,vpp)
dim ret as long
ret=DialogBox(hMainWnd,"VideoPlayer")
'=====================================================================
End If
If bErr Then
MessageBox(hMainWnd,"Missed to play of device.","error",MB_OK)
Exit Sub
End If
'MCI Video============================================================
InvalidateRect(hMainWnd,ByVal 0,0)
'=====================================================================
SetWindowText(hMainWnd,"MCI Audio Player")
End Sub
Sub MainWnd_MCIStopButton_Click()
SetWindowText(hMainWnd,"You pushed stop button of MCI")
Dim bErr As Long
Dim dwCallback As DWord
bErr=mciSendCommand(mop.wDeviceID,MCI_STOP,MCI_WAIT,dwCallback)
If bErr Then
MessageBox(hMainWnd,"Missed to stop of device.","error",MB_OK)
Exit Sub
End If
mciSendCommand(mop.wDeviceID,MCI_CLOSE,MCI_WAIT,dwCallback)
mop.wDeviceID=0
bErr=mciSendCommand(vop.wDeviceID,MCI_STOP,0,d)
SetWindowText(hMainWnd,"MCI Audio Player")
End Sub
Sub MainWnd_IDM_CDPLAY_MenuClick()
MainWnd_CDPlayButton_Click()
End Sub
Sub MainWnd_IDM_CDPAUSE_MenuClick()
MainWnd_CDPauseButton_Click()
End Sub
Sub MainWnd_IDM_CDSTOP_MenuClick()
MainWnd_CDStopButton_Click()
End Sub
Sub MainWnd_IDM_MCIPLAY_MenuClick()
MainWnd_MCIPlayButton_Click()
End Sub
Sub MainWnd_IDM_MCISTOP_MenuClick()
MainWnd_MCIStopButton_Click()
End Sub
Sub MainWnd_IDM_ABOUT_MenuClick()
ShellAbout(hMainWnd,"MCI Player Ver4.00","Masaki Sanjo (M.S.)",LoadIcon(GetModuleHandle(0),101))
End Sub
Sub MainWnd_IDM_EJECT_MenuClick()
MainWnd_EjectButton_Click()
End Sub
Sub MainWnd_IDM_OPEN_MenuClick()
MainWnd_OpenButton_Click()
End Sub
Sub MainWnd_IDM_RESET_MenuClick()
MainWnd_ResetButton_Click()
End Sub
Sub MainWnd_IDM_EXIT_MenuClick()
SendMessage(hMainWnd,WM_CLOSE,0,0)
End Sub
Sub MainWnd_IDM_RELOAD_MenuClick()
MainWnd_ReloadButton_Click()
End Sub
CreateMutex(0,0,"MCI Audio Player")
if GetLastError()=183 then
MsgBox 0,"This program can not start up double.","error",MB_ICONEXCLAMATION
End
End If
Sub MainWnd_IDM_READMEE_MenuClick()
Exec "ReadMe_E.txt"
End Sub
Sub MainWnd_IDM_READMEJ_MenuClick()
exec "ReadMe_J.txt"
End Sub
Sub MainWnd_KeyDown(KeyCode As Long, flags As Long)
select case KeyCode
CASE VK_F1:
MainWnd_ReloadButton_Click()
CASE VK_F3:
MainWnd_EjectButton_Click()
CASE VK_F5:
MainWnd_OpenButton_Click()
CASE VK_F7:
MainWnd_ResetButton_Click()
End Select
End Sub
Sub MainWnd_CheckBox1_Click()
if SendMessage(GetDlgItem(hMainWnd,CheckBox1),BM_GETCHECK,0,0) then
SetWindowPos(hMainWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE)
Else
SetWindowPos(hMainWnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE)
End If
End Sub
Sub MainWnd_IDM_SW_MenuClick()
exec "SystemWatcher.exe"
End Sub
Sub MainWnd_Resize(SizeType As Long, cx As Integer, cy As Integer)
SendMessage(hStatusWnd,WM_SIZE,cx,cy)
End Sub