• 执行外部文件的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
    );

  • 相关阅读:
    求两图的 对比度
    关于opencv中的颜色模型转换之CV_BGR2HSV
    转 C++函数返回值,你必须注意的问题
    opencv 3.2 vs2015 debug assertion __acrt_first_block == header
    vs的【warning C4996:'fopen': This function or variable may be unsafe】解决方案
    c++ opencv 3.2 +Mfc VS2015窗体显示图片方法
    c++中“箭头(->)”和“点号(.)”操作符的区别
    C# devexpress gridcontrol 分页 控件制作
    c#Md5 32位加密结果少了两个0的原因
    opencv 线,椭圆 圆
  • 原文地址:https://www.cnblogs.com/mywolrd/p/1930729.html
Copyright © 2020-2023  润新知