调用其它程序
何志丹
WinExec
原型:
UINT WinExec(
LPCSTR lpCmdLine, // address of command line
UINT uCmdShow // window style for new application
);
用于十六位操作系统及兼容系统.
例如:
WinExec("notepad.exe f://调用程序.txt",SW_SHOW);
WinExec("notepad.exe ",SW_SHOW);
不同的参数用空格分开,故路径中不能有空格,而大部分程序默认是安装在".../Program Files/...",如word,这极大的限制了WinExec的应用范围.
以上可不带路径:
1,程序所在目录.
2,当前路径.
3,系统目录,可以用GetSystemDirectory得到.
4,Windows 目录. 可以用TheGetWindowsDirectory得到.
5,在环境变量中设置的目录.ShellExecute
原型:
HINSTANCE ShellExecute(
HWND hwnd, //父窗口句柄
LPCTSTR lpOperation, //操作,"open","print","explore"
LPCTSTR lpFile, //文件名,前面可加路径
LPCTSTR lpParameters, //参数
LPCTSTR lpDirectory, //默认文件夹
INT nShowCmd //显示方式
);打开一个应用程序
ShellExecute(this->m_hWnd,"open","calc.exe","","", SW_SHOW );
或
ShellExecute(this->m_hWnd,"open","notepad.exe","c:/MyLog.log","",SW_SHOW );打开一个同系统程序相关连的文档
ShellExecute(this->m_hWnd,"open","c:/abc.txt","","",SW_SHOW );激活相关程序,发送EMAIL
ShellExecute(this->m_hWnd,"open","mailto:nishinapp@yahoo.com","","", SW_SHOW );用系统打印机打印文档
ShellExecute(this->m_hWnd,"print","c:/abc.txt","","", SW_HIDE);lpParameters的用法示例:
一,建立一个可以接受参数的程序call.exe,添加如下代码:
BOOL CCallApp::InitInstance()
{
int n = __argc;
for(int i = 1 ; i < n ; i++)
AfxMessageBox(__targv[i]);
//__targv[0]存储的是程序的文件名
...
}
二,Alt + F7的进行Project setting, Debug -> program argurments ->"1 2 3 4 5".
如果有多个参数,用空格分开.
三,运行.
四,执行ShellExecute(NULL,NULL,"f://call.exe","1 2 3 4 5",NULL,SW_SHOW);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
);STARTUPINFO startupInfo;
memset(&startupInfo,0,sizeof(STARTUPINFO));
startupInfo.cb = sizeof(STARTUPINFO);示例:
//程序最启动时最大化
startupInfo.dwFlags |= STARTF_USESHOWWINDOW;
startupInfo.wShowWindow = SW_SHOWMAXIMIZED;
//运行....exe
PROCESS_INFORMATION ProcessInfo;
BOOL bCreate = ::CreateProcess
(
"f://call.exe",// 1 2 3 4",
NULL,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&startupInfo,
&ProcessInfo); //等到call.exe执行完毕
WaitForSingleObject(ProcessInfo.hProcess,1000000);
MessageBox("调用程序结束!");
vc入门宝典十二(调用其它程序)
原创闻缺陷则喜何志丹 博主文章分类:VCMFC\C#界面 ©著作权
文章标签 attributes null application 文档 command 文章分类 运维
©著作权归作者所有:来自51CTO博客作者闻缺陷则喜何志丹的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:vc入门宝典六(多线程)
下一篇:VC雕虫小技集(一)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
vc入门宝典(九)
集合类使用心得何志丹MFC提供集合类(Collect)专门负责数据对象的存储和管理,MFC的集合类分为三类,分别用于处
数据结构 mfc null class list -
vc入门宝典(十)
消息何志丹PreTranslateMessage函数顾名思义,就是在消息被翻译之前,做的一些事.我们可以屏蔽一个键
command 编辑框 菜单项 鼠标移动 -
VC入门宝典十一(xml)
xml 何志丹我们建立一个xml文件,内容如图所示:一,建立一个基于对话框的程序,工程名为xml;二, 初始化OLE.BOOL CXmlApp::InitInstance(){
xml attributes null xml文件 运行库 -
VC入门宝典三(String)
CString何志丹主要内容:1,主要函数的实现2,常用函数3.CString与char []的相互转换4,将NULL字节放入CString中 vc中最主要函
string delete insert microsoft null -
vc入门宝典六(多线程)
多线程 何志丹主要内容:1, 工作者线程2, 用户界面线程3, 同步线程被分为工作者线程和用户用户界面线程
多线程 thread attributes menu null -
vc入门宝典五(对话框)
对话框 何志丹主要内容:1, 建立有模式对话框和无模式对话框2, 控件的对齐及焦点设置3,
dialog layout 工作 ini 控件 -
vc入门宝典七(工具栏)
工具栏 何志丹主要内容:1, 概要。2, 常用函数3, 实例。4, 动态建立工具条5, 在工具栏中嵌控件6, 用对话框加位图按钮作工具条 我们可以在资源编辑器的ToolBar
工具 styles button 框架 command