调用Shell接口(系统运行窗口)的代码

类别:VC语言 点击:0 评论:0 推荐:

//--调用Shell接口(系统运行窗口)的代码

#include "stdafx.h"

//--interface
#include <Exdisp.h>

#include <iostream>
using namespace std;

void FileRun()
{
 //--COM
 CoInitialize(NULL);
 
 do {
  
  cout << "---Invoke ShellRun---" << endl;
  
  IShellDispatch *shell = NULL;
  HRESULT hr = CoCreateInstance(CLSID_Shell
   , NULL
   , CLSCTX_SERVER
   , IID_IDispatch,
   (void**)&shell);
  if (FAILED(hr) || !shell)
  {
   cout << "interface FAILED." << endl;
   break;
  }
  
  shell->FileRun();
  //shell->FindFiles();
  /*
  Shell object methods
  The Shell object has the following methods:
  BrowseForFolder
  CascadeWindows
  ControlPanelItem
  EjectPC
  Explore
  FileRun
  FindComputer
  FindFiles
  Help
  MinimizeAll
  NameSpace
  Open
  RefreshMenu
  SetTime
  ShutdownWindows
  Suspend
  TileHorizontally
  TileVertically
  TrayProperties
  UndoMinimizeALL
  Windows
  */
  
  shell->Release();
  
  cout << "---ShellRun OK.---" << endl;
  break;
 } while (false);
 
 //--COM
 CoUninitialize();
}

int main(int argc, char* argv[])
{
 FileRun();
 return 0;
}

本文地址:http://com.8s8s.com/it/it872.htm