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

📄 mingplayer.cpp

📁 一个avi格式文件的播放。 c++源码 只有文件的播放暂停等功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
		LIST *t = lpList;
		lpList = t->next;
		delete t;
	}
	// Restore.
	if (g_bFullScreen)
	{
		SendMessage(hwnd, WM_COMMAND, IDM_FULL_SCREEN, 0);
	}
	// INI file name
	char iniFileName[MAX_PATH];
	GetModuleFileName(NULL, iniFileName, sizeof(iniFileName));
	strcpy(strrchr(iniFileName, '.')+1, "ini");
	// Window Position.
	WritePrivateProfileStruct("Window", "Position", (LPVOID)&g_rcWindow, sizeof(g_rcWindow), iniFileName);
	// Open file path.
	WritePrivateProfileString("File", "Open Path", szOpenPath, iniFileName);
	// Quit
	PostQuitMessage(0);
	return 0;
}

/**
 */
LRESULT cmdToolbar(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	RECT rc;
	if (IsWindowVisible(hwndRebar)) {
		ShowWindow(hwndRebar, SW_HIDE);
		CheckMenuItem(GetMenu(hwnd), IDM_TOOLBAR, MF_UNCHECKED);
	}
	else {
		ShowWindow(hwndRebar, SW_SHOW);
		CheckMenuItem(GetMenu(hwnd), IDM_TOOLBAR, MF_CHECKED);
	}
	GetClientRect (hwnd, &rc);
	PostMessage (hwnd, WM_SIZE, 0, MAKELPARAM(rc.right, rc.bottom));
	return InvalidateRect(hwnd, NULL, false);
}

/**
 *
 */
LRESULT cmdTopMost(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	RECT rect;
	GetWindowRect(hwnd,&rect);
	if(!g_bTopMost)
	{
		g_bTopMost=TRUE;
		SetWindowPos(hwnd,HWND_TOPMOST,0,0,
			rect.right-rect.left,rect.bottom-rect.top,SWP_NOMOVE|SWP_SHOWWINDOW);
		CheckMenuItem(GetMenu(hwnd),IDM_TOP_MOST,MF_CHECKED );
	}
	else
	{
		g_bTopMost=FALSE;
		SetWindowPos(hwnd,HWND_BOTTOM,0,0,
			rect.right-rect.left,rect.bottom-rect.top,SWP_NOMOVE|SWP_SHOWWINDOW);
		CheckMenuItem(GetMenu(hwnd),IDM_TOP_MOST,MF_UNCHECKED );
		BringWindowToTop(hwnd);
	}
	return 0;
}

/**
 */
LRESULT cmdFullScreen(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	// Screen width and height.
	int screenx = GetSystemMetrics (SM_CXSCREEN);
	int screeny = GetSystemMetrics (SM_CYSCREEN);

	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));
		// Restore the window.
		if (!g_bWindowMax)
			ShowWindow(hwnd, SW_RESTORE);
		else 
			SetWindowPos(hwnd, NULL, -2, -2, screenx+4, screeny+4, SWP_NOZORDER | SWP_FRAMECHANGED);
	}
	else {
		g_bFullScreen = true;
		CheckMenuItem(GetMenu(hwnd), IDM_FULL_SCREEN, MF_CHECKED);
		SendMessage(hwndToolbar, TB_SETSTATE, IDM_FULL_SCREEN, MAKELONG(TBSTATE_CHECKED | TBSTATE_ENABLED, 0));
		// Maximize?
		g_bWindowMax = GetWindowLong (hwnd, GWL_STYLE) & WS_MAXIMIZE ? true : false;
		// Set the window's new position.
		if (!g_bWindowMax)
		{
			GetWindowRect(hwnd, &g_rcWindow);
			ShowWindow (hwnd, SW_SHOWMAXIMIZED);		
		}
		SetWindowPos (hwnd, NULL, -4-1, -42-1, screenx+8+2, screeny+46+2, SWP_NOZORDER | SWP_FRAMECHANGED);
		// Faint: bring databrowser to front.
		SetForegroundWindow(FindWindow(_T("Shell_TrayWnd"),""));
		SetForegroundWindow(hwnd);
	}
	return 0;
}

/**
 * Displays the "About" dialog box
 */
LRESULT cmdAbout(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	MessageBox(hwnd, "MiniPlayer v1.0\nCopyright _ 2001 Li Zhaoming.\nAll Rights Reserved.", szAppName, MB_OK | MB_ICONINFORMATION);
	return 0;
}

/**
 * IDM_EXIT
 */
LRESULT cmdExit(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	return SendMessage(hwnd, WM_DESTROY, 0, 0L);
}

/**
 * IDM_PLAY
 */
LRESULT cmdPlay(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	if(g_bAVI) {
		mciSendString("play thevideo window", 0, 0, 0);
	}
	else {
		mciSendString("play thevideo", 0, 0, 0);
	}
	InvalidateRect(hwndTrack, NULL, false);
	g_bPaused=FALSE;
	return 0;
}

/**
 * IDM_PAUSE
 */
LRESULT cmdPause(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	if(!g_bPaused) {
		mciSendString("pause thevideo", 0, 0, 0);
		g_bPaused=TRUE;
	}
	else {
		mciSendString("resume thevideo", 0, 0, 0);
		g_bPaused=FALSE;
	}
	return 0;
}

/**
 * IDM_STOP
 */
LRESULT cmdStop(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	mciSendString("stop thevideo", 0, 0, 0);
	mciSendString("seek thevideo to start", 0, 0, 0); 
	return 0;
}

