STDMETHODIMP CFlash::Play(BSTR bstrFile, long hInstance, long hWnd)
{
// TODO: Add your implementation code here
try
{
m_hWnd=(HWND)hWnd;
_bstr_t file(bstrFile);
m_hWnd=::MCIWndCreate((HWND)hWnd,(HINSTANCE)hInstance,WS_POPUP|WS_VISIBLE|MCIWNDF_NOPLAYBAR|MCIWNDF_NOMENU,(char*)file);
RECT rect;
::GetWindowRect(m_hWnd,&rect);
int sx,sy;
sx=(::GetSystemMetrics(SM_CXSCREEN)-rect.right+rect.left)/2;
sy=(::GetSystemMetrics(SM_CYSCREEN) -rect.bottom+rect.top)/2;
::SetWindowPos(m_hWnd,HWND_TOPMOST,sx,sy,0,0,SWP_SHOWWINDOW|SWP_NOSIZE);
g_nLength=MCIWndGetLength(m_hWnd);
MCIWndPlay(m_hWnd);
SetTimer(m_hWnd,1,50,TimerProc);
// m_hWnd=::M
}
catch (...)
{
AtlTrace("error:%ul",::GetLastError());
}
return S_OK;
}
void CALLBACK CFlash::TimerProc(HWND hwnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime // current system time
)
{
long nLength;
BOOL bEscape=::GetKeyState(VK_ESCAPE)&0x0100;
nLength=MCIWndGetPosition(hwnd);
//视频放完,或点击ESC键,关闭视频窗口
if((nLength>=g_nLength)||(bEscape))
{
KillTimer(hwnd,idEvent);
MCIWndEnd(hwnd);
MCIWndClose(hwnd);
MCIWndDestroy(hwnd);
}
}
出现错误:error C2664: SetTimer : cannot convert parameter 4 from void (struct HWND__ *,unsigned int,unsigned int,unsigned long) to void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)
None of the functions with this name in scope match the target type
请问各位怎么修改?
回调函数必须为静态函数或者全局函数
这里放在类中,就只能用静态成员函数了,你的是吗?
如果是类成员函数,那么这个回调函数必须是静态的;一般都把回调函数定义为全局的。类的成员函数是根据类对象的偏移类确定其地址的,你把你的回调函数定义类成员,这样是无法确定函数地址的。
SetTimer(hwnd,ID_TIME,100,(TIMERPROC)TimerProc); 应该这样设定
VOID CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
你的TimerProc函数没有使用CFlash的非静态成员,可以把TimerProc函数申明为静态函数就可以了
up
回调函数一定要是静态或全局的