作者:ccrun 本文是ccrun(老妖)根据互联网上搜集来的资料整理而成.非原创. ▲0. 初始化环境和OLE对象#include utilcls.h#include shlobj.h// 初始化COM环境CoInitialize(NULL);// 创建Shell对象Variant vShellO
作者:ccrun
本文是ccrun(老妖)根据互联网上搜集来的资料整理而成.非原创.
▲0. 初始化环境和OLE对象
#include <utilcls.h>
#include <shlobj.h>
// 初始化COM环境
CoInitialize(NULL);
// 创建Shell对象
Variant vShellOLE = Variant::CreateObject("Shell.Application");
▲1. 层叠窗口
Function CascadeWindows("CascadeWindows");
vShellOLE.Exec(CascadeWindows);
▲2. 横向平铺窗口
Function TileHorizontally("TileHorizontally");
vShellOLE.Exec(TileHorizontally);
▲3. 纵向平铺窗口
Function TileVertically("TileVertically");
vShellOLE.Exec(TileVertically);
▲4. 最小化所有窗口
Function MinimizeAll("MinimizeAll");
vShellOLE.Exec(MinimizeAll);
▲5. 撤消全部最小化
Function UndoMinimizeALL("UndoMinimizeALL");
vShellOLE.Exec(UndoMinimizeALL);
▲6. 设置时间
Function SetTime("SetTime");
vShellOLE.Exec(SetTime);
▲7. 查找计算机
Function FindComputer("FindComputer");
vShellOLE.Exec(FindComputer);
▲8. 查找文件
Function FindFiles("FindFiles");
vShellOLE.Exec(FindFiles);
▲9. 帮助
Function Help("Help");
vShellOLE.Exec(Help);
▲10. 运行文件
Function FileRun("FileRun");
vShellOLE.Exec(FileRun);
▲11. 任务栏属性
Function TrayProperties("TrayProperties");
vShellOLE.Exec(TrayProperties);
▲12. 挂起
Function Suspend("Suspend");
vShellOLE.Exec(Suspend);
▲13. 关闭Windows
Function ShutdownWindows("ShutdownWindows");
vShellOLE.Exec(ShutdownWindows);
▲14. 打开目录对话框
int SpecFolder[17] =
// 本文转自 C++Builder研究 - http://www.ccrun.com/article.asp?i=614&d=4cwe33
{
ssfDESKTOP, ssfPROGRAMS, ssfCONTROLS, ssfPRINTERS, ssfPERSONAL, ssfFAVORITES,
ssfSTARTUP, ssfRECENT, ssfSENDTO, ssfBITBUCKET, ssfSTARTMENU, ssfDESKTOPDIRECTORY,
ssfDRIVES, ssfNETWORK, ssfNETHOOD, ssfFONTS, ssfTEMPLATES
};
Function BrowseForFolder("BrowseForFolder");
Variant ppsdf;
int nIndex = 2;
// 以选定的系统目录为根目录
ppsdf = vShellOLE.Exec(BrowseForFolder << short(Handle) << "BrowseForFolder method" <<
BIF_BROWSEINCLUDEFILES << Variant(SpecFolder[nIndex]));
// 以指定的目录为根目录
String strPath("C://123");
ppsdf = vShellOLE.Exec(BrowseForFolder << short(Handle) << "BrowseForFolder method" <<
BIF_BROWSEINCLUDEFILES << Variant(strPath));
▲15. 浏览指定目录
int SpecFolder[17] =
{
ssfDESKTOP, ssfPROGRAMS, ssfCONTROLS, ssfPRINTERS, ssfPERSONAL, ssfFAVORITES,
ssfSTARTUP, ssfRECENT, ssfSENDTO, ssfBITBUCKET, ssfSTARTMENU, ssfDESKTOPDIRECTORY,
ssfDRIVES, ssfNETWORK, ssfNETHOOD, ssfFONTS, ssfTEMPLATES
};
Function Explore("Explore");
// 浏览指定系统特殊目录
int nIndex = 2;
vShellOLE.Exec(Explore << Variant(SpecFolder[nIndex]));
// 浏览指定磁盘目录
String strPath("C://123");
vShellOLE.Exec(Explore << Variant(String strPath));
▲16. 运行控制面板程序
Function ControlPanelItem("ControlPanelItem");
String strCplFile("D://Winnt//System32//appwiz.cpl");
BSTR FPath = TStringConverter<BSTR>::AnsiToOLESTR(strCplFile.c_str());
vShellOLE.Exec(ControlPanelItem << FPath);
▲17. 在退出程序时将Shell对象付空值
vShellOLE = Unassigned;
CoUninitialize();