LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
WPARAM wpItem;
LRESULT IntI = 0;
switch (message)
{
case WM_GETMINMAXINFO:
{
MINMAXINFO* pInfo = (MINMAXINFO*)lParam;
pInfo->ptMinTrackSize.x = XMIN_SIZE;
pInfo->ptMinTrackSize.y = YMIN_SIZE;
}
break;
case WM_COMMAND:
{
if (HIWORD(wParam) == CBN_SELCHANGE)
{
switch LOWORD(wParam)
{
case ID_CBVRENDERER:
{
WCHAR * Buffer[5];
IntI = SendMessage(HW(ID_CBVRENDERER), CB_GETCURSEL, IntI, 0);
if (IntI != CB_ERR)
SendMessage(HW(ID_CBVRENDERER), CB_GETLBTEXT, IntI, (WPARAM)(&Buffer));
KVideo_SetVideoRenderer((TVRenderer)IntI);
if (KVideo_GetPlayerState() != psNotReady)
Confirm(L"Designated video renderer will be applied since next opening media file.");
}
break;
case ID_CBPLAYBACKRATE:
{
WCHAR * Buffer[5];
IntI = SendMessage(HW(ID_CBPLAYBACKRATE), CB_GETCURSEL, IntI, 0);
if (IntI != CB_ERR)
SendMessage(HW(ID_CBPLAYBACKRATE), CB_GETLBTEXT, IntI, (WPARAM)(&Buffer));
WCHAR * fIn = (WCHAR*)(&Buffer);
float fOut = (float)wcstod(fIn, NULL);
KVideo_SetPlaybackRate(fOut);
}
break;
}
}
wpItem = LOWORD(wParam);
switch (wpItem)
{
case ID_OPEN:
{
if (KVideo_GetPlayerState() != psNotReady)
{
KillTimer(gP.MovieHandle, MOVIE_TIMER);
KVideo_CloseFile();
// Einstellungen zurück setzen
gP.MenuAudioChecked = 0;
gP.MenuVideoChecked = 0;
SetWindowText(HW(LB_STREAMDURATION), L"00:00:00\\");
SetWindowText(HW(LB_STREAMELAPSED), L"00:00:00");
SetWindowText(HW(LB_VIDEOINFO), L"0 x 0, 0 FPS");
SetWindowText(HW(LB_FILENAME), L"_");
SetWindowText(HW(LB_AUDIOPROPERTY), L"0 Channel, 0 SPS, 0 BPS");
SetScrollPos(gP.MovieHandle, SBS_HORZ, 0, TRUE);
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
}
// OpenFileDialog Initialisieren
CoInitialize(NULL);
const WCHAR *lpstrFilter = L"Media Files\0*.aac;*.asf;*.avi;*.m4a;*.mp3;*.mp4;*.m4v;*.wav;*.wma;*.wmv;*.3gp;*.3g2;*.mpeg;*.mpg;*.mov;*.qt;*.mkv;*.flv;*.vob\0"
L"All files\0*.*\0";
HANDLE hf;
OPENFILENAME OpenMediaFile;
ClearMemory(&OpenMediaFile, sizeof(OpenMediaFile));
WCHAR szFile[MAX_PATH];
szFile[0] = L'\0';
OpenMediaFile.lStructSize = sizeof(OpenMediaFile);
OpenMediaFile.hwndOwner = NULL;
OpenMediaFile.lpstrFile = szFile;
OpenMediaFile.nMaxFile = sizeof(szFile);
OpenMediaFile.lpstrFilter = lpstrFilter;
OpenMediaFile.nFilterIndex = 1;
OpenMediaFile.lpstrFileTitle = NULL;
OpenMediaFile.nMaxFileTitle = 0;
OpenMediaFile.lpstrInitialDir = NULL;
OpenMediaFile.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Video starten
if (GetOpenFileName(&OpenMediaFile))
{
hf = CreateFile(OpenMediaFile.lpstrFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (hf > 0)
{
CloseHandle(hf);
LRESULT IntI = SendMessage(HW(ID_CBVRENDERER), CB_GETCURSEL, 0, 0);
KVideo_SetVideoRenderer((TVRenderer)IntI);
// Mediafile starten
RunMediaFile(szFile, FALSE);
}
}
CoUninitialize();
}
break;
case ID_PLAY:
{
if (KVideo_GetPlayerState() == psPlaying)
return 0;
if (KVideo_GetPlayerState() == psPaused || KVideo_GetPlayerState() == psStopped)
if (KVideo_Play())
SetTimer(gP.MovieHandle, MOVIE_TIMER, 200, NULL);
}
break;
case ID_PAUSE:
{
if (KVideo_GetPlayerState() == psPlaying)
if (KVideo_Pause())
KillTimer(gP.MovieHandle, MOVIE_TIMER);
}
break;
case ID_STOP:
{
if (KVideo_GetPlayerState() == psPlaying || KVideo_GetPlayerState() == psPaused)
if (KVideo_Stop())
KillTimer(gP.MovieHandle, MOVIE_TIMER);
SetWindowText(HW(LB_STREAMDURATION), L"00:00:00\\");
SetWindowText(HW(LB_STREAMELAPSED), L"00:00:00");
SetScrollPos(gP.MovieHandle, SBS_HORZ, 0, TRUE);
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
}
break;
case ID_FULLSCREEN:
{
gP.bFullScreen = !gP.bFullScreen;
SetForegroundWindow(hWnd);
if (gP.bFullScreen)
{
RECT rect;
rect.right = GetSystemMetrics(SM_CXSCREEN);
rect.bottom = GetSystemMetrics(SM_CYSCREEN);
SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
AdjustWindowRect(&rect, WS_POPUP, FALSE);
MoveWindow(hWnd, 0, 0, rect.right, rect.bottom, FALSE);
}
else
{
RECT rect;
rect.right = dpi(XMIN_SIZE);
rect.bottom = dpi(YMIN_SIZE);
rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE);
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
MoveWindow(hWnd, rect.left, rect.top, dpi(XMIN_SIZE), dpi(YMIN_SIZE), FALSE);
}
}
break;
case ID_CAPTURE:
{
TPlayerState ps = KVideo_GetPlayerState();
if (ps == psStopped || ps == psNotReady)
{
Confirm(L"It's not playing state.");
return 0;
}
else
{
HBITMAP hbmp = 0;
if (KVideo_GetCapturedImage(&hbmp))
{
WCHAR Image[MAX_PATH];
ZeroMemory(Image, MAX_PATH * sizeof(WCHAR));
WCHAR * Path = { 0 };
Path = EXEpath();
_snwprintf_s(Image, MAX_PATH, 259, L"%s%d%s", Path, gP.PicCount, L"_Capture.jpg");
SaveBitmapToFile(Image, hbmp, 0);
gP.PicCount++;
}
DeleteObject(hbmp);
}
}
break;
case ID_CLOSE:
DestroyWindow(hWnd);
break;
// Menüauswahl bearbeiten:
case ID_CKB_SEARCH:
{
if (KVideo_GetPlayerState() != psNotReady)
{
BOOL checked = IsDlgButtonChecked(hWnd, ID_CKB_SEARCH);
if (checked) {
CheckDlgButton(hWnd, ID_CKB_SEARCH, BST_UNCHECKED);
}
else
{
CheckDlgButton(hWnd, ID_CKB_SEARCH, BST_CHECKED);
}
KVideo_SetSearchMode(EnableWindow(HW(ID_CBPLAYBACKRATE), !checked));
break;
}
}
break;
case IDM_ABOUT
:
DialogBox(GetModuleHandle(0), MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_HSCROLL:
{
switch LOWORD(wParam)
{
case TB_ENDTRACK:
gP.bVolume = FALSE;
break;
case TB_THUMBTRACK: // ziehen des "Sliders"
case TB_TOP: // Pos1
case TB_BOTTOM: // Ende
case TB_LINEDOWN: // Pfeiltasten oben/unten
case TB_PAGEDOWN: // Bild runter & in die Leiste geklickt
case TB_PAGEUP: // Bild auf & in die Leiste geklickt
{
gP.bVolume = TRUE;
gP.Position = (int)SendMessage(HW(ID_TBVOLUME), TBM_GETPOS, 0, 0);
if (gP.Position == 0)
KVideo_SetVolume(-10000);
else
KVideo_SetVolume(LONG(5000 * log10(gP.Position)) - 10000);
}
break;
}
}
break;
case WM_SIZE:
{
EnumChildWindows(hWnd, &AnchorEnum, 0);
RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ERASENOW | RDW_UPDATENOW | RDW_ALLCHILDREN | RDW_FRAME);
}
break;
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC)wParam;
SetBkMode(hdcStatic, TRANSPARENT);
return (INT_PTR)GetStockObject(WHITE_BRUSH);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}