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

📄 playerdlg.cpp

📁 一个自己编的Flashplayer
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	GetMenu()->GetSubMenu(1)->GetSubMenu(8)->CheckMenuItem(2,MF_BYPOSITION  |MF_UNCHECKED);
}

void CPlayerDlg::OnQualityMedium() 
{
	// TODO: Add your command handler code here
	m_Flash.SetQuality2("Medium");
	GetMenu()->GetSubMenu(1)->GetSubMenu(8)->CheckMenuItem(1,MF_BYPOSITION  |MF_CHECKED);
	GetMenu()->GetSubMenu(1)->GetSubMenu(8)->CheckMenuItem(0,MF_BYPOSITION  |MF_UNCHECKED);
	GetMenu()->GetSubMenu(1)->GetSubMenu(8)->CheckMenuItem(2,MF_BYPOSITION  |MF_UNCHECKED);
}


void CPlayerDlg::OnUpdateZoomout(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((m_Flash.GetMovie()=="")||!ZoomFlag)
		pCmdUI->Enable(false);
	else
		pCmdUI->Enable(true);
	
	
}


void CPlayerDlg::OnUpdateZoomin(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CString str=m_Flash.GetMovie();
	if ((str=="")||(str=="http://"))
		pCmdUI->Enable(false);
	else
		pCmdUI->Enable(true);
}

void CPlayerDlg::OnUpdateClose(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CString str=m_Flash.GetMovie();
	if ((str=="")||(str=="http://"))
		pCmdUI->Enable(false);
	else
		pCmdUI->Enable(true);
}

void CPlayerDlg::OnPrint() 
{
	// TODO: Add your command handler code here
	//dc.LPtoDP(&rect);
	m_Flash.Stop();
		CFileDialog SavebmpDialog(false,".bmp",NULL,
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ENABLESIZING,
		"位图文件|*.bmp",this);
	SavebmpDialog.m_ofn.lStructSize=88;
	SavebmpDialog.m_ofn.lpstrTitle="保存bmp文件";
	//OpenSWFDialog.m_ofn.lpstrInitialDir="c:";
	if (IDOK==SavebmpDialog.DoModal())
	{
		//MessageBox(OpenSWFDialog.GetPathName());
		//LoadFlash(OpenSWFDialog.GetPathName());
	m_Flash.UpdateWindow();
	capture(&m_Flash);
	SaveBitmapToFile(*m_pBitmap,SavebmpDialog.GetPathName());
	delete(m_pBitmap);
	}

	m_Flash.Play();
}

void CPlayerDlg::OnUpdateViewall(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CString str=m_Flash.GetMovie();
	if ((str=="")||(str=="http://"))
		pCmdUI->Enable(false);
	else
		pCmdUI->Enable(true);
}

void CPlayerDlg::OnUpdate100(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CString str=m_Flash.GetMovie();
	if ((str=="")||(str=="http://"))
		pCmdUI->Enable(false);
	else
		pCmdUI->Enable(true);
}

void CPlayerDlg::OnUpdateFullscreen(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CString str=m_Flash.GetMovie();
	if ((str=="")||(str=="http://"))
		pCmdUI->Enable(false);
	else
		pCmdUI->Enable(true);
}

void CPlayerDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	CRect ct;
	GetClientRect(&ct);

	if(m_Flash.GetSafeHwnd()) 
	{
		if (!m_bPlayList)
		{
			m_Flash.MoveWindow(0,0,ct.Width(),ct.Height()-70);
			m_slider.MoveWindow(0,ct.bottom-50,ct.Width(),30);
			m_strslider.MoveWindow(ct.right-110,ct.bottom-60,100,10);
		}
		else
		{
			m_slider.MoveWindow(0,ct.bottom-50,ct.Width(),30);
			m_strslider.MoveWindow(ct.right-110,ct.bottom-60,100,10);
			m_Flash.MoveWindow(0,ct.top,ct.Width()-100,ct.Height()-70);
			m_CtrList.MoveWindow(ct.right-98,0,98,ct.Height()-70);	
			m_xSplitter.MoveWindow(ct.right-100,0,2,ct.Height()-70);
		}
		
	}

	
}

void CPlayerDlg::LoadFlash(CString FileName)
{
	if( (_access(FileName,0)) == -1 )
	{
		AfxMessageBox("文件不存在");
		return;
	}
	m_Flash.SetMovie(FileName);
	m_nTimer=SetTimer(1,100,0);
	TimerFlag=true;
	m_slider.SetRange(0,m_Flash.GetTotalFrames());
	SetWindowText(FileName);
	
}

void CPlayerDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if (TimerFlag)
	m_slider.SetPos(m_Flash.CurrentFrame());
		CString tip;
	tip.Format("%d/%d",m_Flash.CurrentFrame(),m_Flash.GetTotalFrames());
	m_strslider.SetWindowText(tip);
	CDialog::OnTimer(nIDEvent);
}

BOOL CPlayerDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	if (TimerFlag)
	{
		KillTimer(m_nTimer);
	}
	 m_xSplitter.Unbind();
	return CDialog::DestroyWindow();
}
void CPlayerDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	int num=m_slider.GetPos();
	m_Flash.GotoFrame(num);
	m_Flash.Play();
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);

}



BOOL CPlayerDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST)
	{
		if (m_acc && ::TranslateAccelerator(m_hWnd, m_acc, pMsg))
		return TRUE;
	}//加速键处理
	if (pMsg->hwnd==m_Flash.m_hWnd&&pMsg->message==WM_RBUTTONDOWN)
	{
		CPoint pt(GET_X_LPARAM(pMsg->lParam),GET_Y_LPARAM(pMsg->lParam));
		ClientToScreen(&pt);
		 CMenu rmenu;
		 rmenu.LoadMenu(IDR_RIGHTMENU);
		rmenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON,pt.x,
			pt.y,this);

		return true;
	}
	if(pMsg->message == WM_KEYDOWN) 
	{
		  if(pMsg->wParam==VK_ESCAPE)
		  {
			 
				   if(ScreenFlag)
				   {
						   HWND hwnd=this->GetSafeHwnd();
						   LONG style=GetWindowLong(hwnd,GWL_STYLE);
						   SetWindowLong(hwnd,GWL_STYLE,style+WS_CAPTION );
						   ShowWindow(SW_HIDE);
						   SetWindowPlacement(&m_WndPos);
						   m_Flash.MoveWindow(FlashRect.left,FlashRect.top,FlashRect.Width(),FlashRect.Height(),1);
						   m_Flash.SetWindowPlacement(&m_FlashPos);
						   ScreenFlag=FALSE;
							m_slider.ShowWindow(SW_SHOW );
							m_strslider.ShowWindow(SW_SHOW);
							          CMenu   menu;   
								  menu.LoadMenu(IDR_MENU1);
								  SetMenu(&menu);   
								 DrawMenuBar();   
								  menu.Detach();   
							return true;
				   }
		  }
		  if (pMsg->wParam==VK_RETURN)
		  {
			  if (m_Flash.IsPlaying())
					m_Flash.Stop();
				else
					m_Flash.Play();
			  return true;
		  }
	}

	return CDialog::PreTranslateMessage(pMsg);
	
}

void CPlayerDlg::OnUpdatePrint(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
		CString str=m_Flash.GetMovie();
	if ((str=="")||(str=="http://"))
		pCmdUI->Enable(false);
	else
		pCmdUI->Enable(true);
}

//////////////////////////////////////////////
void CPlayerDlg::capture(CWnd* pParent )
{
  //指定范围(相对窗口)  
  CRect rect;
  pParent->GetClientRect(&rect);
  CPaintDC   dc(pParent);   
  m_pBitmap=new   CBitmap;   
  m_pBitmap->CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());   
  CDC   memDC;   
  memDC.CreateCompatibleDC(&dc);   
  memDC.SelectObject(m_pBitmap);   
  memDC.StretchBlt(0,   0,   rect.Width(),rect.Height(),   &dc,   
  rect.left,   rect.top,   rect.Width(),rect.Height(),   SRCCOPY);   
  memDC.DeleteDC();   
  //m_pBitmap指向的CBitmap保存了截取的图像   
}

