#include "stdafx.h" #include "yaneSDK.h" #include class DropHookWnd : public CWinHook { HWND mhWnd; public: char *filename; void init(HWND hWnd) { mhWnd=hWnd; DragAcceptFiles(hWnd, TRUE); filename=NULL; } ~DropHookWnd() { if(filename) free(filename); } void Play(); LRESULT WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_DROPFILES:{ HDROP hDrop=(HDROP)wParam; char szFileName[256]; int uFileNo = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); DragQueryFile(hDrop, 0, szFileName, sizeof(szFileName)); int len=lstrlen(szFileName); if(filename) free(filename); filename=strdup(szFileName); DragFinish(hDrop); Play(); break; } default: return 0; } return 1; } }; class CAppMainWindow: public CAppBase { DropHookWnd ma; CStreamSound *stream; virtual void MainThread(void) { bool playing; CDirectSound ds; ds.SetFormat(0x0f); stream = new CStreamSound(); stream->SetLoopMode(true); CVirtualKey vk; CDirectInput input; enum {pause, exit}; vk.AddDevice(&input); vk.AddKey(pause,&input,DIK_SPACE); vk.AddKey(exit,&input,DIK_RETURN); CDirectDraw dd; dd.SetDisplay(false,300,100); CFPSTimer timer; timer.SetFPS(12); CTextLayer text; text.GetFont()->SetSize(20); text.SetPos(10,20); CTextLayer spos; spos.GetFont()->SetSize(20); spos.SetPos(10,55); while( IsThreadValid() ) { vk.Input(); if( vk.IsVKeyPush( pause ) ) { if( playing ) { if(stream->Pause()) playing=false; }else{ if(stream->Replay()) playing=true; } } if( vk.IsVKeyPush(exit) ) break; dd.Clear(); if(ma.filename) text.GetFont()->SetText(ma.filename); else text.GetFont()->SetText("nul"); { char tmp[80]; static prevPos=0; LONG pos=stream->GetCurrentPos(); if( pos >= prevPos) sprintf(tmp,"%8d", pos); else sprintf(tmp,"**%8d**", pos); prevPos=pos; spos.GetFont()->SetText(tmp); } dd.OnDraw(); timer.WaitFrame(); } delete stream; stream=NULL; } virtual LRESULT OnPreCreate( CWindowOption &opt) { opt.caption = "player"; opt.classname = "testplayer"; opt.size_x =300; opt.size_y =100; opt.style = WS_SYSMENU | WS_MINIMIZEBOX; return 0; } virtual LRESULT OnCreate() { ma.init( GetHWnd() ); GetMyWindow()->GetHookList()->Add(&ma); return 0; }; virtual LRESULT OnDestroy() { GetMyWindow()->GetHookList()->Del(&ma); return 0; } public: void play(const char *f) { stream->Open( f ); stream->Play(); } }; void DropHookWnd::Play() { CAppMainWindow *mw = static_cast(CAppBase::GetMainApp()); if(!mw) return; mw->play(filename); } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdParam, int nCmdShow) { CAppInitializer::Init(hInstance, hPrevInstance,lpCmdParam,nCmdShow); CSingleApp sapp; if( sapp.IsValid() ) CAppMainWindow().Run(); return 0; }