📄 main.cpp
字号:
{
POINT pt;
POINT pt2;
MSG Msg;
WNDCLASS W;
/*
* 为对话框和资源保存一个全局实例
*
*/
hInstance = hInst;
showing_cursor = 1;
firstStart = 1;
/*
* 装载选项
*
*/
LoadOptions();
/*
* 初始化视频子系统
*
*/
playlist = new Playlist();
playback = new MediaPlayback();
skinList = new SkinList();
resizer = new Resizer();
/*
* 分析命令行和重载选项
*
*/
ParseCmdLine(lpszCmdParam);
/*
* 设置缺省设置
*
*/
playback->SetLoop(options.loop);
playback->videoDecoder->decoreDecoder->SetQuality(options.postprocessing);
playback->SetDesktopMode(FALSE);
/*
* 窗口大小调整
*
*/
windowRect.left = 0;
windowRect.right = DEFAULT_SKIN_WIDTH;
windowRect.top = 0;
windowRect.bottom = DEFAULT_SKIN_HEIGHT;
AdjustWindowRect(&windowRect, WS_POPUP|WS_SIZEBOX, 0);
/*
* 初始化COM库
*
*/
CoInitialize(NULL);
/*
* 注册Window类
*
*/
memset(&W, 0, sizeof(WNDCLASS));
W.style = CS_HREDRAW | CS_VREDRAW | CS_PARENTDC;
W.lpfnWndProc = WndProc;
W.hInstance = hInst;
W.hbrBackground = (HBRUSH)(0);
W.hCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR1));
W.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDB_ICON));
W.lpszClassName = Name;
W.lpszMenuName = NULL;
RegisterClass(&W);
/*
* 装载菜单,并为最近文件链表改变菜单
*
*/
popupMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU1));
ReBuildRecentFilesMenu();
ReBuildPlaylistMenu();
/*
* 产生主窗口
*
*/
hwnd = CreateWindow(Name, Name, WS_POPUP | WS_SIZEBOX,
options.posX, options.posY,
windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top,
NULL, NULL, hInst, NULL);
/*
* 设置窗口区域
*
*/
GetClientRect(hwnd, &clientRect);
GetWindowRect(hwnd, &windowRect);
pt.x = clientRect.left;
pt.y = clientRect.top;
ClientToScreen(hwnd, &pt);
pt2.x = clientRect.right;
pt2.y = clientRect.bottom;
ClientToScreen(hwnd, &pt2);
SetWindowRgn(hwnd, CreateRectRgn( pt.x - windowRect.left,
pt.y - windowRect.top,
(windowRect.right - windowRect.left) - (windowRect.right - pt2.x),
(windowRect.bottom - windowRect.top) - (windowRect.bottom - pt2.y)), TRUE);
DragAcceptFiles(hwnd, TRUE);
/*
* 启动定时器
*
*/
SetTimer(hwnd, TIMER_ID, TIMER_RATE, NULL);
/*
* 装载加速键
*/
hAccel = LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_ACCELERATOR));
/*
* 设置图标
*/
SetClassLong(hwnd, GCL_HICON, (LONG) LoadIcon(hInst, MAKEINTRESOURCE(IDB_ICON)));
/*
* 菜单项
*/
CheckMenuItem(popupMenu, (UINT)ID_LOOP, options.loop ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(popupMenu, (UINT)ID_ON_TOP, options.on_top ? MF_CHECKED : MF_UNCHECKED);
switch(options.aspect_ratio) {
case ASPECT_RATIO_ORIGINAL:
CheckMenuItem(popupMenu, (UINT)ID_ASPECT_FREE, MF_UNCHECKED);
CheckMenuItem(popupMenu, (UINT)ID_ASPECT_ORIGINAL, MF_CHECKED);
break;
case ASPECT_RATIO_TV:
CheckMenuItem(popupMenu, (UINT)ID_ASPECT_FREE, MF_UNCHECKED);
CheckMenuItem(popupMenu, (UINT)ID_ASPECT_43, MF_CHECKED);
break;
case ASPECT_RATIO_WIDE:
CheckMenuItem(popupMenu, (UINT)ID_ASPECT_FREE, MF_UNCHECKED);
CheckMenuItem(popupMenu, (UINT)ID_ASPECT_169, MF_CHECKED);
break;
case ASPECT_RATIO_CUSTOM:
CheckMenuItem(popupMenu, (UINT)ID_ASPECT_FREE, MF_UNCHECKED);
CheckMenuItem(popupMenu, (UINT)ID_ASPECT_CUSTOM, MF_CHECKED);
break;
}
/*
* 装载外壳
*
*/
skin = new Skin(hInst, hwnd);
if(strcmp(skinPath, "Default") == 0) {
skin->LoadDefault(hInst, hwnd);
}
else {
skin->Load(skinPath, hwnd);
}
/*
* 使屏保无效,并得到当前状态
*
*/
screenSaverActive = FALSE;
SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &screenSaverActive, 0);
if(options.disable_screen_saver) {
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);
}
/*
* 开始显示
*
*/
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
GetWindowRect(hwnd, &windowRect);
if(options.on_top)
SetWindowPos(hwnd, (HWND) -1, windowRect.left, windowRect.top, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, TRUE);
/*
* 消息循环
*
*/
while (TRUE)
{
/*
* 得到消息
*/
if (!GetMessage(&Msg, NULL, 0, 0))
return (int) Msg.wParam;
if (!TranslateAccelerator(hwnd, hAccel, &Msg)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
else {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return Msg.wParam;
}
/**************************************************************************************
* *
* - OpenFileForPlaying(): *
* *
* ———打开当前播放链表位置 *
* *
**************************************************************************************/
void OpenFileForPlaying(HWND hwnd) {
char *filename;
RECT rect, windowrect;
/*
* 关闭最后的重放
*
*/
playback->Close();
filename = playlist->GetCurrentItem()->filename;
/*
* 如果没有文件被打开,简单的返回
*
*/
if(filename == NULL) {
return;
}
openning_network = FALSE;
/*
* 清除
*
*/
if(strstr(filename, "http://") != NULL ||
strstr(filename, "HTTP://") != NULL ||
strstr(filename, "FTP://") != NULL ||
strstr(filename, "ftp://") != NULL) {
if(playback->OpenMediaSource(filename) == MP_RESULT_OK) {
openning_network = TRUE;
return;
}
MP_ERROR("The network location you selected could not be opened");
return;
}
else {
if(playback->OpenMedia(filename, hwnd) == MP_RESULT_OK) {
/*
* 第一次调整窗口大小
*/
DWORD i, width, height;
switch(options.aspect_ratio) {
case ASPECT_RATIO_FREE:
case ASPECT_RATIO_ORIGINAL:
width = playback->GetVideoWidth();
height = playback->GetVideoHeight();
break;
case ASPECT_RATIO_TV:
case ASPECT_RATIO_WIDE:
case ASPECT_RATIO_CUSTOM:
width = playback->GetVideoWidth();
height = width*aspectRatios[options.aspect_ratio].yFactor/aspectRatios[options.aspect_ratio].xFactor;
break;
}
if(!playback->fullscreen) {
GetWindowRect(hwnd, &windowrect);
}
if(compact_mode) {
rect.left = 0;
rect.top = 0;
rect.right = width;
rect.bottom = height;
}
else {
rect.left = 0;
rect.top = 0;
rect.right = width + 15;
rect.bottom = height + 115 + 22;
}
AdjustWindowRect(&rect, WS_POPUP|WS_SIZEBOX, FALSE);
fullwindowRect.right = fullwindowRect.left + rect.right - rect.left;
fullwindowRect.bottom = fullwindowRect.top + rect.bottom - rect.top;
if(!playback->fullscreen) {
MoveWindow( hwnd, windowrect.left, windowrect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE);
playback->SetVideoRect(skin->GetVideoRect());
}
/*
* 更新最近的文件链表
*/
UpdateRecentFilesMenu(filename);
/*
* 更新菜单
*/
if(!playback->IsInFullscreen()) {
ChangeMenuForNormalMode();
/*
* 更新最近文件链表
*/
ReBuildRecentFilesMenu();
}
/*
* 设置音量
*/
playback->SetVolume(skin->GetVolume());
/*
* 保存/设置后处理
*/
options.postprocessing = playback->videoDecoder->GetQuality();
playback->videoDecoder->SetQuality(options.postprocessing);
/*
* 播放
*/
playback->Play();
/*
* 更新窗口
*/
UpdateMainWindow();
}
else {
/*
* 文件打开失败
*/
MP_ERROR("The location you selected could not be opened");
}
}
}
/**************************************************************************************
* *
* - AddFilesToPlaylist(): *
* *
* ———增加文件到文件链表 *
* *
**************************************************************************************/
void AddFilesToPlaylist(HWND hwnd)
{
OPENFILENAME ofn;
char szFile[260];
/*
* 显示一个文件选择器
*/
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ZeroMemory(szFile, 260);
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0AVI Files\0*.AVI\0\0";
ofn.nFilterIndex = 2;
ofn.lpstrFileTitle = "";
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
if (GetOpenFileName(&ofn) == TRUE) {
if(ofn.lpstrFile[strlen(ofn.lpstrFile) + 1] == NULL) {
/*
* 只有一个文件被选择
*
*/
playlist->AddItem(ofn.lpstrFile);
}
else {
/*
* 多个文件被选择
*
*/
DWORD index, i = 0;
char dir[1024];
index = strlen(ofn.lpstrFile) + 1;
do {
strcpy(dir, ofn.lpstrFile);
playlist->AddItem((LPSTR)st
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -