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

📄 mainfrm.cpp

📁 能像Windows操作系统的资源管理器一样将资源按目录(文件夹文件)的形式组织起来。 考虑到资源建设的阶段性
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "resExplorer.h"

#include "MainFrm.h"
#include "ResExplorerTree.h"
#include "resExplorerView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(ID_FILE_FOLDER_SETTING, OnFileFolderSetting)
	ON_UPDATE_COMMAND_UI(ID_FILE_FOLDER_SETTING, OnUpdateFileFolderSetting)
	ON_COMMAND(ID_VIEW_BIGICON, OnViewBigicon)
	ON_COMMAND(ID_VIEW_DETAIL, OnViewDetail)
	ON_COMMAND(ID_VIEW_LIST, OnViewList)
	ON_COMMAND(ID_VIEW_SMALLICON, OnViewSmallicon)
	ON_UPDATE_COMMAND_UI(ID_VIEW_BIGICON, OnUpdateViewBigicon)
	ON_UPDATE_COMMAND_UI(ID_VIEW_DETAIL, OnUpdateViewDetail)
	ON_UPDATE_COMMAND_UI(ID_VIEW_LIST, OnUpdateViewList)
	ON_UPDATE_COMMAND_UI(ID_VIEW_SMALLICON, OnUpdateViewSmallicon)
	ON_COMMAND(ID_FILE_OPENFILE, OnFileOpenfile)
	ON_UPDATE_COMMAND_UI(ID_FILE_OPENFILE, OnUpdateFileOpenfile)
	ON_COMMAND(ID_FILE_DOWNLOAD, OnFileDownload)
	ON_UPDATE_COMMAND_UI(ID_FILE_DOWNLOAD, OnUpdateFileDownload)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	//创建视图分隔对象
	if (!m_wndSplitter.CreateStatic(this, 1, 2))
		return FALSE;
	//在视图分隔栏中创建含树控件CResExplorerTree树控件
	if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CResExplorerTree),
		CSize(300, 100), pContext))
	{
		m_wndSplitter.DestroyWindow();
		return FALSE;
	}
	//在视图分隔栏中创建含列表控件的CResExploreView类
	if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CResExplorerView),
		CSize(100, 100), pContext))
	{
		m_wndSplitter.DestroyWindow();
		return FALSE;
	}

    return TRUE;
//去掉以下以前的Client处的创建代码
//	return CFrameWnd::OnCreateClient(lpcs, pContext);
}

void CMainFrame::OnFileFolderSetting() 
{
	// TODO: Add your command handler code here
    CResExplorerTree* pView=(CResExplorerTree*)(m_wndSplitter.GetPane(0,0));
    pView->m_TreeCtrl.SelectItem(NULL);
	//清除所有的树节点,从新构造树节点
	pView->m_TreeCtrl.DeleteAllItems();
    pView->m_tvlparam =0;
    //调整树控件设置状态标志位
	if(pView->isSetting){
	    pView->isSetting=false;
	}else{
	    pView->isSetting=true;
	}
	//保存设置数据
	pView->m_ResDataProvider.SaveSetting();
    //重新插入根节点数据
    pView->InsertXMLItem(pView->m_ResDataProvider.GetResLibs());
}

void CMainFrame::OnUpdateFileFolderSetting(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CResExplorerTree* pView=(CResExplorerTree*)(m_wndSplitter.GetPane(0,0));
    pCmdUI->SetCheck(pView->isSetting);
}

void CMainFrame::OnViewBigicon() 
{
	// TODO: Add your command handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
   
	pView->SwitchView(LVS_ICON);
}

void CMainFrame::OnUpdateViewBigicon(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
	pCmdUI->SetRadio(pView->GetViewType() == LVS_ICON);
}

void CMainFrame::OnViewSmallicon() 
{
	// TODO: Add your command handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
   
	pView->SwitchView(LVS_SMALLICON);
}

void CMainFrame::OnUpdateViewSmallicon(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
	pCmdUI->SetRadio(pView->GetViewType() == LVS_SMALLICON);
}

void CMainFrame::OnViewList() 
{
	// TODO: Add your command handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
   
	pView->SwitchView(LVS_LIST);
}

