递归目录里的视频文件播放问题 求助!求助!

xingyw112 2015-05-09 02:52:05
我有个问题,mfc对话框程序,递归目录扫描到视频文件, 界面上插入Windows Media Player控件 不知道怎么实现怎么双击播放 研究啦好几天也没研究明白 哪位有会的帮忙看看 我应该怎么弄 谢谢
附上递归目录代码

#include "stdafx.h"
#include "FileTree.h"
#include "FileTreeDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int flag;
CString m_pathname;
/////////////////////////////////////////////////////////////////////////////
// CFileTreeDlg dialog

CFileTreeDlg::CFileTreeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileTreeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileTreeDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFileTreeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileTreeDlg)
DDX_Control(pDX, IDC_FILETREE, m_FileTree);
DDX_Control(pDX, IDC_OCX1, m_player);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFileTreeDlg, CDialog)
//{{AFX_MSG_MAP(CFileTreeDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_Open, OnOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFileTreeDlg message handlers

BOOL CFileTreeDlg::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

m_iImageList.Create(24, 24, TRUE,1, 0);
HICON hIcon = NULL;
hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_KEBIAO), IMAGE_ICON, 24, 24, 0);
m_iImageList.Add(hIcon);
m_FileTree.SetImageList ( &m_iImageList,TVSIL_NORMAL );
BrowseDir( "成绩表", NULL );
//BrowseFile(0,"成绩表");//遍历"成绩表"文件夹内的所有目录

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 CFileTreeDlg::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 CFileTreeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CFileTreeDlg::BrowseFile(int CallNum, CString strFile)
{
CallNum++;
CFileFind ff;
CString szDir = strFile;

if(szDir.Right(1) != "\\")
szDir += "\\";

szDir += "*.*";

BOOL res = ff.FindFile(szDir);
while(res)
{
res = ff.FindNextFile();
if(ff.IsDirectory() && !ff.IsDots())
{
//如果是一个子目录,用递归继续往深一层找
CString strPath = ff.GetFilePath();
CString strTitle = ff.GetFileTitle();
int i =0;
switch(CallNum)
{
case 1:
strHTFir = m_FileTree.InsertItem(strTitle,0,0,NULL);
break;
case 2:
strHTSec = m_FileTree.InsertItem(strTitle,0,0,strHTFir);
break;
case 3:
strHtThi = m_FileTree.InsertItem(strTitle,0,0,strHTSec);
break;
case 4:
strHtFor = m_FileTree.InsertItem(strTitle,0,0,strHtThi);
break;
default:
strHtFif = m_FileTree.InsertItem(strTitle,0,0,strHtFor);
break;
}
BrowseFile(CallNum,strPath);
}
else if(!ff.IsDirectory() && !ff.IsDots())
{
//显示当前访问的文件
CString strPath;
CString strTitle;
strPath = ff.GetFilePath();
strTitle = ff.GetFileTitle();
switch(CallNum)
{
case 1:
strRoot = m_FileTree.InsertItem(strTitle,0,0,NULL);
break;
case 2:
strHtEnd = m_FileTree.InsertItem(strTitle,0,0,strHTFir);
break;
case 3:
strHtEnd = m_FileTree.InsertItem(strTitle,0,0,strHTSec);
break;
case 4:
strHtEnd = m_FileTree.InsertItem(strTitle,0,0,strHtThi);
break;
case 5:
strHtEnd = m_FileTree.InsertItem(strTitle,0,0,strHtFor);
break;
default:
strHtEnd = m_FileTree.InsertItem(strTitle,0,0,strHtFif);
break;
}
}
}
ff.Close();//关闭
}


void CFileTreeDlg::BrowseDir( CString strDir, HTREEITEM parent )
{
CFileFind ff;
CString szDir = strDir;
HTREEITEM hSubItem;

if(szDir.Right(1) != "\\")
szDir += "\\";

szDir += "*.*";

BOOL res = ff.FindFile(szDir);
while( res )
{
res = ff.FindNextFile();
if(ff.IsDirectory() && !ff.IsDots())
{
CString strPath = ff.GetFilePath();
CString strTitle = ff.GetFileTitle();

hSubItem = m_FileTree.InsertItem( strTitle, 0, 0, parent );

BrowseDir( strPath, hSubItem );
}
else if(!ff.IsDirectory() && !ff.IsDots())
{
CString strTitle = ff.GetFileTitle();

m_FileTree.InsertItem( strTitle, 0, 0, parent );
}
}
ff.Close();
}