/**
 * IDM_REWIND
 */
LRESULT cmdRewind(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	keybd_event(VK_PRIOR, 0, 0, 0);
	keybd_event(VK_PRIOR, 0, KEYEVENTF_KEYUP, 0);
	return 0;
}

/**
 * IDM_FORWARD
 */
LRESULT cmdForward(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	keybd_event(VK_NEXT, 0, 0, 0);
	keybd_event(VK_NEXT, 0, KEYEVENTF_KEYUP, 0);
	return 0;
}

/**
 *
 */
LRESULT cmdRepeat(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	if (g_bRepeat) {
		g_bRepeat = false;	
		CheckMenuItem(GetMenu(hwnd), IDM_REPEAT, MF_UNCHECKED);
	}
	else {
		g_bRepeat = true;	
		CheckMenuItem(GetMenu(hwnd), IDM_REPEAT, MF_CHECKED);
	}
	return 0;
}

/**
 * IDM_OPEN
 */
LRESULT cmdOpenFile(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
	OPENFILENAME ofn;
	static TCHAR szFileListBuffer[8192];	// String buffer especially for OFN_ALLOWMULTISELECT
	strcpy(szFileListBuffer, szOpenPath);
	static char szFile[256] = "";
	static char szFileTitle[256];
	ZeroMemory(&ofn, sizeof(OPENFILENAME));
	ofn.lStructSize=sizeof(ofn);
	ofn.hwndOwner=hwnd;
	ofn.lpstrFilter="Media Files (All Supported Types)\0*.avi;*.mpg;*.mpeg;*.asf;*.wmv;*.mp2;*.mp3\0\
Movie File (*.avi;*.mpg;*.mpeg)\0*.avi;*.mpg;*.mpeg\0\
Windows Media File (*.asf;*.wmv)\0*.asf;*.wmv\0\
Audio File (*.mp2;*.mp3)\0*.mp2;*.mp3\0\
All Files(*.*)\0*.*\0";
	ofn.nFilterIndex=0;
	ofn.lpstrFile=szFileListBuffer;
	ofn.nMaxFile=sizeof(szFileListBuffer);
	ofn.lpstrFileTitle=szFileTitle;
	ofn.nMaxFileTitle=sizeof(szFileTitle);
	ofn.lpfnHook = ofnHookProc;
	ofn.Flags = OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT |
		OFN_HIDEREADONLY | OFN_ENABLEHOOK |
		OFN_ENABLESIZING | OFN_EXPLORER;

	if(GetOpenFileName(&ofn))
	{
		LPTSTR psz = ofn.lpstrFile + ofn.nFileOffset;
		psz[-1] = _T('\\');

		while (lpList != NULL)
		{
			LIST *t = lpList;
			lpList = t->next;
			delete t;
		}
		// Loop through all files selected.
		while (*psz != 0)
		{
			int len = _tcslen(psz);
			_tcscpy(ofn.lpstrFile + ofn.nFileOffset, psz);
			psz += len + 1;

			// Now lpstrFile can be used.
			
			LIST *t = new LIST;
			t->next = NULL;
			strcpy((char *)t->file, ofn.lpstrFile);
			if (lpList == NULL)
			{
				lpList = t;
				lpListX = t;
			}
			else 
			{
				lpListX->next = t;
				lpListX = t;
			}
		}
		lpListX = lpList;
		mciSendString("close thevideo", 0, 0, 0);
		openVideoFile(hwnd, (char *)lpListX->file);
	}
	return 0;
}

/**
 *
 */
void openVideoFile(HWND hwnd, LPSTR szFileName)
{
	RECT rect;
	MCI_DGV_OPEN_PARMS  mciOpen;
	MCI_DGV_STATUS_PARMS mciStatus;
	ZeroMemory(&mciOpen,sizeof(mciOpen));
	mciStatus.dwItem=MCI_DGV_STATUS_HWND;
	mciOpen.lpstrAlias="thevideo";
	mciOpen.lpstrElementName=szFileName;
	mciOpen.hWndParent=hwnd;
	mciOpen.dwCallback=(DWORD)hwnd;
	mciOpen.dwStyle=WS_CHILD;
	if(mciSendCommand(0,MCI_OPEN,MCI_OPEN_ALIAS|MCI_OPEN_ELEMENT|
		MCI_DGV_OPEN_PARENT|MCI_DGV_OPEN_WS,(DWORD)&mciOpen)!=0)
		MessageBox(hwnd,"Can not open Media File",szAppName,
		  MB_ICONEXCLAMATION|MB_OK);
	else
	{
		uDeviceID=mciOpen.wDeviceID;
		g_bAVI = strstr(szFileName,".avi") ? TRUE : FALSE;
		mciSendCommand(uDeviceID,MCI_STATUS,MCI_STATUS_ITEM,(DWORD)&mciStatus);
		hwndVideo=(HWND)mciStatus.dwReturn;
		// Window position.
		GetClientRect(hwnd,&rect);
		SendMessage(hwnd, WM_SIZE, 0, MAKELONG(rect.right-rect.left, rect.bottom-rect.top));
		// Play
		SendMessage(hwnd, WM_COMMAND, IDM_PLAY, NULL);
		// Open file path.
		strcpy(szOpenPath, szFileName);
		// Window text.
		char title[200];
		strcpy(title, strrchr(szFileName, '\\')+1);
		strcpy(strrchr(title, '.'), "");
		strcat(title, " - ");
		strcat(title, szTitle);
		SetWindowText(hwnd,title);
	}
}

⌨️ 快捷键说明

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