?? main.cpp
字號:
{
POINT pt;
POINT pt2;
MSG Msg;
WNDCLASS W;
/*
* 為對話框和資源保存一個全局實例
*
*/
hInstance = hInst;
showing_cursor = 1;
firstStart = 1;
/*
* 裝載選項
*
*/
LoadOptions();
/*
* 初始化視頻子系統(tǒng)
*
*/
playlist = new Playlist();
playback = new MediaPlayback();
skinList = new SkinList();
resizer = new Resizer();
/*
* 分析命令行和重載選項
*
*/
ParseCmdLine(lpszCmdParam);
/*
* 設(shè)置缺省設(shè)置
*
*/
playback->SetLoop(options.loop);
playback->videoDecoder->decoreDecoder->SetQuality(options.postprocessing);
playback->SetDesktopMode(FALSE);
/*
* 窗口大小調(diào)整
*
*/
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();
/*
* 產(chǎn)生主窗口
*
*/
hwnd = CreateWindow(Name, Name, WS_POPUP | WS_SIZEBOX,
options.posX, options.posY,
windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top,
NULL, NULL, hInst, NULL);
/*
* 設(shè)置窗口區(qū)域
*
*/
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));
/*
* 設(shè)置圖標
*/
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);
}
/*
* 使屏保無效,并得到當前狀態(tài)
*
*/
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);
/*
* 消息循環(huán)
*
*/
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;
/*
* 關(guān)閉最后的重放
*
*/
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) {
/*
* 第一次調(diào)整窗口大小
*/
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();
}
/*
* 設(shè)置音量
*/
playback->SetVolume(skin->GetVolume());
/*
* 保存/設(shè)置后處理
*/
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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -