that's all!
3Q!

解决方案 »

  1.   

    WinExe
    ShellExecute
    CreateProcess
      

  2.   

    Launching Applications
    Once your application has located a file object, the next step is often to act on it in some way. For instance, your application might want to launch another application that allows the user to modify a data file. If the file of interest is an executable, your application might want to simply launch it. This document discusses how to use ShellExecute or ShellExecuteEx to perform these tasks.Using ShellExecute and ShellExecuteEx 
    A Simple Example of How to Use ShellExecuteEx 
    Using ShellExecute and ShellExecuteEx
    To use ShellExecute or ShellExecuteEx, your application must specify the file or folder object that is to be acted on, and a verb that specifies the operation. For ShellExecute, assign these values to the appropriate parameters. For ShellExecuteEx, fill in the appropriate members of a SHELLEXECUTEINFO structure. There are also several other members or parameters that can be used to fine-tune the behavior of the two functions.File and folder objects can be part of the file system or virtual objects, and they can be identified by either paths or PIDLs. 
    Object Verbs
    The verbs available for an object are essentially the items that you find on an object's shortcut menu. To find which verbs are available, look in the registry underHKEY_CLASSES_ROOT\CLSID\{object_clsid}\Shell\verb
    where object_clsid is the CLSID of the object, and verb is the name of the available verb. The verb\Command subkey contains the data indicating what happens when that verb is invoked.To find out which verbs are available for predefined Shell objects, look in the registry underHKEY_CLASSES_ROOT\object_name\Shell\verb
    where object_name is the name of the predefined Shell object. Again, the verb\Command subkey contains the data indicating what happens when that verb is invoked.Commonly available verbs include:Verb Description 
    edit  Launches an editor and opens the document for editing. 
    find Initiates a search starting from the specified directory. 
    open  Launches an application. If this file is not an executable file, its associated application is launched. 
    print  Prints the document file. 
    properties  Displays the object's properties. Each verb corresponds to the command that would be used to launch the application from a console window. The open verb is a good example, as it is commonly supported. For .exe files, open simply launches the application. However, it is more commonly used to launch an application that operates on a particular file. For instance, .txt files can be opened by WordPad. The open verb for a .txt file would thus correspond to something like the following command: "C:\Program Files\Windows NT\Accessories\Wordpad.exe" "%1"When you use ShellExecute or ShellExecuteEx to open a .txt file, Wordpad.exe is launched with the specified file as its argument. Some commands can have additional arguments, such as flags, that can be added as needed to launch the application properly. For further discussion of shortcut menus and verbs, see Extending Shortcut Menus.In general, trying to determine the list of available verbs for a particular file is somewhat complicated. In many cases, you can simply set the lpVerb parameter to NULL, which invokes the default command for the file class. This procedure is usually equivalent to setting lpVerb to "open", but some file classes may have a different default command. For further information, see Extending Shortcut Menus and the ShellExecuteEx reference documentation.Using ShellExecute to Launch the Find Dialog Box
    When a user right-clicks a folder icon in Windows Explorer, one of the menu items is "Find". If they select that item, the Shell launches its Find utility. This utility displays a dialog box that can be used to search files for a specified text string. An application can programmatically launch the Find utility for a directory by calling ShellExecute, with "find" as the lpVerb parameter, and the directory path as the lpFile parameter. For instance, the following line of code launches the Find utility for the c:\MyPrograms directory.ShellExecute(hwnd,"find","c:\\MyPrograms",NULL, NULL, 0);A Simple Example of How to Use ShellExecuteEx
    The following sample console application illustrates the use of ShellExecuteEx. Most error checking code has been omitted for clarity.#include <shlobj.h>
    #include <shlwapi.h>main()
    {
        LPMALLOC pMalloc;
        LPITEMIDLIST pidlWinFiles = NULL;
        LPITEMIDLIST pidlItems = NULL;
        IShellFolder *psfWinFiles = NULL;
        IShellFolder *psfDeskTop = NULL;
        LPENUMIDLIST ppenum = NULL;
        STRRET strDispName;
        TCHAR pszParseName[MAX_PATH];
        ULONG celtFetched;
        SHELLEXECUTEINFO ShExecInfo;
        HRESULT hr;
        BOOL fBitmap = FALSE;    hr = SHGetMalloc(&pMalloc);

        hr = SHGetFolderLocation(NULL, CSIDL_WINDOWS, NULL, NULL, &pidlWinFiles);    hr = SHGetDesktopFolder(&psfDeskTop);    hr = psfDeskTop->BindToObject(pidlWinFiles, NULL, IID_IShellFolder, (LPVOID *) &psfWinFiles);
        hr = psfDeskTop->Release();    hr = psfWinFiles->EnumObjects(NULL,SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &ppenum);    while( hr = ppenum->Next(1,&pidlItems, &celtFetched) == S_OK && (celtFetched) == 1)
        {
            psfWinFiles->GetDisplayNameOf(pidlItems, SHGDN_FORPARSING, &strDispName);
            StrRetToBuf(&strDispName, pidlItems, pszParseName, MAX_PATH);
            pMalloc->Free(pidlItems);
            if(StrCmpI(PathFindExtension(pszParseName), TEXT( ".bmp")) == 0)
            {
                fBitmap = TRUE;
                break;
            }
        }

        ppenum->Release();    if(fBitmap)
        {
            ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
            ShExecInfo.fMask = NULL;
            ShExecInfo.hwnd = NULL;
            ShExecInfo.lpVerb = NULL;
            ShExecInfo.lpFile = pszParseName;
            ShExecInfo.lpParameters = NULL;
            ShExecInfo.lpDirectory = NULL;
            ShExecInfo.nShow = SW_MAXIMIZE;
            ShExecInfo.hInstApp = NULL;        ShellExecuteEx(&ShExecInfo);
        }    pMalloc->Free(pidlWinFiles);
        pMalloc->Release();
        psfWinFiles->Release();    return 0;
    }The application first retrieves the PIDL of the Windows directory, and enumerates its contents until it finds the first .bmp file. Unlike the earlier example, IShellFolder::GetDisplayNameOf is used to retrieve the file's parsing name instead of its display name. Because this is a file system folder, the parsing name is a fully qualified path, which is what is needed for ShellExecuteEx.Once the first .bmp file has been located, appropriate values are assigned to the members of a SHELLEXECUTEINFO structure. The lpFile member is set to the parsing name of the file, and the lpVerb member to NULL, to begin the default operation. In this case, the default operation is "open". The structure is then passed to ShellExecuteEx, which launches the default handler for bitmap files, typically MSPaint.exe, to open the file. After the function returns, the PIDLs are freed and the Windows folder's IShellFolder interface is released.
      

  3.   

    怎样加载其他的应用程序? 三个SDK函数 winexec, shellexecute,createprocess可以使用。WinExec最简单,两个参数,前一个指定路径,后一个指定显示方式.后一个参数值得说一下,比如泥用 SW_SHOWMAXMIZED方式去加载一个无最大化按钮的程序,就是Neterm,calc等等,就不会出现正常的窗体,但是已经被加到任务列表里了。
    ShellExecute较 WinExex灵活一点,可以指定工作目录,下面的Example就是直接打开 c:\temp\1.txt,而不用加载与 txt文件关联的应用程序,很多安装程序完成后都会打开一个窗口,来显示Readme or Faq,我猜就是这么作的啦.
    ShellExecute(NULL,NULL,_T("1.txt"),NULL,_T("c:\\temp"),SW_SHOWMAXMIZED)
    CreateProcess最复杂,一共有十个参数,不过大部分都可以用NULL代替,它可以指定进程的安全属性,继承信息,类的优先级等等.来看个很简单的Example:
     STARTUPINFO stinfo
    //启动窗口的信息
     PROCESSINFO procinfo //进程的信息
     CreateProcess(NULL,_T("notepad.exe"),NULL,NULL.FALSE,
    NORMAL_PRIORITY_
     CLASS,NULL,NULL, &stinfo,&procinfo) 
      

  4.   

    很简单,使用函数int system( const char *command );
    其中command是你要执行的文件路径及文件名
    example:
    system("notpad.exe");将运行记事本。
    其实它是运行系统命令行的函数。
    即你在开始菜单的运行里可以运行的命令它都可以执行。
      

  5.   

    对不起,刚才的例子里"notpad.exe"应改为"notepad.exe".
    纯属笔误!^_^
      

  6.   

    谢谢大家!
    我的目的是要在一个程序运行的时候,给一个条件同时运行另外一个vc的
    exe文件,当然是要出现view及窗口等!
    试过函数ShellExecute,就是没出现窗口!
    么办?