shellexecute 中的SW—HEDE为什么不起作用?急急急!!!(50分)

  • 主题发起人 主题发起人 shineya
  • 开始时间 开始时间
S

shineya

Unregistered / Unconfirmed
GUEST, unregistred user!
用SHELLEXECUTE启动其他应用程序并希望在启动之时就隐藏它,为什么用了SW_HIDE<br>还不起作用(程序窗体仍然显现出来了)?
 
刚才实验了一下,这个可以<br>ShellExecute(Handle,nil,'C:/Command.com',nil,'C:/',SW_Hide);<br>这个不可以<br>ShellExecute(Handle,nil,'Calc.Exe',nil,'C:/Windows',SW_Hide);<br>因此判断应该是所属的Application和Form.Handle不一致的问题吧,他将Application<br>给隐藏了,本身就是不可见的,即使Show,也没戏,但是又有一点解释不通了,使用<br>SW_SHOWMAXIMIZED却有效,没办法,等高手解决吧。<br>
 
MIXIMIZE和MINIMIZE是都可以的,甚至用3,7,9等数字代替SW_XXXX都可以,<br>但就篇HIDE没有作用,期待更合理的回答!对了,谁能给我提供一些国外的<br>DELPHI论坛网址,谢了!
 
快来呀,50分呢!
 
