关于几个常见的SHELL问题
最近在CSDN上经常看到有人发问,怎样实现显示查找文件对话框,显示浏览文件夹对话框,显示关闭Windows对话框,一类的问题,所以我整理了几个常用的SHELL实现的方法。如下:
IShellDispatch* pShellDispatch = NULL;
HRESULT hResult = CoInitialize(NULL);
if(FAILED(hResult))
{
return;
}
hResult = CoCreateInstance(CLSID_Shell,NULL,CLSCTX_INPROC_SERVER,
IID_IDispatch,(LPVOID*)&pShellDispatch);
if(FAILED(hResult))
{
return;
}
// COleVariant OleVariant("桌面");
// COleVariant OleTitle("IShellDispatch test");
// Folder* pFolder = NULL;
// hResult = pShellDispatch->BrowseForFolder((LONG)GetSafeHwnd(),
// OleTitle.bstrVal,BIF_RETURNONLYFSDIRS,OleVariant,&pFolder);
//显示浏览文件夹对话框
// hResult = pShellDispatch->CascadeWindows();//层叠窗口
// COleVariant OleVariant("access.cpl");
// hResult = pShellDispatch->ControlPanelItem(OleVariant.bstrVal);//打开控制面板的程序
// COleVariant OleVariant("我的电脑");
// hResult = pShellDispatch->Explore(OleTitle);//用资源管理器打开文件夹
// hResult = pShellDispatch->FileRun();//显示运行对话框
// hResult = pShellDispatch->FindComputer();//显示查找电脑对话框
// hResult = pShellDispatch->FindFiles();//显示查找文件对话框
// hResult = pShellDispatch->MinimizeAll();//显示桌面
// COleVariant OleVariant("我的电脑");
// hResult = pShellDispatch->Open(OleTitle);//打开文件夹
// hResult = pShellDispatch->ShutdownWindows();//显示关闭Windows对话框
// hResult = pShellDispatch->TileHorizontally();//横向平铺窗口
// hResult = pShellDispatch->TileVertically();//纵向平铺窗口
// hResult = pShellDispatch->TrayProperties();//显示任务栏属性对话框
// hResult = pShellDispatch->UndoMinimizeALL();//撤销最小化窗口