吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2177|回复: 3
收起左侧

[C&C++ 转载] 递归目录

[复制链接]
xingyw 发表于 2015-5-3 19:05
本帖最后由 xingyw 于 2015-5-31 14:40 编辑

#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();




发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

qq06314488 发表于 2015-5-3 19:52
szDir += "*.*";
szDir += "*.av
不好意思,少了个i
 楼主| xingyw 发表于 2015-5-3 21:23
你好,这样改完 文件夹 读不出来了 还是谢谢你
szDir += "*.*";
szDir += "*.avi";
 楼主| xingyw 发表于 2015-5-6 14:30
本帖最后由 xingyw 于 2015-5-6 14:36 编辑

我在窗口插入了Windows Media Player控件,控件名        IDC_OCX  我想实现,双击扫描到的视频文件 在Windows Media Player控件里播放,在具体应该怎么实现 我是新手 还不是太懂 弄了几天啦 也没进展 希望哪位说说 谢谢
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-24 03:19

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表