#include #include #include"smf.h" // winmm.lib をリンクする #pragma comment(lib,"winmm") LRESULT CALLBACK WindowProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; char str[64]; static SmfPlay sp("AUTUMN","MIDI"); static double endTime; char end[32]; MMTIME mmt; static DWORD currentTime; char current[32]; switch(uMsg){ case WM_CREATE: endTime=sp.GetEndTime(); SetTimer(hWnd,1,50,NULL); return 0; case WM_KEYDOWN: switch(wParam){ case 'A': sp.Play(); return 0; case 'S': sp.Pause(); return 0; case 'D': sp.Stop(); return 0; case 'F': sp.CreateSMF("smf0.mid"); return 0; } return 0; case WM_TIMER: mmt.wType=TIME_MS; sp.GetCurrentPosition(&mmt,sizeof(MMTIME)); currentTime=mmt.u.ms; InvalidateRect(hWnd,NULL,FALSE); return 0; case WM_PAINT: hdc=BeginPaint(hWnd,&ps); sprintf(end,"%lf",endTime); sprintf(current,"%lf",currentTime/1000.0); wsprintf(str,"%s / %s",current,end); TextOut(hdc,0,0,str,lstrlen(str)); EndPaint(hWnd,&ps); return 0; case WM_DESTROY: KillTimer(hWnd,1); PostQuitMessage(0); return 0; } return DefWindowProc(hWnd,uMsg,wParam,lParam); } int WINAPI WinMain( HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR lpCmdLine,int nCmdShow) { WNDCLASS wc; MSG msg; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = __FILE__; if(!RegisterClass(&wc)) return 0; HWND hWnd=CreateWindow( __FILE__,"MIDIストリーム", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL,hInstance,NULL); if(hWnd==NULL) return 0; BOOL bRet; while((bRet=GetMessage(&msg,NULL,0,0))!=0){ if(bRet==-1) break; DispatchMessage(&msg); } return (int)msg.wParam; }