关于AllocConsole(120分)

  • 主题发起人 主题发起人 歪就歪
  • 开始时间 开始时间

歪就歪

Unregistered / Unconfirmed
GUEST, unregistred user!
在程序里,需要启动CONSOLE,使用了AllocConsole。但如何才能控制有<br>它产生的CONSOLE的大小/位置/HIDE呢?<br><br>我现在的实现HIDE的办法是<br>ALLOCCONSOLE;<br>然后在FINDWINDOW,在SHOWWINDOW(HIDE),但这样作的效果不好。CONSOLE<br>会先显示一下再消失。<br><br>请问,ALLOCCONSOLE调用前,是否能设置CONSOLE的窗口隐藏或大小么?<br><br>谢谢!<br><br>
 
怎么没人理?再加80分……
 
别介啊,同志么?是我这问题没说清楚?<br><br>〖〖〖还是这里没人会DELPHI?〗〗〗<br><br>再加100分,等得到满意答案后给!
 
不甘心!刷!
 
呵呵,这问题没人能回答,我怎么样才能把分数收回呢?
 
就是嘛,有钱的捧的钱场,没钱的捧个人场。<br>我不会答题,捧场来了。
 
我不说话
 
http://www.developersdomain.com/vb/articles/redirectpipe.htm<br>ps.请留下或email给我您的电话。
 
http://www.developersdomain.com/vb/articles/redirectpipe.htm 上介绍的行不行?
 
Hi, yysun:<br><br>thanks, and sorry for delay answer.<br><br>I check the VB code, it is pretty similar with mine. But I will try to move it in Delphi and have a try.<br><br>You can call me at anytime at (416)831.0628(cell). Or Email me at: tianhai@hotmail.com<br><br>y9y
 
Thanks, y9y, here is another information for you:<br>Free Borland Products Seminar: Nov.14, Toronto, ON<br>Go and have a look at Kylix :)
 
http://www.developersdomain.com/vb/articles/redirectpipe.htm <br>那个VB的程序似乎只能在NT下运行,<br>我把它改成DELPHI,发现实际上和ALLOCCONSOLE结果一样<br>只是它用CREATEPROCESS控制得更加细致一些,隐藏窗口自然不是问题<br>不过我发现是不是应该在CREATEPROCESS前用GETSTARTUPINFO取出缺省的STARTUPINFO呢?<br>它用的INPUT、OUTPUT、ERROR的HANDLE和ALLOCCONSOLE后缺省的HANDLE是一样的<br>而且它在控制95的时候用了一个程序再次重定向,似乎有些...<br><br>另外不知道各位有没有用过NT下的NETCAT,它好象也只能在NT下用,95下一运行就死...
 
YYSUN:谢谢,NOV 14,我记住了。<br><br>NETWIND:对,我觉得ALLOCCONSOLE也是为了重新定向它的输入/输出,YYSUN给的VB代码<br>我也尝试用DELPHI写了,在WINDOW95/98环境下,这段代码运行到:<br>&nbsp;ReadFile(hReadPipe, sBuffer, 256, lngBytesRead, nil);<br><br>是会死掉。<br><br>代码如下<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; proc : PROCESS_INFORMATION;<br>&nbsp; start : STARTUPINFO;<br>&nbsp; sa : SECURITY_ATTRIBUTES;<br>&nbsp; psa: &nbsp; &nbsp; PSecurityAttributes;<br>&nbsp; hReadPipe : THandle;<br>&nbsp; hWritePipe : THandle;<br>&nbsp; sOutput : String;<br>&nbsp; lngBytesRead : dword;<br>&nbsp; ret : boolean;<br>&nbsp; sBuffer : &nbsp;Array [0..255] of char;<br><br>begin<br>&nbsp; &nbsp; sa.nLength := sizeof(TSECURITYATTRIBUTES);<br>&nbsp; &nbsp; sa.bInheritHandle := True;<br>&nbsp; &nbsp; &nbsp;sa.lpSecurityDescriptor := nil;<br>&nbsp; &nbsp; &nbsp;psa := @sa;<br>&nbsp; &nbsp; ret := CreatePipe(hReadPipe, hWritePipe, psa, 0);<br>&nbsp; &nbsp; If not ret Then begin<br>&nbsp; &nbsp; &nbsp; showmessage('pipe create err');<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; FillChar(Start, Sizeof(Start), #0);<br>&nbsp; &nbsp; start.cb := SizeOf(start);<br>&nbsp; &nbsp; start.dwFlags := STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW;<br>&nbsp; &nbsp; start.hStdOutput := hWritePipe;<br>&nbsp; &nbsp; start.hStdError := hWritePipe;<br>&nbsp; &nbsp; start.wShowWindow := SW_hide;<br>//CreateProcess(nil, PChar('C:/tmp/console1/project1.exe'), sa, sa, True,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;NORMAL_PRIORITY_CLASS,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil, nil, start, proc);<br><br>&nbsp; &nbsp; ret := &nbsp;CreateProcessA(nil, PChar('C:/tmp/console1/project1.exe'), psa, psa, true, NORMAL_PRIORITY_CLASS, &nbsp;nil, nil, Start, Proc);<br>&nbsp; &nbsp; If not ret Then begin<br>&nbsp; &nbsp; &nbsp; showmessage('createproc err');<br>&nbsp; &nbsp; &nbsp; caption := 'err';<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; End;<br>&nbsp; &nbsp; CloseHandle(hWritePipe);<br>&nbsp; &nbsp; ret := false;<br>&nbsp; &nbsp; FillChar(sBuffer, Sizeof(sBuffer), #0);<br>&nbsp; &nbsp; repeat<br>&nbsp; &nbsp; &nbsp; ret := ReadFile(hReadPipe, sBuffer, 256, lngBytesRead, nil);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add(sBuffer);<br>&nbsp; &nbsp; until<br>&nbsp; &nbsp; &nbsp; ret = false;<br>&nbsp; &nbsp; CloseHandle(proc.hProcess);<br>&nbsp; &nbsp; CloseHandle(proc.hThread);<br>&nbsp; &nbsp; CloseHandle(hReadPipe);<br>&nbsp; &nbsp; caption := sOutput;<br>end;<br><br><br>
 
那个网页中说了95下会死机,所以才用C写了一个小的程序.<br>... A solution to this is to launch a hidden Win32 console application <br>to act as a proxy been your application and the ms-dos program. &nbsp;...<br>我觉得妙就妙在那个不可见的程序, 你不可以把它们合起来吧.
 
YYSUN:<br><br>是,那段文字我看了,看了之后,只觉他解释的不对,或我什么地方没搞对,有两点:<br>1 他说,在WIN95下运行32位控制台程序没问题,但若运行16位的就有麻烦。<br>可我的控制台程序是用DELPHI5写的,100%的32位程序<br><br>2 他解释死机的原因是:程序已经关闭,但很明显,我的DOS程序并没有关闭。<br><br>出于上述原因,我没有再理会它。<br><br>现在,我再去TRY,谢谢!
 
第一次来看看,顺便说点话
 
接受答案了.
 

Similar threads

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