谁曾遇到媒体播放时系统时钟变慢? 如何用MciSendCommand()?

zbw123 2000-05-24 01:03:00
我在用bc++50编成时,用WINDOWS API 的mciSendMessage()函数播放声音文件,当连续播放运行几个小时后,系统时钟慢了几分钟,请问各位VC高手是否遇到过?如何解决或实现?

--------------------------------------------------------------------------------
...全文
147 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zwjmouse 2001-09-09
  • 打赏
  • 举报
回复
你好,我并没有能力解决你的问题,你这是唯一一条用到mcisendcommand 命令的帖子,想来你是高手,我是想问问你,如果我用这条命令播放AVI 时,如何全屏显示。

谢谢 我的EMAIL nzsd@sina.com
  • 打赏
  • 举报
回复
gz
zbw123 2001-08-15
  • 打赏
  • 举报
回复
我在等着高手解决
zbw123 2001-08-10
  • 打赏
  • 举报
回复
我在等着高手解决!
zbw123 2000-06-02
  • 打赏
  • 举报
回复
给出程序清单,大家帮我看一下,谢谢了!
// Borland C++ - (C) Copyright 1992 by Borland International

//*******************************************************************
//
// program - sounder.c
// purpose - a C windows program to demonstrate sound APIs.
//
//*******************************************************************

#define STRICT

#include <windows.h>
#pragma hdrstop
#include <mmsystem.h>
#include <windowsx.h>
#include <time.h>
#include "sounder.h"

// data initialized by first instance
typedef struct tagSETUPDATA
{
char szAppName[20]; // name of application
} SETUPDATA;

SETUPDATA SetUpData;

// Data that can be referenced throughout the
// program but not passed to other instances

HANDLE hInst; // hInstance of application
HWND hWndMain; // hWnd of main window
char szAppName[10]; // name of application
int SayIP, SayTotal; //发声句柄
int biao=0;
// function prototypes

int PASCAL WinMain(HINSTANCE,HINSTANCE,LPSTR,int);
void InitSound(HINSTANCE,HINSTANCE,LPSTR,int);
void InitSoundFirst(HINSTANCE);
void InitSoundEvery(HINSTANCE,int);
LRESULT CALLBACK _export SounderWndProc(HWND,UINT,WPARAM,LPARAM);
void SoundPaint(HWND);

//*******************************************************************
// WinMain - sounder main
//
// paramaters:
// hInstance - The instance of this instance of this
// application.
// hPrevInstance - The instance of the previous instance
// of this application. This will be 0
// if this is the first instance.
// lpszCmdLine - A long pointer to the command line that
// started this application.
// cmdShow - Indicates how the window is to be shown
// initially. ie. SW_SHOWNORMAL, SW_HIDE,
// SW_MIMIMIZE.
//
// returns:
// wParam from last message.
//
//*******************************************************************
int PASCAL WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
int cmdShow)
{
MSG msg;

// Go init this application.
InitSound(hInstance, hPrevInstance, lpszCmdLine, cmdShow);

// Get and dispatch messages for this applicaton.
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return(msg.wParam);
}

#if !defined(__WIN32__)
//*******************************************************************
// InitSoundAdded - done only for added instances of Sound
//
// paramaters:
// hPrevInstance - The instance of the previous instance
// of this application.
//
//*******************************************************************
void InitSoundAdded(
HINSTANCE hPrevInstance)
{
// get the results of the initialization of first instance
GetInstanceData(hPrevInstance, (BYTE*)&SetUpData, sizeof(SETUPDATA));
}
#endif

//*******************************************************************
// InitSound - init the Sound application
//
// paramaters:
// hInstance - The instance of this instance of this
// application.
// hPrevInstance - The instance of the previous instance
// of this application. This will be 0
// if this is the first instance.
// lpszCmdLine - A long pointer to the command line that
// started this application.
// cmdShow - Indicates how the window is to be shown
// initially. ie. SW_SHOWNORMAL, SW_HIDE,
// SW_MIMIMIZE.
//
//*******************************************************************
#pragma argsused
void InitSound(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
int cmdShow)
{
#if defined(__WIN32__)
InitSoundFirst(hInstance);

#else
if (! hPrevInstance) // if no previous instance, this is first
InitSoundFirst(hInstance);
else
InitSoundAdded(hPrevInstance); // this is not first instance
#endif

InitSoundEvery(hInstance, cmdShow); // initialization for all instances
}

