if(CView::OnCreate(lpCreateStruct)==-1)
return -1;
TCHAR szFilePath[MAX_PATH + 1];
GetModuleFileName(NULL, szFilePath, MAX_PATH);
(_tcsrchr(szFilePath, '\\'))[1] = '\0'; //删除文件名,只获得路径
CString str_url = szFilePath;
str_url += "roll.swf";
/*m_cflash.CoInitialize(NULL); */
m_cflash.Create(NULL,"飞行棋", WS_CHILD|WS_VISIBLE, CRect(650, 50, 770, 168), this, FLASHID);
m_cflash.put_Movie(str_url);
m_cflash.Stop();
m_cflash.put_ScaleMode(1);
明明路径什么的也有了,,为什么flash播放不了呢??只是一块白色的区域
注:我的flash意图在窗口上的一块区域内运行
return -1;
TCHAR szFilePath[MAX_PATH + 1];
GetModuleFileName(NULL, szFilePath, MAX_PATH);
(_tcsrchr(szFilePath, '\\'))[1] = '\0'; //删除文件名,只获得路径
CString str_url = szFilePath;
str_url += "roll.swf";
/*m_cflash.CoInitialize(NULL); */
m_cflash.Create(NULL,"飞行棋", WS_CHILD|WS_VISIBLE, CRect(650, 50, 770, 168), this, FLASHID);
m_cflash.put_Movie(str_url);
m_cflash.Stop();
m_cflash.put_ScaleMode(1);
明明路径什么的也有了,,为什么flash播放不了呢??只是一块白色的区域
注:我的flash意图在窗口上的一块区域内运行
解决方案 »
- 编辑框设置
- VC中用什么办法可以实现能够加载gif,bmp,ico,png,jpg图像,并且将它的句柄放到HBITMAP中返回
- 高分提问关于特征提取的问题,望高手指教了
- 这样使用常量字符串会不会有危险?
- 如何将实现将本地的文件上传到服务器?怎样实现?谢谢
- 怎样在一个外部应用程序的窗口文本框中输入文字?(好像很难啊?)
- 谁能提供VC开发的usb通信程序
- 一个关于广播的问题(请问下面这段代码能发送广播包吗?如果能发送,接受方如何操作?
- 《C++ Primer》简体中文版何时出版?谁译的?
- 多线程中主程序退出时,别的线成还在while(TRUE)中怎么办呀?
- 通讯录的问题
- 给基于对话框的应用程序加菜单
CString str_url = szFilePath;
str_url += "roll.swf";
===============
这一段获取的路径可能有问题,断点调试一下
// PlayerDlg.cpp : implementation file
//#include "stdafx.h"
#include "Player.h"
#include "PlayerDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CPlayerDlg dialogCPlayerDlg::CPlayerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPlayerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPlayerDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_pFlash = NULL;
mSourceFile = "";
mSliderTimer = 0;
mCountTimer = 0;
}void CPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPlayerDlg)
DDX_Control(pDX, IDC_STATIC_TIS, m_Tis);
DDX_Control(pDX, IDC_VIDEO_WINDOW, mVideoWindow);
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CPlayerDlg, CDialog)
//{{AFX_MSG_MAP(CPlayerDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_OPEN, OnBtnOpen)
ON_BN_CLICKED(IDC_BTN_PLAY, OnBtnPlay)
ON_BN_CLICKED(IDC_BTN_PAUSE, OnBtnPause)
ON_BN_CLICKED(IDC_BTN_STOP, OnBtnStop)
ON_WM_TIMER()
ON_WM_HSCROLL()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_GETMINMAXINFO()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()BEGIN_EVENTSINK_MAP(CPlayerDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CPlayerDlg)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()/////////////////////////////////////////////////////////////////////////////
// CPlayerDlg message handlersBOOL CPlayerDlg::OnInitDialog()
{
CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
mVideoWindow.ModifyStyle(0, WS_CLIPCHILDREN); VERIFY(m_FrameScrollBar.CreateFromStatic(
SBS_HORZ|WS_CHILD|SS_LEFT|SS_NOTIFY|WS_VISIBLE,
this, IDC_SCROLL_RECT_HORZ, IDC_SCROLL_HORZ));
m_FrameScrollBar.SetScrollRange(0, 1000);
m_FrameScrollBar.SetScrollPos(0);
m_FrameScrollBar.SetThumbColor(RGB(198,97,239)); SetWindowPos(NULL,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,SWP_NOZORDER); ResetSize(); mCountTimer=SetTimer(Count_TIMER,100,NULL); return TRUE; // return TRUE unless you set the focus to a control
}// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.void CPlayerDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPlayerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}void CPlayerDlg::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}void CPlayerDlg::OnCancel()
{
// TODO: Add extra cleanup here
int nChoice=MessageBox("您确定要退出程序吗?","确认",MB_OKCANCEL|MB_DEFBUTTON2|MB_ICONINFORMATION);
if(nChoice!=IDOK)
return; CDialog::OnCancel();
}void CPlayerDlg::OnBtnOpen()
{
CString strFilter = "";
//strFilter += "FLASH File (*.swf)|*.swf|";
CFileDialog dlgOpen(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,
strFilter, this);
if (IDOK == dlgOpen.DoModal())
{
mSourceFile = dlgOpen.GetPathName();
DestroyFlash();
CreateFlash(); OnBtnPlay();
}
}void CPlayerDlg::OnBtnPlay()
{
if(m_pFlash){
m_pFlash->Play(); if (mSliderTimer == 0)
mSliderTimer = SetTimer(SLIDER_TIMER, 100, NULL);
}
}void CPlayerDlg::OnBtnPause()
{
if(m_pFlash){
m_pFlash->Stop(); if (mSliderTimer == 0)
mSliderTimer = SetTimer(SLIDER_TIMER, 100, NULL);
}
}void CPlayerDlg::OnBtnStop()
{
if(m_pFlash){
m_pFlash->Rewind();
m_pFlash->Stop();
if (mSliderTimer){
KillTimer(mSliderTimer);
mSliderTimer = 0;
}
m_FrameScrollBar.SetScrollPos(0);
}
}void CPlayerDlg::CreateFlash(void)
{
mVideoWindow.ShowWindow(FALSE);
m_pFlash=new CShockwaveFlash();
m_pFlash->Create(NULL,WS_CHILD|WS_VISIBLE,CRect(0,0,10,10),this,IDC_VIDEO_WINDOW);
//m_pFlash->Create(NULL,WS_CHILD|WS_VISIBLE,CRect(0,0,10,10),this,NULL);
m_pFlash->LoadMovie(0,mSourceFile);
ResetSize();
}void CPlayerDlg::DestroyFlash(void)
{
if (m_pFlash){
m_pFlash->Stop();
delete m_pFlash;
m_pFlash=NULL;
}
}void CPlayerDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (nIDEvent == mSliderTimer){
if(m_pFlash){
int nFrameCurrent=m_pFlash->CurrentFrame();
int nFrameTotal=m_pFlash->GetTotalFrames();
int newPos = int(nFrameCurrent * 1000 / nFrameTotal);
if (m_FrameScrollBar.GetScrollPos() != newPos)
m_FrameScrollBar.SetScrollPos(newPos);
}
} if(nIDEvent == mCountTimer){
if(m_pFlash){
int nFrameCurrent=m_pFlash->CurrentFrame();
int nFrameTotal=m_pFlash->GetTotalFrames();
CString str;
str.Format("%9d/%-9d",nFrameCurrent,nFrameTotal);
m_Tis.SetWindowText(str);
}
} CDialog::OnTimer(nIDEvent);
}void CPlayerDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if (pScrollBar->GetSafeHwnd() == m_FrameScrollBar.GetSafeHwnd()){
if(m_pFlash){
long pos=m_pFlash->GetTotalFrames() * m_FrameScrollBar.GetScrollPos() / 1000;
m_pFlash->SetFrameNum(pos);
}
}
}BOOL CPlayerDlg::DestroyWindow()
{
if (mSliderTimer){
KillTimer(mSliderTimer);
mSliderTimer = 0;
} if(mCountTimer){
KillTimer(mCountTimer);
mCountTimer=0;
} DestroyFlash(); return CDialog::DestroyWindow();
}void CPlayerDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
ResetSize();
}void CPlayerDlg::ResetSize()
{
CRect reWindow;
CRect reVideo,reTis,reScrollBar,reButton;
GetClientRect(reWindow);
if(mVideoWindow.GetSafeHwnd()){
reVideo.left=reWindow.left+5;
reVideo.right=reWindow.right-5;
reVideo.top=reWindow.top+5;
reVideo.bottom=reWindow.bottom-55;
mVideoWindow.MoveWindow(reVideo); if(m_pFlash)
m_pFlash->MoveWindow(reVideo);
}
if(m_Tis.GetSafeHwnd()){
reTis.left=reWindow.left+5;
reTis.right=reWindow.right-5;
reTis.top=reVideo.bottom+2;
reTis.bottom=reTis.top+10;
m_Tis.MoveWindow(reTis);
} if(m_FrameScrollBar.GetSafeHwnd()){
reScrollBar.left=reWindow.left+5;
reScrollBar.right=reWindow.right-5;
reScrollBar.top=reTis.bottom+5;
reScrollBar.bottom=reScrollBar.top+7;
m_FrameScrollBar.ResetWidth(reScrollBar.Width());
m_FrameScrollBar.MoveWindow(reScrollBar);
CRect rect;
int n=5;
GetDlgItem(IDC_BTN_OPEN)->GetWindowRect(&reButton);
rect.left=(reWindow.Width()-4*reButton.Width()-3*n)/2;
rect.right=rect.left+reButton.Width();
rect.bottom=reWindow.bottom-2;
rect.top=rect.bottom-reButton.Height();
GetDlgItem(IDC_BTN_OPEN)->MoveWindow(rect);
rect.left=rect.right+n;
rect.right=rect.left+reButton.Width();
GetDlgItem(IDC_BTN_PLAY)->MoveWindow(rect);
rect.left=rect.right+n;
rect.right=rect.left+reButton.Width();
GetDlgItem(IDC_BTN_PAUSE)->MoveWindow(rect);
rect.left=rect.right+n;
rect.right=rect.left+reButton.Width();
GetDlgItem(IDC_BTN_STOP)->MoveWindow(rect);
} Invalidate();
}CString CPlayerDlg::GetTimeStr(int nTime)
{
CString result="";
CString str1="00",str2="00",str3="00";
int temp; if(nTime>=3600){
temp=nTime/3600;
nTime=nTime%3600;
if(temp>9)
str1.Format("%d",temp);
else
str1.Format("0%d",temp);
}
if(nTime>=60){
temp=nTime/60;
nTime=nTime%60;
if(temp>9)
str2.Format("%d",temp);
else
str2.Format("0%d",temp);
}
if(nTime>9)
str3.Format("%d",nTime);
else if(nTime<1)
str3.Format("00");
else
str3.Format("0%d",nTime); result.Format("%s:%s:%s",str1,str2,str3); return result;
}void CPlayerDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// TODO: Add your message handler code here and/or call default
CRect rectWindow;
GetWindowRect(&rectWindow);
CRect rectClient;
GetClientRect(&rectClient); int nWidthOffset = rectWindow.Width() - rectClient.Width();
int nHeightOffset = rectWindow.Height() - rectClient.Height(); lpMMI->ptMinTrackSize.x = MINX + nWidthOffset;
lpMMI->ptMinTrackSize.y = MINY + nHeightOffset; CDialog::OnGetMinMaxInfo(lpMMI);
}
还得:
m_pFlash->LoadMovie(0,mSourceFile);
之后调用函数播放m_pFlash->Play();