int CPlayerDlg::SaveBitmapToFile(HBITMAP hBitmap, CString lpFileName) //hBitmap 为刚才的屏幕位图句柄
{      //lpFileName 为位图文件名
 HDC     hDC;         
    //设备描述表
 int     iBits;      
 //当前显示分辨率下每个像素所占字节数
 WORD    wBitCount;   
    //位图中每个像素所占字节数
 //定义调色板大小, 位图中像素字节大小 ,  位图文件大小 , 写入文件字节数
 DWORD           dwPaletteSize=0,dwBmBitsSize,dwDIBSize, dwWritten;
 BITMAP          Bitmap;        
 //位图属性结构
 BITMAPFILEHEADER   bmfHdr;        
 //位图文件头结构
 BITMAPINFOHEADER   bi;            
 //位图信息头结构 
 LPBITMAPINFOHEADER lpbi;          
 //指向位图信息头结构
    HANDLE          fh, hDib, hPal;
 HPALETTE     hOldPal=NULL;
 //定义文件,分配内存句柄,调色板句柄
 
 //计算位图文件每个像素所占字节数
 hDC = CreateDC("DISPLAY",NULL,NULL,NULL);
 iBits = GetDeviceCaps(hDC, BITSPIXEL) * 
  GetDeviceCaps(hDC, PLANES);
 DeleteDC(hDC);
 if (iBits <= 1)
  wBitCount = 1;
 else if (iBits <= 4)
  wBitCount = 4;
 else if (iBits <= 8)
  wBitCount = 8;
 else if (iBits <= 24)
  wBitCount = 24;
else
  wBitCount = 32;
 //计算调色板大小
 if (wBitCount <= 8)
  dwPaletteSize=(1<<wBitCount)*sizeof(RGBQUAD);
 
 //设置位图信息头结构
 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);
 bi.biSize            = sizeof(BITMAPINFOHEADER);
 bi.biWidth           = Bitmap.bmWidth;
 bi.biHeight          = Bitmap.bmHeight;
 bi.biPlanes          = 1;
 bi.biBitCount         = wBitCount;
 bi.biCompression      = BI_RGB;
 bi.biSizeImage        = 0;
 bi.biXPelsPerMeter     = 0;
 bi.biYPelsPerMeter     = 0;
 bi.biClrUsed         = 0;
 bi.biClrImportant      = 0;
 
 dwBmBitsSize = ((Bitmap.bmWidth*wBitCount+31)/32)*4*Bitmap.bmHeight;
 //为位图内容分配内存