//*******************************************************************
// InitSoundFirst - done only for first instance of Sounder
//
// paramaters:
// hInstance - The instance of this instance of this
// application.
//
//*******************************************************************
void InitSoundFirst(
HINSTANCE hInstance)
{
WNDCLASS wcSoundClass;

// Get string from resource with application name.
LoadString(hInstance, IDS_NAME, (LPSTR) SetUpData.szAppName, 10);

// Define the window class for this application.
wcSoundClass.lpszClassName = SetUpData.szAppName;
wcSoundClass.hInstance = hInstance;
wcSoundClass.lpfnWndProc = SounderWndProc;
wcSoundClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wcSoundClass.hIcon = LoadIcon(hInstance, SetUpData.szAppName);
wcSoundClass.lpszMenuName = NULL;
wcSoundClass.hbrBackground = GetStockObject(WHITE_BRUSH);
wcSoundClass.style = CS_HREDRAW and CS_VREDRAW;
wcSoundClass.cbClsExtra = 0;
wcSoundClass.cbWndExtra = 0;

// Register the class
RegisterClass(&wcSoundClass);
}

//*******************************************************************
// InitSoundEvery - done for every instance of Sound
//
// paramaters:
// hInstance - The instance of this instance of this
// application.
// cmdShow - Indicates how the window is to be shown
// initially. ie. SW_SHOWNORMAL, SW_HIDE,
// SW_MIMIMIZE.
//
//*******************************************************************
void InitSoundEvery(
HINSTANCE hInstance,
int cmdShow)
{
hInst = hInstance; // save for use by window procs

// Create applications main window.
hWndMain = CreateWindow(
SetUpData.szAppName, // window class name
SetUpData.szAppName, // window title
WS_OVERLAPPEDWINDOW, // type of window
100, // x window location
100, // y
450, // cx and size
250, // cy
NULL, // no parent for this window
NULL, // use the class menu
hInstance, // who created this window
NULL // no parms to pass on
);

// Update display of main window.
ShowWindow(hWndMain, cmdShow);
UpdateWindow(hWndMain);
}