void CMainFrame::OnUpdateViewList(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
	pCmdUI->SetRadio(pView->GetViewType() == LVS_LIST);

}

void CMainFrame::OnViewDetail() 
{  
	// TODO: Add your command handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
   
	pView->SwitchView(LVS_REPORT);
}

void CMainFrame::OnUpdateViewDetail(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
    pCmdUI->SetRadio(pView->GetViewType() == LVS_REPORT);
}

void CMainFrame::OnFileDownload() 
{ 
	// TODO: Add your command handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
    if(pView->m_ListCtrl.GetSelectedCount()>1){
	    //系统暂时不支持该功能
		//AfxMessageBox("下传多个文件");
	}else{
		CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));

		//AfxMessageBox("打开单个文件");
		// pView->m_ListCtrl
		int iItem=pView->m_ListCtrl.GetNextItem(-1,LVNI_SELECTED); 
		CString filePath=pView->m_ResDataProvider.GetFilePathByID(pView->m_ListCtrl.GetItemText(iItem,4));
        //打开文件对话框,方便下载  
		

    CString		Filter;
    //根据filePath生成相关文件filter
	TCHAR ch[1];
	_tcscpy(ch,(LPCTSTR)"\\"); // copy caller's pathname
    Filter="所有文件(*.*)|*.*||";
    char initFileName[MAX_PATH];//="C:\\ttt.TXT\0";
    strcpy (initFileName,(LPCTSTR)(filePath.Mid(filePath.ReverseFind(ch[0])+1)));
    CFileDialog dlgFile (FALSE, NULL, initFileName, OFN_HIDEREADONLY, Filter, NULL) ;
	if (dlgFile.DoModal() == IDCANCEL)
		return ;
     int nOk;
     //可以改变源路径
	TCHAR strSrc[_MAX_PATH + 1]; // allow one more character
	_tcscpy(strSrc, (LPCTSTR)filePath); // copy caller's pathname
	strSrc[_tcslen(strSrc)+1]=0; // need two NULLs at end
     //设置目的路径
	 CString tmpSaveFile=dlgFile.GetPathName();
     char strDst[MAX_PATH];//="C:\\ttt.TXT\0";
     strcpy(strDst,(LPCSTR)(tmpSaveFile)); 

     char  strTitle[]="下载资源文件";
     //进度题头
     SHFILEOPSTRUCT FileOp;
     FileOp.hwnd=m_hWnd;
     FileOp.wFunc=FO_COPY;
     //执行文件拷贝
     FileOp.pFrom=strSrc;
     FileOp.pTo=strDst;
     FileOp.fFlags=FOF_ALLOWUNDO;
     FileOp.hNameMappings=NULL;
     FileOp.lpszProgressTitle=strTitle;

       	nOk=SHFileOperation(&FileOp);
       	if(nOk){
		   CString errStr;
            errStr.Format("出现以下错误: %d\n",nOk);
			//AfxMessageBox(errStr);
       	}else{
    		AfxMessageBox("文件下载完成!");
        }
		if(FileOp.fAnyOperationsAborted){
          	 AfxMessageBox("操作已被用户取消!\n");
		}
	}
}

void CMainFrame::OnUpdateFileDownload(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
    pCmdUI->Enable(pView->m_ListCtrl.GetSelectedCount());

}

void CMainFrame::OnFileOpenfile() 
{
	// TODO: Add your command handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
    if(pView->m_ListCtrl.GetSelectedCount()>1){
		//系统暂时不支持该功能
		//AfxMessageBox("打开多个文件");
	}else{
        int iItem=pView->m_ListCtrl.GetNextItem(-1,LVNI_SELECTED); 
        CString fielPath=pView->m_ResDataProvider.GetFilePathByID(pView->m_ListCtrl.GetItemText(iItem,4));

     ShellExecute(NULL,"open",fielPath,NULL,NULL,SW_SHOWNORMAL);

	}	
}

void CMainFrame::OnUpdateFileOpenfile(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CResExplorerView* pView=(CResExplorerView*)(m_wndSplitter.GetPane(0,1));
    pCmdUI->Enable(pView->m_ListCtrl.GetSelectedCount());
}

⌨️ 快捷键说明

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