/*xxxxxxxx计算位图大小分解一下(解释一下上面的语句)xxxxxxxxxxxxxxxxxxxx 
//每个扫描行所占的字节数应该为4的整数倍,具体算法为:
 int biWidth = (Bitmap.bmWidth*wBitCount) / 32;
 if((Bitmap.bmWidth*wBitCount) % 32)
  biWidth++; //不是整数倍的加1
 biWidth *= 4;//到这里,计算得到的为每个扫描行的字节数。
 dwBmBitsSize = biWidth * Bitmap.bmHeight;//得到大小
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/


 hDib  = GlobalAlloc(GHND,dwBmBitsSize+dwPaletteSize+sizeof(BITMAPINFOHEADER));
 lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib);
 *lpbi = bi;
 // 处理调色板   
 hPal = GetStockObject(DEFAULT_PALETTE);
 if (hPal)
 {
  hDC = ::GetDC(NULL);
  hOldPal=SelectPalette(hDC,(HPALETTE)hPal,FALSE);
  RealizePalette(hDC);
 }
 // 获取该调色板下新的像素值
 GetDIBits(hDC,hBitmap,0,(UINT)Bitmap.bmHeight,(LPSTR)lpbi+sizeof(BITMAPINFOHEADER)+dwPaletteSize, (BITMAPINFO *)lpbi,DIB_RGB_COLORS);
 //恢复调色板   
 if (hOldPal)
 {
  SelectPalette(hDC, hOldPal, TRUE);
  RealizePalette(hDC);
  ::ReleaseDC(NULL, hDC);
 }
 //创建位图文件    
 fh=CreateFile(lpFileName, GENERIC_WRITE,0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
 if (fh==INVALID_HANDLE_VALUE)
  return FALSE;
 // 设置位图文件头
 bmfHdr.bfType = 0x4D42;  // "BM"
 dwDIBSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+dwPaletteSize+dwBmBitsSize;  
 bmfHdr.bfSize = dwDIBSize;
 bmfHdr.bfReserved1 = 0;
 bmfHdr.bfReserved2 = 0;
 bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER)+(DWORD)sizeof(BITMAPINFOHEADER)+dwPaletteSize;
 // 写入位图文件头
 WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL);
 // 写入位图文件其余内容
  WriteFile(fh, (LPSTR)lpbi, sizeof(BITMAPINFOHEADER)+dwPaletteSize+dwBmBitsSize , &dwWritten, NULL); 
 //清除   
 GlobalUnlock(hDib);
 GlobalFree(hDib);
 CloseHandle(fh);
 return TRUE;
}

void CPlayerDlg::OnDropFiles(HDROP hDropInfo )
{
	UINT cFiles = ::DragQueryFile( hDropInfo, 0xffffffff, 0, 0);
  CString szText,temp;
  char szFile[MAX_PATH];
  
  for( UINT count = 0; count < cFiles; count++ )
  if(cFiles>0)
  {
	  ::DragQueryFile(hDropInfo, count, szFile, sizeof(szFile));
	  temp=szFile;
	  if(temp.Right(4)==".swf")
	  {
		  szText += szFile;//文件名存于szFile
		  szText += "\r\n";//取所有的文件到szText中,一行一个
		  LoadFlash(szFile);
		}
  }
}

void CPlayerDlg::OnPlaylist() 
{
	CRect ct;
	GetClientRect(&ct);
	// TODO: Add your command handler code here
	if (m_bPlayList)
	{
		GetMenu()->GetSubMenu(1)->CheckMenuItem(IDM_PLAYLIST,MF_BYCOMMAND |MF_UNCHECKED);
		m_CtrList.ShowWindow(SW_HIDE);
		m_xSplitter.ShowWindow(SW_HIDE);
		//m_xSplitter.Unbind();
		m_Flash.MoveWindow(0,ct.top,ct.Width(),ct.Height()-70);
		m_slider.MoveWindow(0,ct.bottom-50,ct.Width(),30);
		m_strslider.MoveWindow(ct.right-110,ct.bottom-60,100,10);
		m_bPlayList=false;
		//m_xSplitter.~CxSplitterWnd();
	}
	else
	{
		GetMenu()->GetSubMenu(1)->CheckMenuItem(IDM_PLAYLIST,MF_BYCOMMAND |MF_CHECKED);
		m_CtrList.ShowWindow(SW_RESTORE);
		m_xSplitter.ShowWindow(SW_RESTORE);

		m_xSplitter.BindWithControl(this, IDC_SPLITTER);
		m_xSplitter.SetMinWidth(50, 100);
		m_xSplitter.AttachAsLeftPane(IDC_FLASH);
		m_xSplitter.AttachAsRightPane(IDC_LIST1);
		m_xSplitter.RecalcLayout();
		m_Flash.MoveWindow(0,ct.top,ct.Width()-100,ct.Height()-70);
		m_CtrList.MoveWindow(ct.right-98,0,98,ct.Height()-70);	
		m_xSplitter.MoveWindow(ct.right-100,0,2,ct.Height()-70);
		m_bPlayList=true;

	}


}
CString GetFileName(CString &Path)
{
	int    nPos;   
   nPos=Path.ReverseFind('\\');   
   CString temp=Path.Right(Path.GetLength()-nPos-1); 
   return temp;
}

void CPlayerDlg::OnDblclkList1() 
{
	// TODO: Add your control notification handler code here
	//LoadFlash(m_PlayList[m_CtrList.GetCurSel()]);
	
	LoadFlash(m_PlayList.GetAt(m_CtrList.GetCurSel()));
}

⌨️ 快捷键说明

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