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

📄 main.cpp

📁 <VC++视频音频开发>一书的光盘资料。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			   itemInfo.fType  = MFT_STRING;
			   itemInfo.dwTypeData = buffer;
			   itemInfo.cch = strlen(buffer);
			   itemInfo.wID = ID_RECENT_FILE1 + i;
		   
			   InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &itemInfo);
			}
	   }
    itemInfo.cbSize = sizeof(MENUITEMINFO);
    itemInfo.fMask  = MIIM_DATA | MIIM_TYPE | MIIM_ID;
    itemInfo.fType  = MFT_SEPARATOR;
    itemInfo.dwTypeData = "";
    itemInfo.cch = strlen("");
    itemInfo.wID = ID_RECENT_FILE1 + i;
		   
	InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &itemInfo);

    itemInfo.cbSize = sizeof(MENUITEMINFO);
    itemInfo.fMask  = MIIM_DATA | MIIM_TYPE | MIIM_ID;
    itemInfo.fType  = MFT_STRING;
    itemInfo.dwTypeData = "Clear list";
	itemInfo.cch = strlen("Clear list");
	itemInfo.wID = ID_CLEAR_LIST;
		   
	InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &itemInfo);

   }
   else {

	   count = GetMenuItemCount(menu);

	   for(i=0; i<count; i++)
		   RemoveMenu(menu, 0, MF_BYPOSITION);

	   itemInfo.cbSize = sizeof(MENUITEMINFO);
	itemInfo.fMask  = MIIM_DATA | MIIM_TYPE | MIIM_ID;
    itemInfo.fType  = MFT_STRING;
    itemInfo.dwTypeData = "No recent files...";
    itemInfo.cch = strlen("No recent files...");
    itemInfo.wID = ID_RECENT_FILE1;
		   
	InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &itemInfo);
	EnableMenuItem(menu, ID_RECENT_FILE1, MF_GRAYED);
   }

}

/**************************************************************************************
 *                                                                                    *
 * - UpdateRecentFilesMenu():                                                         *
 *                                                                                    *
 *   ———加入(如果可以)一个条目到文件链表                                         *
 *                                                                                    *
 **************************************************************************************/

void UpdateRecentFilesMenu(char *filename)
{
	DWORD i;
	DWORD insert = 1;

	for(i=0; i < 5; i++) {
				
		if(RecentFiles[i] != NULL && strcmp(RecentFiles[i], filename) == 0) {
			insert = 0;
		}
	}

	if(insert) {
		
		for(i=4; i > 0; i--) {
				
			RecentFiles[i] = RecentFiles[i - 1];
		}

		RecentFiles[0] = (char *) new char[(strlen(filename) + 1)];
		strncpy(RecentFiles[0], filename, strlen(filename));
		RecentFiles[0][strlen(filename)] = '\0';
	}
}


/**************************************************************************************
 *                                                                                    *
 * - PreparesDesktopMode():                                                           *
 *                                                                                    *
 *   ———设置桌面模式                                                               *
 *                                                                                    *
 **************************************************************************************/

void PrepareDesktopMode() {

	HRESULT hr;
	IActiveDesktop *pActiveDesktop;

	/*
	 * 活动桌面填充
	 * --------------------
	 */

	hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
					      IID_IActiveDesktop, (void**)&pActiveDesktop);


	if(hr == S_OK) {

		wchar_t *wstr;

		pActiveDesktop->GetWallpaper((LPWSTR) &wallpaper, MAX_PATH, 0);
		pActiveDesktop->GetPattern((LPWSTR) &pattern, MAX_PATH, 0);

		wstr = (wchar_t *) new char[2*MAX_PATH];
		mbtowc(wstr, "None", MAX_PATH);
		pActiveDesktop->SetWallpaper((WCHAR *) wstr, 0);
		pActiveDesktop->SetPattern((WCHAR *) wstr, 0);
	
		pActiveDesktop->ApplyChanges(AD_APPLY_ALL);

		pActiveDesktop->Release();
	}

	/*
	 * 标准填充
	 * --------------
	 */

	COLORREF colorref;
	INT      background;

	background = COLOR_DESKTOP;
	colorref   = DD_OVERLAY_COLORREF;

	/*
	 * 得到设置
	 */

	backColor = GetSysColor(COLOR_DESKTOP);
				
	/*
	 * 设置
	 */

	SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "", 0);
	SetSysColors(1, &background, &colorref);
}

/**************************************************************************************
 *                                                                                    *
 * - UnPreparesDesktopMode():                                                         *
 *                                                                                    *
 *   ———取消桌面模式的设置                                                         *
 *                                                                                    *
 **************************************************************************************/

