用ShellExcute()直接就可以实现啊!最简单了!具体用法,MSDN中有详细介绍!

解决方案 »

  1.   

    我的MSDN盘读不出来了,谢谢你,请问是否是shellexecute参数lpParameters
    设为在dos中自动输入的字符串?
      

  2.   

    蓝色冲击波还在吗?能否把msdn中的相关部分email给我?
       多谢![email protected]
      

  3.   

    HINSTANCE ShellExecute(
        HWND hwnd, 
        LPCTSTR lpVerb,
        LPCTSTR lpFile, 
        LPCTSTR lpParameters, 
        LPCTSTR lpDirectory,
        INT nShowCmd
    );Parameters
    hwnd 
    Handle to a parent window. This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box. 
    lpVerb 
    A string, referred to as a verb, that specifies the action to be performed. The set of available verbs depends on the particular file or folder. Generally, the actions available from an object's context menu are available verbs. For more information about verbs and their availability, see Object Verbs. See Extending Context Menus for further discussion of context menus. The following verbs are commonly used: Verb Description 
    edit  Launches an editor and opens the document for editing. If lpFile is not a document file, the function will fail. 
    explore Explores the folder specified by lpFile.  
    find Initiates a search starting from the specified directory. 
    open  Opens the file specified by the lpFile parameter. The file can be an executable file, a document file, or a folder. 
    print  Prints the document file specified by lpFile. If lpFile is not a document file, the function will fail. 
    properties  Displays the file or folder's properties. 
    If you set this paramater to NULL:For systems prior to Microsoft® Windows® 2000, the default verb is used if it is valid and available in the registry. If not, the "open" verb is used. 
    For Windows 2000 and later systems, the default verb is used if available. If not, the "open" verb is used. If neither verb is available, the system uses the first verb listed in the registry. 
    lpFile 
    Address of a null-terminated string that specifies the file or object on which to execute the specified verb. To specify a shell namespace object, pass the fully-qualified parse name. Note that not all verbs are supported on all objects. For example, not all document types support the "print" verb. 
    lpParameters 
    If the lpFile parameter specifies an executable file, lpParameters is an address to a null-terminated string that specifies the parameters to be passed to the application.The format of this string is determined by the verb that is to be invoked. If lpFile specifies a document file, lpParameters should be NULL. 
    lpDirectory 
    Address of a null-terminated string that specifies the default directory. 
    nShowCmd 
    Flags that specify how an application is to be displayed when it is opened. If lpFile specifies a document file, the flag is simply passed to the associated application. It is up to the application to decide how to handle it.  
    SW_HIDE  Hides the window and activates another window. 
    SW_MAXIMIZE  Maximizes the specified window. 
    SW_MINIMIZE  Minimizes the specified window and activates the next top-level window in the z-order. 
    SW_RESTORE  Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window. 
    SW_SHOW  Activates the window and displays it in its current size and position.  
    SW_SHOWDEFAULT  Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window. 
    SW_SHOWMAXIMIZED  Activates the window and displays it as a maximized window. 
    SW_SHOWMINIMIZED  Activates the window and displays it as a minimized window. 
    SW_SHOWMINNOACTIVE  Displays the window as a minimized window. The active window remains active. 
    SW_SHOWNA  Displays the window in its current state. The active window remains active. 
    SW_SHOWNOACTIVATE  Displays a window in its most recent size and position. The active window remains active. 
    SW_SHOWNORMAL  Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time. Return Values
    Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise. The following table lists the error values. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Microsoft® Windows® applications. It is not a true HINSTANCE, however. The only thing that can be done with the returned HINSTANCE is to cast it to an integer and compare it with the value 32 or one of the error codes below.0  The operating system is out of memory or resources. 
    ERROR_FILE_NOT_FOUND  The specified file was not found. 
    ERROR_PATH_NOT_FOUND  The specified path was not found. 
    ERROR_BAD_FORMAT  The .exe file is invalid (non-Win32® .exe or error in .exe image). 
    SE_ERR_ACCESSDENIED  The operating system denied access to the specified file.  
    SE_ERR_ASSOCINCOMPLETE  The file name association is incomplete or invalid. 
    SE_ERR_DDEBUSY  The DDE transaction could not be completed because other DDE transactions were being processed. 
    SE_ERR_DDEFAIL  The DDE transaction failed. 
    SE_ERR_DDETIMEOUT  The DDE transaction could not be completed because the request timed out. 
    SE_ERR_DLLNOTFOUND  The specified dynamic-link library was not found.  
    SE_ERR_FNF  The specified file was not found.  
    SE_ERR_NOASSOC  There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable. 
    SE_ERR_OOM  There was not enough memory to complete the operation. 
    SE_ERR_PNF  The specified path was not found. 
    SE_ERR_SHARE  A sharing violation occurred. Res
    This method allows you to execute any commands in a folder's context menu or stored in the registry. To open a folder, use either of the following calls: ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);or ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);To explore a folder, use: ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL);To launch the shell's Find utility for a directory, use:ShellExecute(handle, "find", path_to_folder, NULL, NULL, 0);If lpOperation is NULL, the function opens the file specified by lpFile. If lpOperation is "open" or "explore", the function will attempt to open or explore the folder. With multiple monitors, if you specify the window handle and set lpOperation to "Properties", any windows created by ShellExecute may not appear in the correct position. To obtain information about the application that is launched as a result of calling ShellExecute, use ShellExecuteEx. See Also
    IShellExecuteHookRequirements 
      Windows NT/2000: Requires Windows NT 3.1 or later. 
      Windows 95/98: Requires Windows 95 or later. 
      Header: Declared in shellapi.h. 
      Import Library: shell32.lib.
      

  4.   

    风!多谢!!!据说有个功能更强大的shellexecuteEx函数,能在MSDN中找到吗?
      

  5.   

    我给你吧
    ShellExecuteEx
    Performs an action on a file. BOOL ShellExecuteEx(
        LPSHELLEXECUTEINFO lpExecInfo
    );Parameters
    lpExecInfo 
    Address of a SHELLEXECUTEINFO structure that contains and receives information about the application being executed. 
    Return Values
    Returns TRUE if successful, or FALSE otherwise. Call GetLastError for error information. Res
    With multiple monitors, if you specify an hwnd and set the lpVerb member of lpExecInfo to "Properties" , any windows created by ShellExecuteEx may not appear in the correct position. If the function succeeds, it sets the hInstApp member of the SHELLEXECUTEINFO structure to a value greater than 32. If the function fails, hInstApp is set to the SE_ERR_XXX error value that best indicates the cause of the failure. Although hInstApp is declared as an HINSTANCE for compatibility with 16-bit Microsoft Windows applications, it is not a true HINSTANCE. It can only be cast to an integer and compared to either 32 or the SE_ERR_XXX error codes.Note: the SE_ERR_XXX error values are provided for compatibility with ShellExecute. To retrieve more accurate error information, use GetLastError. It may return one of the following values: ERROR_FILE_NOT_FOUND  The specified file was not found. 
    ERROR_PATH_NOT_FOUND  The specified path was not found. 
    ERROR_DDE_FAIL  The DDE transaction failed. 
    ERROR_NO_ASSOCIATION  There is no application associated with the given file name extension. 
    ERROR_ACCESS_DENIED  Access to the specified file is denied. 
    ERROR_DLL_NOT_FOUND  One of the library files necessary to run the application can't be found. 
    ERROR_CANCELLED  The function prompted the user for additional information, but the user canceled the request. 
    ERROR_NOT_ENOUGH_MEMORY  There is not enough memory to perform the specified action. 
    ERROR_SHARING_VIOLATION  A sharing violation occurred. See Also
    IShellExecuteHookRequirements 
      Version 4.00 and later of Shell32.dll  Windows NT/2000: Requires Windows NT 4.0 or later. 
      Windows 95/98: Requires Windows 95 or later. 
      Header: Declared in shellapi.h. 
      Import Library: shell32.lib.
      

  6.   

    还有
    SHELLEXECUTEINFO
    Contains information used by ShellExecuteEx. typedef struct _SHELLEXECUTEINFO{
        DWORD cbSize; 
        ULONG fMask; 
        HWND hwnd; 
        LPCTSTR lpVerb; 
        LPCTSTR lpFile; 
        LPCTSTR lpParameters; 
        LPCTSTR lpDirectory; 
        int nShow; 
        HINSTANCE hInstApp; 
     
        // Optional members 
        LPVOID lpIDList; 
        LPCSTR lpClass; 
        HKEY hkeyClass; 
        DWORD dwHotKey; 
    union {
    HANDLE hIcon;
    HANDLE hMonitor;
    };
        HANDLE hProcess; 
    } SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO; 
     
    Members
    cbSize 
    Size of the structure, in bytes. 
    fMask 
    Array of flags that indicate the content and validity of the other structure members. This can be a combination of the following values. SEE_MASK_CLASSKEY  Use the class key given by the hkeyClass member.  
    SEE_MASK_CLASSNAME  Use the class name given by the lpClass member.  
    SEE_MASK_CONNECTNETDRV  Validate the share and connect to a drive letter. The lpFile member is a Universal Naming Convention (UNC) path of a file on a network.  
    SEE_MASK_DOENVSUBST  Expand any environment variables specified in the string given by the lpDirectory or lpFile member.  
    SEE_MASK_FLAG_DDEWAIT  Wait for the DDE conversation to terminate before returning (if the ShellExecuteEx function causes a DDE conversation to start). For circumstances in which this flag is necessary, see the Res section. 
    SEE_MASK_FLAG_NO_UI  Do not display an error message box if an error occurs.  
    SEE_MASK_HMONITOR Use this flag when specifying a monitor on multimonitor systems. The monitor is specified in the hMonitor member. This flag cannot be combined with SEE_MASK_ICON. 
    SEE_MASK_HOTKEY  Use the hot key given by the dwHotKey member. 
    SEE_MASK_ICON  Use the icon given by the hIcon member. This flag cannot be combined with SEE_MASK_HMONITOR. 
    SEE_MASK_IDLIST  Use the item identifier list given by the lpIDList member. The lpIDList member must point to an ITEMIDLIST structure. 
    SEE_MASK_INVOKEIDLIST  Use the IContextMenu interface of the selected item's context menu handler. Use either lpFile to identify the item by its file system path or lpIDList to identify the item by its PIDL. This flag allows applications to use ShellExecuteEx to invoke verbs from context menu extensions instead of the static verbs listed in the registry. 
    SEE_MASK_NOCLOSEPROCESS  Use to indicate that the hProcess member receives the process handle. This handle is typically used to allow an application to find out when a process created with ShellExecuteEx terminates. In some cases, such as when execution is satisfied through a DDE conversation, no handle will be returned. The calling application is responsible for closing the handle when it is no longer needed. 
    SEE_MASK_NO_CONSOLE Use to create a console for the new process instead of having it inherit the parent's console. It is equivalent to using a CREATE_NEW_CONSOLE flag with CreateProcess. 
    SEE_MASK_UNICODE Use this flag to indicate a Unicode application. hwnd 
    Window handle to any message boxes that the system might produce while executing this function. 
    lpVerb 
    String, referred to as a verb, that specifies the action to be performed. The set of available verbs depends on the particular file or folder. Generally, the actions available from an object's context menu are available verbs. For more specific information about verbs, see Object Verbs. For further discussion of context menus, see Extending Context Menus. The following verbs are commonly used. edit  Launches an editor and opens the document for editing. If lpFile is not a document file, the function will fail. 
    explore Explores the folder specified by lpFile.  
    find Initiates a search starting from the specified directory. 
    open  Opens the file specified by the lpFile parameter. The file can be an executable file, a document file, or a folder. 
    print  Prints the document file specified by lpFile. If lpFile is not a document file, the function will fail. 
    properties  Displays the file or folder's properties. If you set this parameter to NULL:For systems prior to Microsoft® Windows® 2000, the default verb is used if it is valid and available in the registry. If not, the "open" verb is used. 
    For Windows 2000 and later systems, the default verb is used if available. If not, the "open" verb is used. If neither verb is available, the system uses the first verb listed in the registry. 
    lpFile 
    Address of a null-terminated string that specifies the name of the file or object on which ShellExecuteEx will perform the action specified by the lpVerb parameter. The system registry verbs that are supported by the ShellExecuteEx function include "open" for executable files and document files and "print" for document files for which a print handler has been registered. Other applications might have added shell verbs through the system registry, such as "play" for AVI and WAV files. To specify a shell namespace object, pass the fully qualified parse name and set the SEE_MASK_INVOKEIDLIST flag in the fMask parameter. 
    Note If the path is not included with the name, the current directory is assumed. lpParameters 
    Address of a null-terminated string that contains the application parameters. The parameters must be separated by spaces. To include double quotation s, enclose each  in a pair of quotation s, as in the following example. 
    sei.lpParameters = "An example: \"\"\"quoted text\"\"\"";In this case, the application receives three parameters: An, example:, and "quoted text".
      

  7.   

    SHELLEXECUTEINFO
    Contains information used by ShellExecuteEx. typedef struct _SHELLEXECUTEINFO{
        DWORD cbSize; 
        ULONG fMask; 
        HWND hwnd; 
        LPCTSTR lpVerb; 
        LPCTSTR lpFile; 
        LPCTSTR lpParameters; 
        LPCTSTR lpDirectory; 
        int nShow; 
        HINSTANCE hInstApp; 
     
        // Optional members 
        LPVOID lpIDList; 
        LPCSTR lpClass; 
        HKEY hkeyClass; 
        DWORD dwHotKey; 
    union {
    HANDLE hIcon;
    HANDLE hMonitor;
    };
        HANDLE hProcess; 
    } SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO; 
     
    Members
    cbSize 
    Size of the structure, in bytes. 
    fMask 
    Array of flags that indicate the content and validity of the other structure members. This can be a combination of the following values. SEE_MASK_CLASSKEY  Use the class key given by the hkeyClass member.  
    SEE_MASK_CLASSNAME  Use the class name given by the lpClass member.  
    SEE_MASK_CONNECTNETDRV  Validate the share and connect to a drive letter. The lpFile member is a Universal Naming Convention (UNC) path of a file on a network.  
    SEE_MASK_DOENVSUBST  Expand any environment variables specified in the string given by the lpDirectory or lpFile member.  
    SEE_MASK_FLAG_DDEWAIT  Wait for the DDE conversation to terminate before returning (if the ShellExecuteEx function causes a DDE conversation to start). For circumstances in which this flag is necessary, see the Res section. 
    SEE_MASK_FLAG_NO_UI  Do not display an error message box if an error occurs.  
    SEE_MASK_HMONITOR Use this flag when specifying a monitor on multimonitor systems. The monitor is specified in the hMonitor member. This flag cannot be combined with SEE_MASK_ICON. 
    SEE_MASK_HOTKEY  Use the hot key given by the dwHotKey member. 
    SEE_MASK_ICON  Use the icon given by the hIcon member. This flag cannot be combined with SEE_MASK_HMONITOR. 
    SEE_MASK_IDLIST  Use the item identifier list given by the lpIDList member. The lpIDList member must point to an ITEMIDLIST structure. 
    SEE_MASK_INVOKEIDLIST  Use the IContextMenu interface of the selected item's context menu handler. Use either lpFile to identify the item by its file system path or lpIDList to identify the item by its PIDL. This flag allows applications to use ShellExecuteEx to invoke verbs from context menu extensions instead of the static verbs listed in the registry. 
    SEE_MASK_NOCLOSEPROCESS  Use to indicate that the hProcess member receives the process handle. This handle is typically used to allow an application to find out when a process created with ShellExecuteEx terminates. In some cases, such as when execution is satisfied through a DDE conversation, no handle will be returned. The calling application is responsible for closing the handle when it is no longer needed. 
    SEE_MASK_NO_CONSOLE Use to create a console for the new process instead of having it inherit the parent's console. It is equivalent to using a CREATE_NEW_CONSOLE flag with CreateProcess. 
    SEE_MASK_UNICODE Use this flag to indicate a Unicode application. hwnd 
    Window handle to any message boxes that the system might produce while executing this function. 
      

  8.   

    真是非常感谢大家!!!但我不太明白这几个函数,能否简要说明一下如何用
    它们实现调用flashpla.exe后自动播放2.swf???我现用shellexecute()
    只能打开flashpla.exe ,但不能自动播放.swf文件???
    刚才网络堵车掉线了,所以这么晚才看到,抱歉@_^
      

  9.   

    还是用CreateProcess比较好吧?你要播放的2.swf可以加在命令行吧,例子
    STARTUPINFO startinfo;
    GetStartupInfo(&startinfo);
    PROCESS_INFORMATION processinfo;
    CreateProcess("c:\\windows\\flashplay.exe 2.swf","",NULL,NULL,0,CREATE_NEW_CONSOLE,NULL,"c:\\",&startinfo,&processinfo);
    试试吧,不知道flashplay的参数行是怎么样的,你自己试试吧,祝你好运。:)
      

  10.   

    小麻烦!望高人赐教--使用CREATEPROCESS()调用另一程序时,编译无误
    ,但运行出现
     ["0x5f43351b"指令引用的"0x00000000"内存。该内存不能为"read" ]   为什么??????是否因为少添加了什么.LIB?#include "stdafx.h"
    #include "10.h"
    #include "WINBASE.H"main(void)
    {
    STARTUPINFO si;
    GetStartupInfo(&si);
    PROCESS_INFORMATION pi;
    CreateProcess("e:\\flashplay.exe"," ",
                     NULL,NULL,FALSE,CREATE_NEW_CONSOLE,NULL,"e:\\",&si,&pi);
    return(0);
    } Win2K+Vc6
      

  11.   

    小麻烦!望高人赐教--使用CREATEPROCESS()调用另一程序时,编译无误
    ,但运行出现
     ["0x5f43351b"指令引用的"0x00000000"内存。该内存不能为"read" ]   为什么??????是否因为少添加了什么.LIB?#include "stdafx.h"
    #include "10.h"
    #include "WINBASE.H"main(void)
    {
    STARTUPINFO si;
    GetStartupInfo(&si);
    PROCESS_INFORMATION pi;
    CreateProcess("e:\\flashplay.exe"," ",
                     NULL,NULL,FALSE,CREATE_NEW_CONSOLE,NULL,"e:\\",&si,&pi);
    return(0);
    } Win2K+Vc6
      

  12.   

    ShellExecute( NULL , "open" , "1.swf" , NULL , NULL , SW_SHOWNORMAL );orShellExecute( NULL , "open" ,"c:\\flashplay.exe" , "c:\\1.swf" , NULL , SW_SHOWNORMAL );