void CFileTreeDlg::OnDblclkFiletree(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
// TODO: Add your control notification handler code here
//此处放置双击播放代码,不知道怎么实现

*pResult = 0;
}
...全文
206 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaozhiyong110 2015-05-20
  • 打赏
  • 举报
回复
调试你的BrowseDir函数就行了 树控件显示的内容就是BrowseDir里面m_FileTree.InsertItem这个动作 BrowseDir( "成绩表", NULL ); 这个就是从当前目录里的 “成绩表”这个文件夹开始搜索...
yaozhiyong110 2015-05-19
  • 打赏
  • 举报
回复
引用 2 楼 yaozhiyong110 的回复:
首先你的程序里 CString strPath; CString strTitle; strPath = ff.GetFilePath(); strTitle = ff.GetFileTitle(); 这里用个map来保存下 strTitle 和 strPath的对应关系 不然到时你获取到title得不到path也播放不了文件 HTREEITEM item = m_FileTree.GetSelectedItem(); CString text = m_FileTree.GetItemText(item); text就是你节点显示的内容 就是你上面的title 然后从map里找到path 最后就是Media Player去播放这个path的文件
定义这个成员变量 map<CString,CString> m_mapPath; 然后 strPath = ff.GetFilePath(); strTitle = ff.GetFileTitle();后面 加上 m_mapPath[strTitle]=strPath; 最后OnDblclkFiletree里面 HTREEITEM item = m_FileTree.GetSelectedItem(); CString title= m_FileTree.GetItemText(item); CString path=m_mapPath[title]; 然后就是用mediaplayer播放这个path
xingyw112 2015-05-19
  • 打赏
  • 举报
回复
还有个问题 我调试的时候 树形控件为什么没有显示哪 那怎么调试呀
xingyw112 2015-05-19
  • 打赏
  • 举报
回复
谢谢 已经能用了 点数怎么给你呀
yaozhiyong110 2015-05-19
  • 打赏
  • 举报
回复
引用 7 楼 xingyw112 的回复:
我照着你说的弄啦 可是还是不行 麻烦你看看,我加的对不对,看看那哪里不对 这是源码连接 麻烦你啦 谢谢 http://pan.baidu.com/s/1ntmmMiX 4gx3
我调试了下 你的BrowseDir函数else if按下面改下 BrowseFile这个函数你根本没用到... else if(!file.IsDirectory() && !file.IsDots()) { CString strPath = file.GetFilePath(); CString strTitle = file.GetFileTitle(); m_mapPath[strTitle]=strPath; m_FileTree.InsertItem( strTitle, 0, 0, parent ); }
xingyw112 2015-05-19
  • 打赏
  • 举报
回复
我照着你说的弄啦 可是还是不行 麻烦你看看,我加的对不对,看看那哪里不对 这是源码连接 麻烦你啦 谢谢 http://pan.baidu.com/s/1ntmmMiX 4gx3
xingyw112 2015-05-18
  • 打赏
  • 举报
回复
具体我应该怎么弄 我之前也弄了 播放提示不能播放此文件
yaozhiyong110 2015-05-18
  • 打赏
  • 举报
回复
HTREEITEM item = m_FileTree.GetSelectedItem(); CString text = m_FileTree.GetItemText(item); 是在OnDblclkFiletree里...
yaozhiyong110 2015-05-18
  • 打赏
  • 举报
回复
首先你的程序里 CString strPath; CString strTitle; strPath = ff.GetFilePath(); strTitle = ff.GetFileTitle(); 这里用个map来保存下 strTitle 和 strPath的对应关系 不然到时你获取到title得不到path也播放不了文件 HTREEITEM item = m_FileTree.GetSelectedItem(); CString text = m_FileTree.GetItemText(item); text就是你节点显示的内容 就是你上面的title 然后从map里找到path 最后就是Media Player去播放这个path的文件
xingyw112 2015-05-18
  • 打赏
  • 举报
回复
怎么没人回帖呀
qwd108114 2015-05-18
  • 打赏
  • 举报
回复
首先要先检查下你加载视频的文件路径是否正确

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