/**
* MingPlayer.cpp
* Copyright _ 2001 Li Zhaoming. All rights reserved.
*/
#include "stdafx.h"
#include "resource.h"
HWND hwndVideo;
UINT uDeviceID;
BOOL g_bAVI;
BOOL g_bPaused = true;
BOOL g_bRepeat = true;
BOOL g_bTopMost = false;
BOOL g_bWindowMax = false;
RECT g_rcWindow = { 0, 0, 300, 300 };
struct LIST
{
char *file[256];
LIST *next;
};
LIST *lpList = NULL;
LIST *lpListX = NULL;
// Main window message table definition.
MSD rgmsd[] =
{
{WM_CREATE, msgCreate },
{WM_SIZE, msgSize },
{WM_GETMINMAXINFO, msgGetMinMaxInfo},
{WM_SYSCOMMAND, msgSysCommand },
{WM_NOTIFY, msgNotify },
{WM_KEYDOWN, msgKeyDown },
{WM_TIMER, msgTimer },
{WM_PAINT, msgPaint },
{WM_COMMAND, msgCommand },
{WM_DESTROY, msgDestroy },
{WM_CLOSE, msgDestroy },
};
MSDI msdiMain =
{
sizeof(rgmsd) / sizeof(MSD),
rgmsd,
edwpWindow
};
// Main window command table definition.
CMD rgcmd[] =
{
// File
{IDM_OPEN, cmdOpenFile },
{IDM_EXIT, cmdExit },
// View
{IDM_TOOLBAR, cmdToolbar },
{IDM_TOP_MOST, cmdTopMost },
{IDM_FULL_SCREEN, cmdFullScreen },
// Play
{IDM_PLAY, cmdPlay },
{IDM_PAUSE, cmdPause },
{IDM_STOP, cmdStop },
{IDM_REWIND, cmdRewind },
{IDM_FORWARD, cmdForward },
{IDM_REPEAT, cmdRepeat },
// Help
{IDM_ABOUT, cmdAbout },
};
CMDI cmdiMain =
{
sizeof(rgcmd) / sizeof(CMD),
rgcmd,
edwpWindow
};
/**
* Processes messages for the main window.
*/
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
return dispatchMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
}
/**
* Handle the WM_COMMAND messages for the main window.
*/
LRESULT msgCommand(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
return dispatchCommand(&cmdiMain, hwnd, wparam, lparam);
}
/**
* Handle the WM_CREATE messages for the main window.
*/
LRESULT msgCreate(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
// INI file name
char iniFileName[MAX_PATH];
GetModuleFileName(NULL, iniFileName, sizeof(iniFileName));
strcpy(strrchr(iniFileName, '.')+1, "ini");
// Window Position.
GetPrivateProfileStruct("Window", "Position", (LPVOID) &g_rcWindow, sizeof(g_rcWindow), iniFileName);
MoveWindow (hwnd, g_rcWindow.left, g_rcWindow.top, g_rcWindow.right-g_rcWindow.left, g_rcWindow.bottom-g_rcWindow.top, true);
GetPrivateProfileString("File", "Open Path", szOpenPath, szOpenPath, MAX_PATH, iniFileName);
// Timer
SetTimer(hwnd, IDM_TIMER, TIMER_TIMEOUT, NULL);
// Initialize the common control library.
InitCommonControls();
// First, we initialize the common controls
INITCOMMONCONTROLSEX iccex;
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccex.dwICC = ICC_COOL_CLASSES | ICC_USEREX_CLASSES; // load the reba and combo and combo
InitCommonControlsEx(&iccex);
// Create toolbar and status bar.
if (!createToolbar(hwnd)) return -1;
return 0;
}
/**
* This function resizes the toolbar control.
*/
LRESULT msgSize(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
int cx = LOWORD(lparam);
int cy = HIWORD(lparam);
RECT rctb, rc;
if (IsWindowVisible(hwndRebar)){
GetClientRect(hwnd, &rc);
GetWindowRect(hwndRebar, &rctb);
cy -= (rctb.bottom-rctb.top);
//SendMessage(hwndRebar, uMessage, wparam, lparam);
MoveWindow(hwndRebar, 0, (rc.bottom - rc.top) -(rctb.bottom-rctb.top), LOWORD(lparam), 0, TRUE);
// Re-position the client window
MoveWindow (hwndVideo, 4, 4, cx-8, cy-8, false);
}
return 0 ;
}
/**
* Handle the WM_GETMINMAXINFO message.
*/
LRESULT msgGetMinMaxInfo(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
LPMINMAXINFO lpinfo = (LPMINMAXINFO) lparam;
// For toggling full screen mode on.
lpinfo->ptMaxTrackSize.x = 8 +2 + GetSystemMetrics(SM_CXSCREEN);
lpinfo->ptMaxTrackSize.y = 46 +2 + GetSystemMetrics(SM_CYSCREEN);
return 0 ;
}
LRESULT msgTimer(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
char buffer[256];
int length, position;
mciSendString("status thevideo length", buffer, 20, hwnd);
length= atoi(buffer);
mciSendString("status thevideo position", buffer, 20, hwnd);
position=atoi(buffer);
if (length != 0) {
sprintf(buffer,"%02d:%02d/%02d:%02d",position/600, position%600/36,length/600,length%600/20);
updateStatusBar(buffer, 1.0*position/length);
if (position == length) {
mciSendString("seek thevideo to start", 0, 0, 0);
lpListX = lpListX->next;
if (lpListX != NULL)
{
mciSendString("close thevideo", 0, 0, 0);
openVideoFile(hwnd, (char *)lpListX->file);
}
else {
g_bPaused = true;
lpListX = lpList;
if (g_bRepeat) {
mciSendString("close thevideo", 0, 0, 0);
openVideoFile(hwnd, (char *)lpListX->file);
}
}
}
}
return 0;
}
/**
*
*/
LRESULT msgKeyDown(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
char buffer[100];
//
int length, position;
mciSendString("status thevideo length", buffer, 19, hwnd);
length= atoi(buffer);
mciSendString("status thevideo position", buffer, 19, hwnd);
position=atoi(buffer);
//
int cnt = lparam & 0x00ff;
int step = length*cnt/200;
//
switch (wparam)
{
case VK_PRIOR:
mciSendString("stop thevideo", 0, 0, 0);
sprintf(buffer, "seek thevideo to %d", position - step);
mciSendString(buffer, buffer, 19, hwnd);
if (g_bPaused)
{
SendMessage(hwnd, WM_COMMAND, IDM_PLAY, NULL);
SendMessage(hwnd, WM_COMMAND, IDM_PAUSE, NULL);
}
else
{
SendMessage(hwnd, WM_COMMAND, IDM_PLAY, NULL);
}
InvalidateRect(hwndTrack, NULL, false);
break;
case VK_NEXT:
mciSendString("stop thevideo", 0, 0, 0);
sprintf(buffer, "seek thevideo to %d", position + step);
mciSendString(buffer, buffer, 19, hwnd);
if (g_bPaused)
{
SendMessage(hwnd, WM_COMMAND, IDM_PLAY, NULL);
SendMessage(hwnd, WM_COMMAND, IDM_PAUSE, NULL);
}
else
{
SendMessage(hwnd, WM_COMMAND, IDM_PLAY, NULL);
}
InvalidateRect(hwndTrack, NULL, false);
break;
case VK_HOME:
mciSendString("stop thevideo", 0, 0, 0);
mciSendString("seek thevideo to start", 0, 0, 0);
if (g_bPaused)
{
SendMessage(hwnd, WM_COMMAND, IDM_PLAY, NULL);
SendMessage(hwnd, WM_COMMAND, IDM_PAUSE, NULL);
}
else
{
SendMessage(hwnd, WM_COMMAND, IDM_PLAY, NULL);
}
InvalidateRect(hwndTrack, NULL, false);
break;
case VK_END:
mciSendString("seek thevideo to end", 0, 0, 0);
break;
case VK_ESCAPE:
if (g_bFullScreen)
SendMessage(hwnd, WM_COMMAND, IDM_FULL_SCREEN, NULL);
}
return 0;
}
/**
*
*/
LRESULT msgSysCommand(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
if (LOWORD(wparam) == SC_RESTORE || LOWORD(wparam) == SC_MINIMIZE)
{
if (g_bFullScreen)
{
g_bFullScreen = false;
CheckMenuItem(GetMenu(hwnd), IDM_FULL_SCREEN, MF_UNCHECKED);
SendMessage(hwndToolbar, TB_SETSTATE, IDM_FULL_SCREEN, MAKELONG(TBSTATE_ENABLED, 0));
}
}
if (!(IsZoomed(hwnd) || IsIconic(hwnd)))
{
GetWindowRect(hwnd, &g_rcWindow);
}
return DefWindowProc(hwnd, uMessage, wparam, lparam);
}
/**
* Handle the WM_PAINT message.
*/
LRESULT msgPaint(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
RECT rc;
PAINTSTRUCT ps;
HDC hdc=BeginPaint(hwnd, &ps);
// Begin paint.
GetClientRect(hwnd, &rc);
FillRect(hdc, &rc, (HBRUSH) GetStockObject(BLACK_BRUSH));
FrameRect(hdc, &rc, (HBRUSH) GetStockObject(WHITE_BRUSH));
InflateRect(&rc, 1, 1);
rc.left++; rc.top++;
FrameRect(hdc, &rc, (HBRUSH) GetStockObject(GRAY_BRUSH));
// End paint.
EndPaint(hwnd, &ps);
return 0;
}
/**
* Calls PostQuitMessage().
*/
LRESULT msgDestroy(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
mciSendCommand(uDeviceID,MCI_CLOSE,0,0);
// Delete list;
while (lpList != NULL)
{