zoukankan      html  css  js  c++  java
  • 执行外部文件的API

    1.HINSTANCE ShellExecute(         
        HWND hwnd,             // 父窗口句柄  NULL
        LPCTSTR lpOperation,   // 动作  "Open" "edit" "explore"..
        LPCTSTR lpFile,        // 要通过动作来操纵的文件对象 "notepad"
        LPCTSTR lpParameters,  // 若lpFile为可执行文件,lpParameters就是该可执行文件的命令行参数 "test.txt"
        LPCTSTR lpDirectory,   // 默认目录  NULL
        INT nShowCmd           // SW_HIDE ,SW_MAXIMIZE ,SW_MINIMIZE SW_SHOW SW_SHOWDEFAULT....
    );

    BOOL ShellExecuteEx(         
        LPSHELLEXECUTEINFO lpExecInfo
    );

    应用:
    打开一个应用程序:
             ShellExecute(this->m_hWnd,"Open","calc.exe","","",SW_SHOW);
    打开一个同系统程序相关连的文档:
             ShellExecute(this->m_hWnd,"open","c:\\abc.txt","","",SW_SHOW);
    打开一个网页:
             ShellExecute(this->m_hWnd,"open","http://www.google.com","","",SW_SHOW);
    激活相关程序,发送EMAIL:
             ShellExecute(this->m_hWnd,"open","maito:future_fighter123@yahoo.com.cn","","",SW_SHOW);
    用系统打印机打印文档:
             ShellExecute(this->m_hWnd,"print","c:\\abc.txt","","",SW_HIDE);
    用系统查找功能来查找指定文件:
             ShellExecute(this->m_hWnd,"find","c:\windows",NULL,NULL,SW_SHOW);
    启动一个程序,直到它运行结束:
     SHELLEXECUTEINFO ShExecInfo = {0};
     ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
     ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
     ShExecInfo.hwnd = NULL;
     ShExecInfo.lpVerb = NULL;
     ShExecInfo.lpFile = "c:\\MyProgram.exe";  
     ShExecInfo.lpParameters = ""; 
     ShExecInfo.lpDirectory = NULL;
     ShExecInfo.nShow = SW_SHOW;
     ShExecInfo.hInstApp = NULL; 
     ShellExecuteEx(&ShExecInfo);
     WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
         或者:
     PROCESS_INFORMATION ProcessInfo;
     STARTUPINFO StartupInfo; //This is an [in] parameter
     ZeroMemory(&StartupInfo, sizeof(StartupInfo));
     StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
     if(CreateProcess("c:\\winnt\\notepad.exe", NULL,
         NULL,NULL,FALSE,0,NULL,
         NULL,&StartupInfo,&ProcessInfo))
     {
         WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
         CloseHandle(ProcessInfo.hThread);
         CloseHandle(ProcessInfo.hProcess);
     } 
     else
     {
         MessageBox("The process could not be started...");
     }
    显示文件或文件夹的属性:
     SHELLEXECUTEINFO ShExecInfo ={0};
     ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
     ShExecInfo.fMask = SEE_MASK_INVOKEIDLIST ;
     ShExecInfo.hwnd = NULL;
     ShExecInfo.lpVerb = "properties";
     ShExecInfo.lpFile = "c:\\"; //can be a file as well
     ShExecInfo.lpParameters = "";
     ShExecInfo.lpDirectory = NULL;
     ShExecInfo.nShow = SW_SHOW;
     ShExecInfo.hInstApp = NULL;
     ShellExecuteEx(&ShExecInfo);


    2.UINT WinExec(
      LPCSTR lpCmdLine,   // 命令行参数
      UINT uCmdShow       // 显示方式,和ShowWindow的一样
    );

    3.BOOL CreateProcess(
      LPCTSTR lpApplicationName,
      LPTSTR lpCommandLine,
      LPSECURITY_ATTRIBUTES lpProcessAttributes,
      LPSECURITY_ATTRIBUTES lpThreadAttributes,
      BOOL bInheritHandles,
      DWORD dwCreationFlags,
      LPVOID lpEnvironment,
      LPCTSTR lpCurrentDirectory,
      LPSTARTUPINFO lpStartupInfo,
      LPPROCESS_INFORMATION lpProcessInformation
    );

  • 相关阅读:
    2016阿里巴巴73款开源产品全向图
    在微软5年,我学到的几个小技能
    2016 年 Java 工具和技术的调查:IDEA 已超过
    PHP学习总结(9)——PHP入门篇之WAMPServer服务控制面板介绍
    Template Pattern & Strategy Pattern
    天之道,损有余而补不足。人之道,则不然,损不足以奉有余。孰能有余以奉天下?唯有道者
    [林锐13]面向对象程序设计方法概述
    [林锐8.4]函数指针
    ZT c++ 中的重载全局new,delete
    ZT 自定义operator new与operator delete的使用(1)
  • 原文地址:https://www.cnblogs.com/mywolrd/p/1930729.html
Copyright © 2011-2022 走看看