📄 shelltools.cpp
字号:
/***************************************************************************/
/* NOTE: */
/* This document is copyright (c) by Oz Solomonovich. All non-commercial */
/* use is allowed, as long as this document not altered in any way, and */
/* due credit is given. */
/***************************************************************************/
#include "stdafx.h"
#include "ShellTools.h"
/////////////////////////////////////////////////////////////////////////////
// CInitializer
// private class used for automatic initialization and cleanup of local
// variables
static class CInitializer
{
public:
CInitializer();
~CInitializer();
static LPSHELLFOLDER m_sfDesktop;
static LPMALLOC m_pAllocator;
static HIMAGELIST m_hShellImageList;
} __init;
LPSHELLFOLDER CInitializer::m_sfDesktop = NULL;
LPMALLOC CInitializer::m_pAllocator = NULL;
HIMAGELIST CInitializer::m_hShellImageList = NULL;
CInitializer::CInitializer()
{
SHGetDesktopFolder(&m_sfDesktop);
SHGetMalloc(&m_pAllocator);
SHFILEINFO sfi;
m_hShellImageList = (HIMAGELIST)SHGetFileInfo((LPCSTR)"C:\\", 0,
&sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
}
CInitializer::~CInitializer()
{
m_sfDesktop->Release();
m_pAllocator->Release();
}
// == Icon Extraction == //
typedef struct
{
RECEIVERFUNC pReceiver;
LPVOID pContext;
LPCTSTR pszPath;
UINT uFlags;
} gfi_thread_data, *pgfi_thread_data;
static UINT gfiExecutor(LPVOID pParam)
{
pgfi_thread_data pData = (pgfi_thread_data)pParam;
HICON theIcon = GetFileIcon(pData->pszPath, pData->uFlags);
pData->pReceiver(theIcon, pData->pContext);
delete pData;
return 0;
}
// GetFileIcon - returns the icon associated with a namespace object.
HICON GetFileIcon(LPCTSTR pszPath, UINT uFlags, RECEIVERFUNC pReceiver,
LPVOID pContext)
{
if (pReceiver == NULL)
{
SHFILEINFO sfi;
SHGetFileInfo(pszPath, 0, &sfi, sizeof(SHFILEINFO),
uFlags | SHGFI_ATTRIBUTES | SHGFI_DISPLAYNAME | SHGFI_ICON |
SHGFI_SMALLICON);
return ImageList_GetIcon(CInitializer::m_hShellImageList,
sfi.iIcon, 0);
}
else
{
pgfi_thread_data pData = new gfi_thread_data;
pData->pReceiver = pReceiver;
pData->pContext = pContext;
pData->pszPath = pszPath;
pData->uFlags = uFlags;
return (HICON)AfxBeginThread(gfiExecutor, pData);
}
}
// == Open Folder == //
void OpenLocation(CString &cLocation, OpenMethods aMethod)
{
if (aMethod == defaultAction)
{
ShellExecute(AfxGetMainWnd()->m_hWnd, NULL, cLocation, NULL, NULL,
SW_SHOWDEFAULT);
}
else
{
CString cExecString = "", cWinDir;
PROCESS_INFORMATION pi;
STARTUPINFO si;
switch (aMethod)
{
case explore:
cExecString += "/e,";
break;
case exploreFrom:
cExecString = "/e,/root,";
break;
}
GetStartupInfo(&si);
GetWindowsDirectory(cWinDir.GetBuffer(256), 256);
cWinDir.ReleaseBuffer();
cExecString = cWinDir + "\\Explorer.exe " + cExecString + cLocation;
CreateProcess(NULL, (char *)(const char *)(cExecString), NULL,
NULL, FALSE, 0, NULL, NULL, &si, &pi);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -