📄 path.cpp
字号:
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 Windows directory
//-------------------------------------------------------------
void CPath::WindowsDirectory()
{
TCHAR buff_path[MAX_PATH];
GetWindowsDirectory(buff_path,MAX_PATH);
Empty();
SetDriveDirectory(buff_path);
}
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 Windows system directory
//-------------------------------------------------------------
void CPath::SystemDirectory()
{
TCHAR buff_path[MAX_PATH];
GetSystemDirectory(buff_path,MAX_PATH);
Empty();
SetDriveDirectory(buff_path);
}
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 root of system drive (usually C:\)
//-------------------------------------------------------------
void CPath::SystemDriveRootDirectory()
{
SystemDirectory();
SetDirectory(_T(""));
}
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 the name of specified module
//-------------------------------------------------------------
void CPath::Module(HINSTANCE hInstance)
{
TCHAR buff_path[MAX_PATH];
GetModuleFileName(hInstance,buff_path,MAX_PATH);
m_strPath =buff_path;
}
#ifdef __MFC__
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 the name of current module
//-------------------------------------------------------------
void CPath::Module()
{
Module(AfxGetInstanceHandle());
}
#endif
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 the directory of current module
//-------------------------------------------------------------
void CPath::ModuleDirectory(HINSTANCE hInstance)
{
Module(hInstance);
SetNameExtension(_T(""));
}
#ifdef __MFC__
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 the directory of current module
//-------------------------------------------------------------
void CPath::ModuleDirectory()
{
Module();
SetNameExtension(_T(""));
}
#endif
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Currently, if the current environment has an
// entry for the TEMP environment variable, the directory will
// be set to that. If not, the directory will be the Windows
// System directory. The caller of this method, however, should
// not rely on this convention
//-------------------------------------------------------------
void CPath::TempDirectory()
{
TCHAR buff_path[MAX_PATH];
GetTempPath(MAX_PATH,buff_path);
m_strPath =buff_path;
SetNameExtension(_T(""));
}
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 program files folder
// Usually C:\Program Files
//-------------------------------------------------------------
void CPath::ProgramFilesDirectory()
{
string strPath;
if(GetRegistryPath(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"),_T("ProgramFilesDir"),strPath))
{
// Got a path, use it
Empty();
SetDriveDirectory(strPath.c_str());
}
else
{
// This is some old or unknown system
Empty();
SetDriveDirectory(_T("C:\\Programs"));
}
}
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 common files folder
// Usually C:\Program Files\Common Files
//-------------------------------------------------------------
void CPath::CommonFilesDirectory()
{
string strPath;
if(GetRegistryPath(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"),_T("CommonFilesDir"),strPath))
{
// Got a path, use it
Empty();
SetDriveDirectory(strPath.c_str());
}
else
{
// This is some old or unknown system
Empty();
SetDriveDirectory(_T("C:\\Programs\\Common"));
}
}
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 common files folder
// On Win95 is C:\Program Files\Accessories
// On WinNT is C:\Program Files\Windows NT\Accessories
//-------------------------------------------------------------
void CPath::AccessoriesDirectory()
{
// Accessories folder is in Program Files folder
ProgramFilesDirectory();
COSVersion osver;
WORD ostype =osver.GetOSType();
WORD wintype =osver.GetWindowsType();
BOOL is_Win95 =(ostype==OS_WIN95) || (ostype==OS_WIN98);
BOOL is_NT =((ostype & OS_WINNT) != 0);
if((wintype != WIN_32S) && is_Win95)
{
// Windows 95
AppendDirectory(_T("Accessories"));
return;
}
if((wintype != WIN_32S) && is_NT && (((osver.GetMajorVersion()==3) && (osver.GetMinorVersion()>=51)) || (osver.GetMajorVersion()>3)))
{
// Windows NT with the new Chichago shell
AppendDirectory(_T("Windows NT\\Accessories"));
return;
}
// This is some old or unknown system
AppendDirectory(_T("Accessry"));
}
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 media folder
// Usually C:\Windows\Media
//-------------------------------------------------------------
void CPath::MediaDirectory()
{
string strPath;
if(GetRegistryPath(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"),_T("MediaPath"),strPath))
{
// Got a path, use it
Empty();
SetDriveDirectory(strPath.c_str());
}
else
{
// This is some old or unknown system
WindowsDirectory();
AppendDirectory(_T("Media"));
}
}
//-------------------------------------------------------------
// Pre :
// Post :
// Globals :
// I/O :
// Task : Set path 2 device definition folder
// Usually C:\Windows\Inf
//-------------------------------------------------------------
void CPath::DeviceDirectory()
{
string strPath;
if(GetRegistryPath(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"),_T("DevicePath"),strPath))
{
// Got a path, use it
Empty();
SetDriveDirectory(strPath.c_str());
}
else
{
// This is some old or unknown system
WindowsDirectory();
AppendDirectory(_T("Inf"));
}
}
//-------------------------------------------------------------
// Pre :
// Post : If this function is called on a system which does not
// support the new Chichago shell, it will return FALSE
// Globals :
// I/O :
// Task : Set path 2 one of the special folders in Chichago
//-------------------------------------------------------------
BOOL CPath::ShellDirectory(int nShellFolderID)
{
COSVersion osver;
WORD ostype =osver.GetOSType();
WORD wintype =osver.GetWindowsType();
BOOL is_Win95 =(ostype==OS_WIN95) || (ostype==OS_WIN98);
BOOL is_NT =((ostype & OS_WINNT) != 0);
if((wintype != WIN_32S) &&
(is_Win95 || (is_NT && (((osver.GetMajorVersion()==3) && (osver.GetMinorVersion()>=51)) || (osver.GetMajorVersion()>3)))))
{
// These systems support the new Chichago shell, get location from registry
BOOL result =FALSE;
LPITEMIDLIST pidl =NULL;
TCHAR special_path[MAX_PATH];
// Get a PIDL 2 the special shell folder
HRESULT hr =SHGetSpecialFolderLocation(NULL,nShellFolderID,&pidl);
if(SUCCEEDED(hr))
{
// Convert the PIDL in2 a path
result =SHGetPathFromIDList(pidl,special_path);
// Free the PIDL
// Get the address of our task allocator's IMalloc interface
LPMALLOC pMalloc;
hr =SHGetMalloc(&pMalloc);
if(SUCCEEDED(hr))
{
// Free the PIDL
pMalloc->Free(pidl);
// Free our task allocator
pMalloc->Release();
}
}
if(result)
{
// We've got the special path, now set ourselves 2 point 2 this
Empty();
SetDriveDirectory(special_path);
}
return result;
}
// This is some old or unknown system, shell folders not supported
return FALSE;
}
//---------------------------------------------------------------------------
// Pre :
// Post : Return TRUE on success
// Globals :
// I/O :
// Task : Set path 2 one of the special folders in Chichago
// This function manually digs in the registry instead of using
// SHGetSpecialFolderLocation, since it seems that this does not work 4
// special location constants beginning with
//---------------------------------------------------------------------------
BOOL CPath::ShellDirectory2(int nShellFolderID)
{
COSVersion osver;
WORD ostype =osver.GetOSType();
WORD wintype =osver.GetWindowsType();
BOOL is_Win95 =(ostype==OS_WIN95) || (ostype==OS_WIN98);
BOOL is_NT =((ostype & OS_WINNT) != 0);
if((wintype != WIN_32S) &&
(is_Win95 || (is_NT && (((osver.GetMajorVersion()==3) && (osver.GetMinorVersion()>=51)) || (osver.GetMajorVersion()>3)))))
{
// These systems support the new Chichago shell, get location from registry
HKEY root;
string key;
string value;
switch(nShellFolderID)
{
case CSIDL_DESKTOPDIRECTORY:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("Desktop");
break;
case CSIDL_FAVORITES:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("Favorites");
break;
case CSIDL_FONTS:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("Fonts");
break;
case CSIDL_NETHOOD:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("NetHood");
break;
case CSIDL_PERSONAL:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("Personal");
break;
case CSIDL_RECENT:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("Recent");
break;
case CSIDL_SENDTO:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("SendTo");
break;
case CSIDL_TEMPLATES:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("Templates");
break;
case CSIDL_APPDATA:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("AppData");
break;
case CSIDL_STARTMENU:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("Start Menu");
break;
case CSIDL_STARTUP:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("Startup");
break;
case CSIDL_PROGRAMS:
root =HKEY_CURRENT_USER;
key =_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
value =_T("Programs");
break;
case CSIDL_COMMON_DESKTOPDIRECTORY:
root =HKEY_LOCAL_MACHINE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -