VC下代替system函数的API

来源:互联网 发布:两个表格数据匹配重复 编辑:程序博客网 时间:2024/05/17 18:44

在VC下调用system函数会出现dos窗口,如果不想让dos窗口出现,可以使用如下函数代替system函数:

1、createprocess

STARTUPINFO  si; 
ZeroMemory(&si,  sizeof(si)); 
si.cb = sizeof STARTUPINFO;

PROCESS_INFORMATION  pi; 
BOOL  res  =  CreateProcess(NULL, 
"c:\\winnt\\system32\\cmd.exe",  //  执行你的  dos  命令 
NULL, 
NULL, 
NULL, 
NORMAL_PRIORITY_CLASS    ¦  CREATE_NO_WINDOW, 
NULL, 
NULL, 
&si, 
&pi); 

if  (TRUE  ==  res) 

CloseHandle(pi.hProcess); 
CloseHandle(pi.hThread); 


把dwCreationFlags这个参数设置为CREATE_NO_WINDOW

 
2、ShellExecute [Ex]

用法:ShellExecute(NULL,  NULL,"xxx.exe",  NULL,  NULL,  SW_HIDE);

3、WinExec

不提倡用这个,用法:

WinExec("xxx.exe", SW_HIDE);

Note  This function is provided only for compatibility with 16-bit Windows. Applications should use theCreateProcess function.

原创粉丝点击