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

📄 browseforfolder.cpp

📁 一个不错的自制解压缩程序
💻 CPP
字号:
// BrowseForFolder.cpp: implementation of the CBrowseForFolder class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//#include "TestZipDlg.h"
#include "BrowseForFolder.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBrowseForFolder::CBrowseForFolder()
{
	Image = 0;
	flags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS;
	hWndOwner = NULL;
}

CBrowseForFolder::~CBrowseForFolder()
{
}

// browse for a folder
bool CBrowseForFolder::GetFolder(CString &returnPath)
{
	LPITEMIDLIST pidlRoot = NULL;
	// get the pidl of the root 
	GetPidl(strDirRoot, pidlRoot);
	
	char strBuff[MAX_PATH + 1];
	
	returnPath.Empty();
	LPMALLOC pMalloc;
	if (SUCCEEDED(SHGetMalloc(&pMalloc)))
	{
		BROWSEINFOA brInfo= 
		{
			hWndOwner, 
				pidlRoot, 
				strBuff, 
				strTitle,
				flags,
				BrowseCallbackProc,
				(LPARAM)&strStartupDir,
				Image
		};
		LPITEMIDLIST pidl = SHBrowseForFolder(&brInfo);
		
		if (pidl)
		{
			SHGetPathFromIDList(pidl, strBuff);
			pMalloc->Free(pidl);
			returnPath = strBuff;
		}
		if (pidlRoot) 
			pMalloc->Free(pidlRoot);
		pMalloc->Release();					
	}
	
	if (!returnPath.IsEmpty())
		return true;
	else 
		return false;
}

void CBrowseForFolder::GetPidl(CString name, LPITEMIDLIST pidl)
{
	LPSHELLFOLDER pshf;
	ULONG chEaten;
	OLECHAR oleRoot[MAX_PATH];
	// convert path to Unicode string
	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1,
		oleRoot, MAX_PATH);
	if (SUCCEEDED(SHGetDesktopFolder(&pshf)))
	{
		// get pidl
		pshf->ParseDisplayName(hWndOwner, NULL, oleRoot, &chEaten, 
			&pidl, NULL);
	}
	else return;
	pshf->Release();
}

// set if the EditBox is present in the browse dialog
void CBrowseForFolder::SetEditBox(bool val)
{
	if (val) 
		flags |= BIF_EDITBOX;
	else 
		flags &= ~BIF_EDITBOX;
}

// set if the StatusBar is present in the browse dialog
void CBrowseForFolder::SetStatusBar(bool val)
{
	if (val) 
		flags |= BIF_STATUSTEXT;
	else 
		flags &= ~BIF_STATUSTEXT;
}

int CALLBACK CBrowseForFolder::BrowseCallbackProc(HWND hwnd, UINT uMsg, 
												  LPARAM lParam, LPARAM lpData)
{
	switch (uMsg)
	{
		case BFFM_INITIALIZED: 
			{
				// set the initial directory
				CString* pString = (CString*)lpData;
				if (!pString) 
					return 0;
				LPTSTR szDir = pString->GetBuffer(pString->GetLength());
				// WParam is TRUE since you are passing a path.
				// It would be FALSE if you were passing a pidl.
				SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDir);             
				break;       
			}
		case BFFM_SELCHANGED: 
			{
				// Set the status window to the currently selected path.
				TCHAR szDir[MAX_PATH];
				if (SHGetPathFromIDList((LPITEMIDLIST) lParam , szDir)) 
					SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir);
				break;            
			}            
		default:
			break;         
	}         
	return 0;
}


⌨️ 快捷键说明

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