#include <xl/Win32/COM/Objects/xlMediaPlayer.h> class MediaPlayer : public xl::MediaPlayer { public: void Play(LPCTSTR lpUrl) { BSTR bstrUrl = SysAllocString(lpUrl); m_pWMPPlayer->put_URL(bstrUrl); SysFreeString(bstrUrl); } }; LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); const LPCTSTR CLASS_NAME = _T("MediaPlayerContainer"); WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcex.lpszClassName = CLASS_NAME; RegisterClassEx(&wcex); HWND hWnd = CreateWindow(CLASS_NAME, _T("MediaPlayer Sample"), WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); if (hWnd == nullptr) { return 0; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); RECT rect = {}; GetClientRect(hWnd, &rect); rect.left += 100; rect.top += 100; rect.right -= 100; rect.bottom -= 100; MediaPlayer mp; if (!mp.CreateMediaPlayer(hWnd, &rect)) { return 0; } mp.Play(_T("Sample.mid")); MSG msg = {}; while (GetMessage(&msg, nullptr, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, nullptr, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int)msg.wParam; } |