void UnPrepareDesktopMode() {

	HRESULT hr;
	IActiveDesktop *pActiveDesktop;

	/*
	 * 活动桌面填充
	 * --------------------
	 */

	hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
					      IID_IActiveDesktop, (void**)&pActiveDesktop);


	if(hr == S_OK) {

		pActiveDesktop->SetWallpaper(wallpaper, 0);
		pActiveDesktop->SetPattern(pattern, 0);
	
		pActiveDesktop->ApplyChanges(AD_APPLY_ALL);

		pActiveDesktop->Release();
	}

	/*
	 * API填充
	 */

	INT background = COLOR_DESKTOP;
		
	SetSysColors(1, &background, &backColor);
	SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, NULL, 0);

	playback->SetDesktopMode(FALSE);
}

/**************************************************************************************
 *                                                                                    *
 * - PrepareCompactMode():                                                            *
 *                                                                                    *
 *   ———设置桌面模型                                                               *
 *                                                                                    *
 **************************************************************************************/

void PrepareCompactMode() {

	HMENU        menu;
	MENUITEMINFO itemInfo;

	menu = GetSubMenu(popupMenu, 0);

	memset(&itemInfo, 0, sizeof(MENUITEMINFO));
	
	itemInfo.cbSize     = sizeof(MENUITEMINFO);
	itemInfo.fType      = MFT_STRING;
	itemInfo.fMask      = MIIM_TYPE;
	itemInfo.dwTypeData = "&Standard Mode\tAlt+C";
		
	SetMenuItemInfo(menu, ID_COMPACT, FALSE, &itemInfo);
}

/**************************************************************************************
 *                                                                                    *
 * - UnPrepareCompactMode():                                                          *
 *                                                                                    *
 *   ———取消桌面模式的设置                                                         *
 *                                                                                    *
 **************************************************************************************/

void UnPrepareCompactMode() {

	HMENU        menu;
	MENUITEMINFO itemInfo;
	
	compact_mode = 0;
	skin->SetCompact(FALSE);

	/*
	 * 改变菜单项文本
	 */	

	menu = GetSubMenu(popupMenu, 0);

	memset(&itemInfo, 0, sizeof(MENUITEMINFO));

	itemInfo.cbSize     = sizeof(MENUITEMINFO);
	itemInfo.fType      = MFT_STRING;
	itemInfo.fMask      = MIIM_TYPE;
	itemInfo.dwTypeData = "&Compact Mode\tAlt+C";

	SetMenuItemInfo(menu, ID_COMPACT, FALSE, &itemInfo);

	/*
	 * 调整窗口大小
	 */

	GetWindowRect(hwnd, &windowRect);
	
	MoveWindow( hwnd, windowRect.left - 7, 
				windowRect.top - 22, 
				cwindowRect.right - cwindowRect.left, 
				cwindowRect.bottom - cwindowRect.top, TRUE);
				
	playback->SetVideoRect(skin->GetVideoRect());
}

/**************************************************************************************
 *                                                                                    *
 * - ChangeMenuForNormalMode():                                                       *
 *                                                                                    *
 *   ———重新产生播放链表浮动菜单                                                   *
 *                                                                                    *
 **************************************************************************************/

void ChangeMenuForNormalMode() 
{
	HMENU menu;

	menu = GetSubMenu(popupMenu, 0);

	/*
	 * 字幕及其属性菜单
	 */

	MENUITEMINFO itemInfo;
				
	/*
	 * 更新菜单项
	 */

	EnableMenuItem(popupMenu, ID_COMPACT, MF_ENABLED);
	EnableMenuItem(popupMenu, ID_FULLSCREEN, MF_ENABLED);

	EnableMenuItem(popupMenu, (UINT)ID_ON_TOP,      MF_ENABLED);

	EnableMenuItem(popupMenu, (UINT)ID_ASPECT_ORIGINAL, MF_ENABLED);
	EnableMenuItem(popupMenu, (UINT)ID_ASPECT_FREE,     MF_ENABLED);
	EnableMenuItem(popupMenu, (UINT)ID_ASPECT_43,       MF_ENABLED);
	EnableMenuItem(popupMenu, (UINT)ID_ASPECT_169,      MF_ENABLED);
	EnableMenuItem(popupMenu, (UINT)ID_ASPECT_CUSTOM,   MF_ENABLED);

	menu = GetSubMenu(popupMenu, 0);

	memset(&itemInfo, 0, sizeof(MENUITEMINFO));
	
	itemInfo.cbSize     = sizeof(MENUITEMINFO);
	itemInfo.fType      = MFT_STRING;
	itemInfo.fMask      = MIIM_TYPE;
	itemInfo.dwTypeData = "&Desktop mode\tAlt+D";
		
	SetMenuItemInfo(menu, ID_DESKTOP, FALSE, &itemInfo);

	EnableMenuItem(popupMenu, (UINT)ID_PROPERTIES,      MF_ENABLED);
	EnableMenuItem(popupMenu, (UINT)ID_DESKTOP,         MF_ENABLED);
}

/**************************************************************************************
 *                                                                                    *
 * - ChangeMenuForFullscreenlMode():                                                  *
 *                                                                                    *
 *   ———重新产生播放链表浮动菜单                                                   *
 *                                                                                    *
 **************************************************************************************/

