⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 播放器源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
 *   -- Re-Paint the main window                                                      *
 *                                                                                    *
 **************************************************************************************/

void UpdateMainWindow()
{
	RECT rect;

	GetClientRect(hwnd, &rect);
	InvalidateRect(hwnd, &rect, TRUE); 
	UpdateWindow(hwnd);
}

/**************************************************************************************
 *                                                                                    *
 *                                      QUIT                                          *
 *                                    --------                                        *
 **************************************************************************************/

void Quit() 
{
	SaveOptions();
	playback->Close();

	if(playback->desktopMode) {

		UnPrepareDesktopMode();
	}
		
	if(options.disable_screen_saver) {

		SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, screenSaverActive, NULL, 0);
	}

	Cleanup();

	PostQuitMessage(0);
}

/**************************************************************************************
 *                                                                                    *
 * - WinMain():                                                                       *
 *                                                                                    *
 *   -- Program Entry Point                                                           *
 *                                                                                    *
 **************************************************************************************/

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{ 
	POINT     pt;
	POINT     pt2;
    MSG       Msg;
    WNDCLASS  W;

	/*
	 * Keep a global instance
	 * for dialogs and ressources
	 *
	 */

	hInstance = hInst;

	showing_cursor = 1;
	firstStart     = 1;

	/*
	 * Load the options
	 *
	 */

	LoadOptions();

	/*
     * Init the video subsystem 
     *
     */

	playlist = new Playlist();
	playback = new MediaPlayback();
	skinList = new SkinList();
	resizer  = new Resizer();

	/*
	 * Parses the command line
	 * and ovveride options
	 *	
     */

	ParseCmdLine(lpszCmdParam);

	/*
	 * Set the default settings
	 *
	 */

	playback->SetLoop(options.loop);
	playback->videoDecoder->decoreDecoder->SetQuality(options.postprocessing);
	playback->SetDesktopMode(FALSE);

	/*
	 * Window size adjustmen
	 *
	 */

	windowRect.left   = 0;
	windowRect.right  = DEFAULT_SKIN_WIDTH;
	windowRect.top    = 0;
	windowRect.bottom = DEFAULT_SKIN_HEIGHT;

    AdjustWindowRect(&windowRect, WS_POPUP|WS_SIZEBOX, 0);

	/*
	 * Initialize the COM library
	 *
	 */

	CoInitialize(NULL);	

	/*
	 * Register the Window Class
	 * 
	 */

	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);

   /*
    * Load the menu and change 
	* it for recent file list
	*
    */

	popupMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU1));

	ReBuildRecentFilesMenu();
	ReBuildPlaylistMenu();

   /*
    * Create the main window
    *
    */

	hwnd = CreateWindow(Name, Name, WS_POPUP | WS_SIZEBOX, 
		                options.posX, options.posY, 
						windowRect.right - windowRect.left, 
						windowRect.bottom - windowRect.top, 
						NULL, NULL, hInst, NULL);
   /*
    * Set the window Rgn
    *
    */

	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); 

	/*
     * Register for Drag n' Drop
     */

	DragAcceptFiles(hwnd, TRUE);

   /*
    * Start TIMER
    *
    */

	SetTimer(hwnd, TIMER_ID, TIMER_RATE, NULL);

	/*
	 * Load Accelerators
	 */

	hAccel = LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_ACCELERATOR));	

	/*
	 * Set the icon
	 */

	SetClassLong(hwnd, GCL_HICON, (LONG) LoadIcon(hInst, MAKEINTRESOURCE(IDB_ICON))); 
 
	/*
	 * Menu items 
	 */

	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;
	}

   /*
    * Loads the skin
    *
    */

   skin = new Skin(hInst, hwnd);

   if(strcmp(skinPath, "Default") == 0) {

	   skin->LoadDefault(hInst, hwnd);
   }
   else {
	
	   skin->Load(skinPath, hwnd);
   }

   /*
    * Disable screen saver
    * And Get the current State
    *
    */
		
	screenSaverActive = FALSE;
	
	SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &screenSaverActive, 0);

	if(options.disable_screen_saver) {

		SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);
   }

   /*
    * Let the Show Begin
	*
    */

	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);

	/*
	 * Message Loop
	 *
	 */

	while (TRUE)
    {

	   /*
		* Get the messages
		*/

	   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():                                                            *
 *                                                                                    *
 *   -- Opens the current playlist location                                           *
 *                                                                                    *
 **************************************************************************************/

void OpenFileForPlaying(HWND hwnd) {

	char *filename;
	RECT rect, windowrect;

	/*
	 * Closes last playback
	 *
	 */

	playback->Close();
	filename = playlist->GetCurrentItem()->filename;

	/*
	 * If no file to open
	 * we simply returns... 
	 * 
	 */

	if(filename == NULL) {

		return;
	}

	openning_network = FALSE;

	/*
	 * We need to make that cleaner
	 *
	 */
	
	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) {

		/*
		 * First resize the window
		 */

		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());
		}

		/*
		 * Update recent file list
		 */
		
		UpdateRecentFilesMenu(filename);

		/*
		 * And update the menu
		 */

		if(!playback->IsInFullscreen()) {

			ChangeMenuForNormalMode();
			
			/*
			 * And the recent file list
			 */
		
			ReBuildRecentFilesMenu();
		}

		/*
		 * Set the volume
		 */

		playback->SetVolume(skin->GetVolume());
		
		/*
		 * Save/Set postprocessing
		 */

		options.postprocessing = playback->videoDecoder->GetQuality();
		playback->videoDecoder->SetQuality(options.postprocessing);

		/*
	 	 * Then play
		 */

		playback->Play();

		/*
		 * And update the window
		 */

		UpdateMainWindow();
	}
	else {

		/*
		 * File couldn't be opened
		 */

		MP_ERROR("The location you selected could not be opened");
	}
  }
}

/***************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -