#define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
# include <conio.h>
# include <windows.h>
# include <stdlib.h>
# include <string.h>
# include <io.h>
# include <errno.h>
# pragma comment (lib , "WINMM.LIB")
void Error (MCIERROR err)
{
char buf[260];
mciGetErrorStringA (err , buf , sizeof (buf));
printf ("\t%d\t%s\n " , err , buf);
}
void SetDown (void)
{
// Simulate a key press
keybd_event( VK_DOWN,
0x5000,
KEYEVENTF_EXTENDEDKEY,
0 );
// Simulate a key release
keybd_event( VK_DOWN,
0x5000,
KEYEVENTF_KEYUP,
0);
}
void GetFileName (char *FilePath , char * FileNameExtension)
{
FILE * fp = fopen ("MusicName.txt" , "w+");
if (!fp)
return ;
_finddata_t Info;
char cmd[MAX_PATH];
sprintf (cmd , "%s%s" , FilePath , FileNameExtension);
long hFind;
hFind = _findfirst (cmd , &Info);
fputs (Info.name , fp);
if (hFind == -1)
{
puts ("失败");
return ;
}
while (!_findnext (hFind , &Info))
{
fputs ("\n" , fp);
puts (Info.name);
fputs (Info.name , fp);
}
fputs ("\n" , fp);
fclose (fp);
_findclose (hFind);
}
void MciFunction (char *FilePath , char *FileName)
{
//
char FileName[260];
char cmd[260];
MCIDEVICEID dev = 0;
MCI_OPEN_PARMSA open;
DWORD err;
MCI_PLAY_PARMS play;
MCI_BREAK_PARMS br;
//
while (fgets (FileName , 260 , fp) != NULL)
//
{
//
open.lpstrAlias = "mysong";
play.dwCallback = NULL;
play.dwFrom = 0;
br.nVirtKey = VK_DOWN;
br.hwndBreak = NULL;
br.dwCallback = NULL;
FileName[strlen (FileName) - 1] = '\0';
sprintf (cmd , "%s%s" , FilePath , FileName);
open.lpstrDeviceType = NULL;
open.lpstrElementName = cmd;
printf ("%s\n" , cmd);
err = mciSendCommandA (NULL , MCI_OPEN ,
MCI_OPEN_ELEMENT | MCI_WAIT | MCI_OPEN_SHAREABLE , (DWORD)(PVOID)&open);
if (err)
{
Error (err);
return;
}
dev = open.wDeviceID;
//
MCI_STATUS_PARMS status;
//
status.dwItem = MCI_STATUS_POSITION;
err = mciSendCommand (dev , MCI_BREAK , MCI_BREAK_KEY ,(DWORD)(PVOID)&br);
if (err)
{
Error (err);
return;
}
err = mciSendCommand (dev , MCI_PLAY , MCI_WAIT , (DWORD)(PVOID)&play );
SetDown ();
Sleep (1000);
if (err)
{
Error (err);
return;
}
//
mciSendCommand (dev , MCI_STATUS , MCI_STATUS_ITEM , (DWORD)(PVOID)&status);
//
printf ("%d\n" , status.dwReturn);
MCI_GENERIC_PARMS close;
close.dwCallback = NULL;
mciSendCommand (dev , MCI_CLOSE , 0 , (DWORD)(PVOID)&close);
//}
}
int main (void)
{
char FilePath[MAX_PATH] = "C:\\Users\\yutang\\Desktop\\music\\";
char FileNameExtension[32] = "*.mp3";
//
gets (FilePath);
//
gets (FileNameExtension);
char FileName[260];
FILE *fp = fopen ("MusicName.txt" , "r");
if (!fp)
return 0;
GetFileName (FilePath , FileNameExtension);
while (fgets (FileName , 260 , fp) != 0)
{
MciFunction (FilePath , FileName);
}
fclose (fp);
return 0;
}
我加了一个函数,void SetDown (void),有那么一点意思了,但还是有些问题。总是隔一首播放一首,不知道是怎么回事。
MCI_BREAK_HWND 这个句柄是怎么来的,怎么获取这个参数啊 。
我在上面查了下,HWND
hwndBreak 只是介绍了这个成员代表了什么,但是怎么获取,怎么用就不知道了。
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
[此贴子已经被作者于2017-10-23 03:04编辑过]