void ChangeMenuForFullscreenMode() 
{
	HMENU        menu;
	MENUITEMINFO itemInfo;

	GetWindowRect(hwnd, &fullwindowRect);

	/*
	 * 使某些项无效
	 */

	EnableMenuItem(popupMenu, ID_COMPACT, MF_GRAYED);
	EnableMenuItem(popupMenu, ID_FULLSCREEN, MF_GRAYED);
	
	EnableMenuItem(popupMenu, (UINT)ID_ON_TOP,      MF_GRAYED);

	EnableMenuItem(popupMenu, (UINT)ID_ASPECT_ORIGINAL, MF_GRAYED);
	EnableMenuItem(popupMenu, (UINT)ID_ASPECT_FREE,     MF_GRAYED);
	EnableMenuItem(popupMenu, (UINT)ID_ASPECT_43,       MF_GRAYED);
	EnableMenuItem(popupMenu, (UINT)ID_ASPECT_169,      MF_GRAYED);
	EnableMenuItem(popupMenu, (UINT)ID_ASPECT_CUSTOM,   MF_GRAYED);

	menu = GetSubMenu(popupMenu, 0);

	memset(&itemInfo, 0, sizeof(MENUITEMINFO));
	
	itemInfo.cbSize     = sizeof(MENUITEMINFO);
	itemInfo.fType      = MFT_STRING;
	itemInfo.fMask      = MIIM_TYPE;
	itemInfo.dwTypeData = "Go back to normal mode\tAlt+Enter";
		
	SetMenuItemInfo(menu, ID_DESKTOP, FALSE, &itemInfo);
}

/**************************************************************************************
 *                                                                                    *
 * - ReBuildPlaylistMenu():                                                           *
 *                                                                                    *
 *   ———重新产生播放链表浮动菜单                                            *
 *                                                                                    *
 **************************************************************************************/

void ReBuildPlaylistMenu()
{
	HMENU menu;
	DWORD i;
	DWORD count;
	MENUITEMINFO itemInfo;

	menu = GetSubMenu(GetSubMenu(GetSubMenu(popupMenu, 0), 9), 0);

	count = GetMenuItemCount(menu);

	for(i=0; i < count; i++) {
						
		RemoveMenu(menu, 0, MF_BYPOSITION);				
	}

	/*
	 * 增加标准项
	 *
	 */

	itemInfo.cbSize = sizeof(MENUITEMINFO);
	itemInfo.fMask  = MIIM_DATA | MIIM_TYPE | MIIM_ID;
	itemInfo.fType  = MFT_STRING;
	itemInfo.dwTypeData = "Add Files...\tAlt+A";
	itemInfo.cch = strlen("Add Files...\tAlt+A");
	itemInfo.wID = ID_MENU_PLAYBACK_FILES_ADDFILES;
		   
	InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &itemInfo);

	itemInfo.cbSize = sizeof(MENUITEMINFO);
	itemInfo.fMask  = MIIM_DATA | MIIM_TYPE | MIIM_ID;
	itemInfo.fType  = MFT_SEPARATOR;
	itemInfo.dwTypeData = "-";
	itemInfo.cch = strlen("-");
	itemInfo.wID = 0;
		   
	InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &itemInfo);


	/*
	 * 增加文件
	 */
   
    for(i=0; i < playlist->GetItemCount(); i++) {
	   
		char *name;

		if(strrchr(playlist->GetItemAt(i)->filename, '\\') != NULL) {

			name = strrchr(playlist->GetItemAt(i)->filename, '\\') + 1;
		}
		else {

			name = playlist->GetItemAt(i)->filename;
		}

	  itemInfo.cbSize     = sizeof(MENUITEMINFO);
	  itemInfo.fMask      = MIIM_DATA | MIIM_TYPE | MIIM_ID;
	  itemInfo.fType      = MFT_STRING;
	  itemInfo.dwTypeData = name;
	  itemInfo.cch        = strlen(name);
	  itemInfo.wID        = ID_PLAYLIST1 + i;
	  itemInfo.dwItemData = i;
		   
	  InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &itemInfo);
   }

	/*
	 * 选择当前的项
	 *
	 */

	CheckMenuItem(menu, ID_PLAYLIST1 + playlist->GetCurrentPosition(), MF_CHECKED);
}

/**************************************************************************************
 *                                                                                    *
 * - UpdateMainWindow():                                                              *
 *                                                                                    *
 *   ———重新绘制主窗口                                                             *
 *                                                                                    *
 **************************************************************************************/

void UpdateMainWindow()
{
	RECT rect;

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

/**************************************************************************************
 *                                                                                    *
 *                                      退出                                          *
 *                                    --------                                        *
 **************************************************************************************/

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

	if(playback->desktopMode) {

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

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

	Cleanup();

	PostQuitMessage(0);
}

/**************************************************************************************
 *                                                                                    *
 * - WinMain():                                                                       *
 *                                                                                    *
 *   ———程序入口                                                                   *
 *                                                                                    *
 **************************************************************************************/

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)

⌨️ 快捷键说明

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