//*******************************************************************
// SoundWndProc - handles messages for this application
//
// paramaters:
// hWnd - The window handle for this message
// message - The message number
// wParam - The WPARAM parmater for this message
// lParam - The LPARAM parmater for this message
//
// returns:
// depends on message.
//
//*******************************************************************
LRESULT CALLBACK _export SounderWndProc(
HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
HDC hdc;
RECT rct;
DWORD res;
static char Buffer[100], Buffer1[100];
static MCI_GENERIC_PARMS MciGenParm;
static MCI_OPEN_PARMS MciOpenParm;
static MCI_PLAY_PARMS MciPlayParm;
static UINT wDeviceID;
static UINT ntimeid;
time_t lg;
struct tm * gmt;
char szBuf[250];

switch (message)
{
case WM_CREATE:
CreateWindow ("button", "&Clear",
WS_CHILD and WS_VISIBLE and BS_PUSHBUTTON,
20, 40, 120, 30,
hWnd, (HMENU)IDBT_CLEAR, hInst, NULL);

CreateWindow ("button", "&sndSoundPlay",
WS_CHILD and WS_VISIBLE and BS_PUSHBUTTON,
20, 80, 120, 30,
hWnd, (HMENU)IDBT_SNDPLAY, hInst, NULL);

CreateWindow ("button", "Mci &Command",
WS_CHILD and WS_VISIBLE and BS_PUSHBUTTON,
20, 120, 120, 30,
hWnd, (HMENU)IDBT_MCICMD, hInst, NULL);

CreateWindow ("button", "Mci &String",
WS_CHILD and WS_VISIBLE and BS_PUSHBUTTON,
20, 160, 120, 30,
hWnd, (HMENU)IDBT_MCISTR, hInst, NULL);
ntimeid=SetTimer(hWnd,10,1000U,NULL);
return(DefWindowProc(hWnd, message, wParam, lParam));

case WM_TIMER:
hdc=GetDC(hWnd);
time(&lg);
gmt=localtime(&lg);
wsprintf(szBuf,"%02d:%02d:%02d",gmt->tm_hour,
gmt->tm_min, gmt->tm_sec);
SetBkColor(hdc,GetSysColor(COLOR_BTNFACE)); //99.2.2改背景颜色
SetTextColor(hdc,GetSysColor(COLOR_BTNTEXT));
TextOut(hdc,20,20,szBuf,8);
ReleaseDC(hWnd,hdc);
if (SayIP==SayTotal)
{
SayIP=0;
SayTotal=1;
PostMessage(hWnd,WM_COMMAND,IDBT_MCICMD,0L);
}
// return(DefWindowProc(hWnd, message, wParam, lParam));
break;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case IDBT_CLEAR:
hdc = GetDC (hWnd);
GetClientRect (hWnd, &rct);
BitBlt (hdc, 150, 40, rct.right, rct.bottom, NULL, 0, 0, WHITENESS);
TextOut (hdc, 20, 5, "Is your sound board and setup installed?", 40);
ReleaseDC (hWnd, hdc);
break;

case IDBT_SNDPLAY:
hdc = GetDC (hWnd);
TextOut (hdc, 150, 80, "API: sndPlaySound()", 19);
ReleaseDC (hWnd, hdc);
sndPlaySound ("sounder.wav", SND_SYNC);
break;

case IDBT_MCISTR:
hdc = GetDC (hWnd);
wsprintf (Buffer1, "API: mciSendString() open/play/stop/close");
TextOut (hdc, 150, 160, Buffer1, lstrlen(Buffer1));
res = mciSendString ((LPSTR)"open sounder.wav alias sounder", Buffer, 80, NULL);
if (!res)
MessageBox (hWnd, "Play", "Sounder", MB_OK);

res = mciSendString ((LPSTR)"play sounder", Buffer, 80, NULL);
if (!res)
MessageBox (hWnd, "Stop", "Sounder", MB_OK);

res = mciSendString ((LPSTR)"stop sounder", NULL, 0, NULL);
if (!res)
MessageBox (hWnd, "Close", "Sounder", MB_OK);

mciSendString ((LPSTR)"close sounder", NULL, 0, NULL);
ReleaseDC (hWnd, hdc);
break;

case IDBT_MCICMD:
MciOpenParm.dwCallback = 0L;
MciOpenParm.wDeviceID = 0;
// MciOpenParm.wReserved0 = 0; //2000.2.14
MciOpenParm.lpstrDeviceType ="waveaudio";
MciOpenParm.lpstrElementName = (LPSTR)"ten.wav";
MciOpenParm.lpstrAlias =NULL;
res = mciSendCommand (0, MCI_OPEN, MCI_OPEN_TYPE and MCI_OPEN_ELEMENT,
(DWORD)(LPMCI_OPEN_PARMS)&MciOpenParm);
if (res)
{
mciGetErrorString(res,szBuf,100);
MessageBox (NULL, szBuf, "Sounder open in say", MB_OK);
break;
}

MciPlayParm.dwCallback =(unsigned long) hWnd;
MciPlayParm.dwFrom = 0;
MciPlayParm.dwTo = 0;
wDeviceID = MciOpenParm.wDeviceID;
res = mciSendCommand (wDeviceID, MCI_PLAY, MCI_NOTIFY,
(DWORD) (LPMCI_PLAY_PARMS)&MciPlayParm);
if (res)
{
mciSendCommand(wDeviceID,MCI_CLOSE,0,NULL);
mciGetErrorString(res,szBuf,100);
MessageBox (NULL, szBuf, "Sounder play", MB_OK);
}
break;
default:
break;
}
break;
case MM_MCINOTIFY:
switch (wParam)
{
case MCI_NOTIFY_SUCCESSFUL:
break;
case MCI_NOTIFY_ABORTED:
wsprintf(szBuf,"ABORTED!");
MessageBox (NULL, szBuf, "IN MM_MCINOTIFY", MB_OK);
break;
case MCI_NOTIFY_SUPERSEDED:
wsprintf(szBuf,"SUPPERSEDED!");
MessageBox (NULL, szBuf, "IN MM_MCINOTIFY", MB_OK);
break;
case MCI_NOTIFY_FAILURE:
wsprintf(szBuf,"FAILURE!");
MessageBox (NULL, szBuf, "IN MM_MCINOTIFY", MB_OK);
break;
default:
wsprintf(szBuf,"wrong!");
MessageBox (NULL, szBuf, "IN MM_MCINOTIFY", MB_OK);
break;
};
MciGenParm.dwCallback = 0L;
res = mciSendCommand (LOWORD(lParam), MCI_STOP, MCI_WAIT,
(DWORD)(LPMCI_GENERIC_PARMS)&MciGenParm);
if (res)
{
mciGetErrorString(res,szBuf,100);
MessageBox (NULL, szBuf, "Sounder stop2", MB_OK);
}
mciSendCommand (LOWORD(lParam), MCI_CLOSE, MCI_WAIT,
(DWORD)(LPMCI_GENERIC_PARMS)&MciGenParm);
SayIP=SayTotal=0;
wDeviceID=0;
break;

case WM_DESTROY:
if (wDeviceID )
{
MciGenParm.dwCallback = 0L;
res = mciSendCommand (wDeviceID, MCI_STOP, MCI_WAIT,
(DWORD)(LPMCI_GENERIC_PARMS)&MciGenParm);
if (res)
{
mciGetErrorString(res,szBuf,100);
MessageBox (NULL, szBuf, "Sounder stop2", MB_OK);
}
mciSendCommand (wDeviceID, MCI_CLOSE, MCI_WAIT,
(DWORD)(LPMCI_GENERIC_PARMS)&MciGenParm);
}
if (ntimeid!=0) KillTimer(hWnd,ntimeid);
PostQuitMessage(0); // this is the end...
break;

case WM_CLOSE:
// Tell windows to destroy our window.
DestroyWindow(hWnd);
break;

default:
// Let windows handle all messages we choose to ignore.
return(DefWindowProc(hWnd, message, wParam, lParam));
}
return(0L);
}

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