改用CreateProcess吧<br>var<br>&nbsp; zAppName:array[0..512] of char;<br>&nbsp; StartupInfo:TStartupInfo;<br>&nbsp; ProcessInfo:TProcessInformation;<br>begin<br>&nbsp; zAppName:='c:/windows/calc.exe' &nbsp;<br>&nbsp; FillChar(StartupInfo,Sizeof(StartupInfo),#0);<br>&nbsp; StartupInfo.cb := Sizeof(StartupInfo);<br>&nbsp; StartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br>&nbsp; StartupInfo.wShowWindow := SW_MINIMIZE;<br>&nbsp; if not CreateProcess(nil,<br>&nbsp; &nbsp; zAppName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ pointer to command line string }<br>&nbsp; &nbsp; nil, &nbsp; { pointer to process securityattributes }<br>&nbsp; &nbsp; nil, &nbsp; { pointer to thread security attributes }<br>&nbsp; &nbsp; false, { handle inheritance flag }<br>&nbsp; &nbsp; NORMAL_PRIORITY_CLASS,<br>&nbsp; &nbsp; nil, &nbsp; { pointer to new environment block }<br>&nbsp; &nbsp; nil, &nbsp; { pointer to current directory name }<br>&nbsp; &nbsp; StartupInfo, &nbsp; &nbsp; &nbsp; { pointer to STARTUPINFO }<br>&nbsp; &nbsp; ProcessInfo) &nbsp; &nbsp; &nbsp; { pointer to PROCESS_INF }<br>&nbsp; then <br>&nbsp; &nbsp;raise Exception.Create('execution error!')<br>end;
 
cxzhu,谢谢你的参与,可是我没用过CREATEPROCESS,不知道怎样创建它,<br>你的代码调试没通过,能不能给的再详细点!
 
不是可以用Application.Show(Main)Form := False;
 
//所有源程序都给你吧,希望多给点分。<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; hnd: THANDLE<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>function WinExec_NoShow(FileName:String):THANDLE;<br>var<br>&nbsp; zAppName:array[0..512] of char;<br>&nbsp; zCurDir:array[0..255] of char;<br>&nbsp; WorkDir:String;<br>&nbsp; StartupInfo:TStartupInfo;<br>&nbsp; ProcessInfo:TProcessInformation;<br>&nbsp; returnresult:DWORD;<br>&nbsp; i: integer;<br>begin<br>&nbsp; StrPCopy(zAppName,FileName);<br>&nbsp; WorkDir := ExtractFilePath(ParamStr(0));<br>&nbsp; StrPCopy(zCurDir,WorkDir);<br>&nbsp; FillChar(StartupInfo,Sizeof(StartupInfo),#0);<br>&nbsp; StartupInfo.cb := Sizeof(StartupInfo);<br>&nbsp; StartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br>&nbsp; StartupInfo.wShowWindow := SW_SHOWDEFAULT;<br>&nbsp; if CreateProcess(nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; zAppName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ pointer to command line string }<br>&nbsp; &nbsp; &nbsp; &nbsp; nil, &nbsp; { pointer to process securityattributes }<br>&nbsp; &nbsp; &nbsp; &nbsp; nil, &nbsp; { pointer to thread security attributes }<br>&nbsp; &nbsp; &nbsp; &nbsp; false, { handle inheritance flag }<br>&nbsp; &nbsp; &nbsp; &nbsp; CREATE_SUSPENDED,<br>&nbsp; &nbsp; &nbsp; &nbsp; nil, &nbsp; { pointer to new environment block }<br>&nbsp; &nbsp; &nbsp; &nbsp; nil, &nbsp; { pointer to current directory name }<br>&nbsp; &nbsp; &nbsp; &nbsp; StartupInfo, &nbsp; &nbsp; &nbsp; { pointer to STARTUPINFO }<br>&nbsp; &nbsp; &nbsp; &nbsp; ProcessInfo) &nbsp; &nbsp; &nbsp; { pointer to PROCESS_INF }<br>&nbsp; then<br>&nbsp; &nbsp; Result := ProcessInfo.hThread<br>&nbsp; else<br>&nbsp; &nbsp; Result := NULL;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; hnd := WinExec_NoShow('calc');<br>&nbsp; if hnd = NULL then<br>&nbsp; &nbsp; ShowMessage('creation error');<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; if hnd &lt;&gt; NULL then<br>&nbsp; &nbsp; ResumeThread(hnd);<br>end;<br><br>end.<br>
 
谢谢CXZHU,我要认真研究一下CREATEPROCESS,不过程序能通过的话,<br>我会先记上你的20分的。
 
to:cxzhu,不好意思,近段出差了,我的程序已完成,我放弃了这项功能。现在很忙,<br>没有时间研究,不过你的代码我在D6下通不过,NULL错误,不知什么原因,请指教。
 
我是在D5下调试的,一切顺利。<br><br>以下引用Delphi 5 Help<br><br>Null variable<br>See also<br>-------------------------------------------------------------------------------<br>Null represents the null Variant.<br><br>Unit<br>System<br><br>Category<br>variant support routines<br>var Null: Variant;<br>Description<br>Use Null to indicate unknown or missing data. Null can be assigned to variables <br>in an application that must contain a null value. Assigning Null to a Variant <br>variable does not cause an error, and Null can be returned from any function <br>with a Variant return value.<br><br>Assigning Null to a variable of any type other than Variant causes either a <br>compile-time error or raises an EVariantError exception. For example, in the <br>following code the assignment of v, the Null Variant, to Variant q is successful;<br>&nbsp;whereas the conversion of Variant v, which is now Null, to the integer return <br>type of the Test function, raises an exception.<br><br>function Test(v: Variant): Integer;<br>var<br>&nbsp; q: Variant;<br>&nbsp; msg: string;<br>begin<br>&nbsp; q := v; { this is ok, since q is a variant }<br>&nbsp; if VarIsNull(q) then<br>&nbsp; &nbsp; msg := 'q is a null variant'<br>&nbsp; else<br>&nbsp; &nbsp; msg := 'q is not a null variant';<br>&nbsp; ShowMessage(msg);<br>&nbsp; Result := v; { this raises an exception!!!}<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; Test(Null);<br>end;<br><br>Expressions involving Null always result in Null. Thus, Null is said to<br>"Propagate"through intrinsic functions that return Variant data types. If any <br>part of the expression evaluates to Null, the entire expression evaluates to <br>Null.
 
to:cxzhu, under delphi 6, compile error shows, undeclared identifier 'NULL',<br>refer to every statement 'Result := Null;' I am quite puzzling, null need not to<br>be declared, I think. Hope to help me. Thanks.
 
不好意思,这么长时间没能上网,现把问题结束。谢谢各位参与。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部