// // MCIウインドウによるメディア再生 // // 2001/ 9/30 宍戸 輝光 // #include #include HINSTANCE hInst; LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); HWND hwMain; int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, PSTR szCmdLine,int iCmdShow){ MSG msg; WNDCLASSEX wndclass; // ウインドウクラス設定 wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL,IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = "CWindow"; wndclass.hIconSm = NULL; RegisterClassEx(&wndclass); /* ウインドウクラス登録 */ hwMain = CreateWindow("CWindow","MCIWnd", WS_OVERLAPPEDWINDOW | WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT, 280,120,NULL,NULL,hInstance,NULL); DragAcceptFiles(hwMain,TRUE); /* ドラッグ&ドロップ受入 */ while (GetMessage(&msg,NULL,0,0)) { /* メッセージループ */ TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { static HWND hwMci; HDROP hDrop; TCHAR lpszFn[MAX_PATH+1]; static BOOL loaded; switch (iMsg) { case WM_CREATE: hwMci=MCIWndCreate(hwnd,hInst,MCIWNDF_NOPLAYBAR|MCIWNDF_NOMENU,NULL); loaded=FALSE; return 0; case WM_DROPFILES: /* ファイルがドロップされた時の処理 */ hDrop=(HDROP)wParam; /* HDROPを取得 */ DragQueryFile(hDrop,0,lpszFn,256); /* ファイル名を取得 */ DragFinish(hDrop); /* 終了処理 */ if (loaded) MCIWndClose(hwMci); MCIWndOpen(hwMci,lpszFn,0); MCIWndPlay(hwMci); loaded=TRUE; SetWindowText(hwnd,lpszFn); return 0; case WM_DESTROY : // 終了処理 if (loaded) MCIWndClose(hwMci); MCIWndDestroy(hwMci); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd,iMsg,wParam,lParam); }