//Module   : WinTimer.cpp
//include  : mmsystem.h
//Import   : WinMM.lib
//
//Contents : 乽儅儖僠儊僨傿傾僞僀儅乕偺巊梡曽朄乿
//

#include <windows.h>  //Win32n API's
#include "DefOrg.h"
#include "OrgData.h"
#include "Sound.h"

//僄儔乕僠僃僢僋儅僋儘
//#define MMInspect(ret)  if((ret) != TIMERR_NOERROR) return FALSE;

/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/
//僾儘僩僞僀僾愰尵
/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/

BOOL InitMMTimer();
BOOL StartTimer(DWORD dwTimer);
//VOID CALLBACK TimerProc(UINT uTID,UINT uMsg,DWORD dwUser,DWORD dwParam1,DWORD dwParam2);
BOOL QuitMMTimer();

/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/
//僌儘乕僶儖曄悢
/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/
static UINT ExactTime   = 13;//嵟彫惛搙
static UINT TimerID     = NULL;

/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/
//僞僀儅乕惛搙傪愝掕偡傞丅
//偙偺娭悢偼傾僾儕働乕僔儑儞弶婜壔帪偵堦搙屇傃弌偡丅
/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/
BOOL InitMMTimer()
{
	/*TIMECAPS tc;
	MMRESULT ret;

	//僞僀儅乕偺惛搙忣曬傪庢摼偡傞
	ret = timeGetDevCaps(&tc,sizeof(TIMECAPS));
	if(ret != TIMERR_NOERROR) return FALSE;
	if(ExactTime < tc.wPeriodMin)ExactTime = tc.wPeriodMin;
	//偙偺惛搙偱弶婜壔偡傞
	ret = timeBeginPeriod(ExactTime);
	if(ret != TIMERR_NOERROR) return FALSE;
	return TRUE;*/

	return TRUE;
}

/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/
//僞僀儅乕傪婲摦偡傞丅
//dwTimer   愝掕偡傞僞僀儅乕娫妘
/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/
BOOL StartTimer(DWORD dwTimer)
{
	/*MMRESULT ret = NULL;
	ExactTime = dwTimer;
	//僞僀儅乕傪惗惉偡傞
	TimerID = timeSetEvent
	(
		dwTimer,       //僞僀儅乕帪娫
		1,             //嫋梕偱偒傞僞僀儅乕惛搙
		(LPTIMECALLBACK)TimerProc, //僐乕儖僶僢僋僾儘僔乕僕儍
		NULL,          //儐乕僓乕偑僐乕儖僶僢僋娭悢偺dwUser偵憲傞忣曬抣
		TIME_PERIODIC //僞僀儅乕帪娫枅偵僀儀儞僩傪敪惗偝偣傞
	);
	if(ret != TIMERR_NOERROR) return FALSE;
	return TRUE;*/

	S_SetOrganyaTimer(dwTimer);
	return TRUE;
}
/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/
//僞僀儅乕偺僐乕儖僶僢僋娭悢
/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/
/*VOID CALLBACK TimerProc(UINT uTID,UINT uMsg,DWORD dwUser,DWORD dwParam1,DWORD dwParam2)
{
	DWORD dwNowTime;
	dwNowTime = timeGetTime();
	//===================================================================================
	//偙偙偵儐乕僓乕掕媊偺僜乕僗傪彂偔丅
	//婎杮揑偵娭悢傪屇傃弌偡偩偗偱張棟偼懠偺娭悢偱偡傞傋偒偩傠偆丅
	//===================================================================================
	org_data.PlayData();
}*/

/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/
//僞僀儅乕儕僜乕僗傪奐曻偡傞丅
//傾僾儕働乕僔儑儞廔椆帪偵堦搙屇傃弌偡丅
/*仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭*/
BOOL QuitMMTimer()
{
	/*MMRESULT ret;

	if(TimerID != TIMERR_NOERROR)
	{
		//僞僀儅乕傪巊梡拞側傜廔椆偝偣傞
		ret = timeKillEvent(TimerID);
		if((ret) != TIMERR_NOERROR) return FALSE;
	}
	//僞僀儅乕儕僜乕僗傪奐曻偡傞
	ret = timeEndPeriod(ExactTime);
	if((ret) != TIMERR_NOERROR) return FALSE;
	return TRUE;*/

	S_SetOrganyaTimer(0);
	return TRUE;
}