关于进程(bcb原代码)(50分)

  • 主题发起人 主题发起人 a_fi
  • 开始时间 开始时间
A

a_fi

Unregistered / Unconfirmed
GUEST, unregistred user!
#include &lt;ShellApi.hpp&gt;<br>//---------------------------------------------------------------------------<br>#pragma package(smart_init)<br>#pragma resource "*.dfm"<br>TForm1 *Form1;<br>//---------------------------------------------------------------------------<br>__fastcall TForm1::TForm1(TComponent* Owner)<br>: TForm(Owner)<br>{<br>}<br>//---------------------------------------------------------------------------<br><br>void __fastcall TForm1::Button1Click(TObject *Sender)<br>{<br>STARTUPINFO StartupInfo;<br>PROCESS_INFORMATION ProcessInfo;<br>char *sCommandLine;<br>bool bCreateProcess;<br><br>sCommandLine ="c://windows//notepad c://.1.txt";<br>StartupInfo.cb = sizeof(STARTUPINFO);<br>StartupInfo.dwFlags = STARTF_USESHOWWINDOW;<br>StartupInfo.wShowWindow = SW_NORMAL;<br>CreateProcess(NULL,sCommandLine.c_str(), NULL,<br>NULL, FALSE, CREATE_NEW_CONSOLE|NORMAL_PRIORITY_CLASS, NULL,<br>NULL, &amp;StartupInfo, &amp;ProcessInfo);<br><br>if (bCreateProcess)<br>WaitForSingleObject(ProcessInfo.hProcess, INFINITE);<br><br>if(bCreateProcess)<br>{<br>WaitForInputIdle(ProcessInfo.hProcess, 60000);<br>//time-out interval in milliseconds<br>Memo1-&gt;Clear();<br><br>Memo1-&gt;Lines-&gt;Add("你好");<br><br>}<br><br>}<br>==========================<br>question:<br>why not notepad open this file(c:/1.txt)?<br>为何记事本未运行,怎样使他打开指定的文件c:/1.txt?<br><br><br><br><br>
 
sCommandLine是一个字符串指针,<br>sCommandLine.c_str() 是什么? 没有看懂。
 
能運行嗎
 
CreateProcess(NULL,sCommandLine.c_str(), NULL,<br>NULL, FALSE, CREATE_NEW_CONSOLE|NORMAL_PRIORITY_CLASS, NULL,<br>NULL, &amp;StartupInfo, &amp;ProcessInfo);<br>参数不对,好好看一下帮助,<br>你在任务管理中看一下notepad.exe是否运行。如果运行了,就是<br>CREATE_NEW_CONSOLE|NORMAL_PRIORITY_CLASS参数的问题。
 
用winexec就可以了,WinExec("sCommandLine",SW_SHOW);<br>sCommandLine应该是定义为AnsiString才有sCommandLien.c_str();<br>可能sCommandLine = "c://windows//notepad.exe c://.1.txt";<br>
 
接受答案了.
 
后退
顶部