请教各位 怎样将应用程序在我的窗体里运行啊(20分)

  • 主题发起人 主题发起人 hangyang
  • 开始时间 开始时间
H

hangyang

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个这样的东西,就是让一个用应程序(exe文件)固定到我的窗体的Panel上来运行<br>。(应用程序的窗口小于panel窗口)。希望各位前辈能帮帮我。谢谢!分不多了哈,多多包涵。
 
这个涉及到ole技术,建议看看这方面的资料
 
你做一个模拟器,估计可以,不过可能有点难
 
各位前辈 ,我还要补充一点的是用应程序是DOS下的exe文件。怎样放在窗体里啊。也就是怎么就行绑架窗体啊。谢谢了
 
DOS?? 哈哈哈 &nbsp;要是DOS就不用那么麻烦了,管道输出到你程序界面上就行了<br>给你个例子,也是从别人那抄来改的,放个memo、edit、button<br>默认是执行命令行CMD.exe<br>从edit里输入命令<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, Grids;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; procedure Edit1KeyDown(Sender: TObject; var Key: Word;<br>&nbsp; &nbsp; &nbsp; Shift: TShiftState);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; inputCMD:string;<br>&nbsp; &nbsp; function OutPutCmdProText(Command:string; AOutPutMemo:TMemo; ATimeOut:Cardinal=0):byte;<br>&nbsp; public<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 TForm1.OutPutCmdProText(Command:string; AOutPutMemo:TMemo; ATimeOut:Cardinal=0):byte;<br>var<br>&nbsp; hOutPutReadPipe, hOutPutWritePipe, hInPutReadPipe, hInPutWritePipe:THandle;<br>&nbsp; si:STARTUPINFO;<br>&nbsp; lsa:SECURITY_ATTRIBUTES;<br>&nbsp; pi:PROCESS_INFORMATION;<br>&nbsp; cchReadBuffer,cchWriteBuffer:DWORD;<br>&nbsp; ph, fname:PChar;<br>&nbsp; tk:Cardinal;<br>begin<br>&nbsp; inputCMD:='';<br>&nbsp; result:=0;<br><br>&nbsp; fname:=allocmem(255);<br>&nbsp; ph:=AllocMem(5000);<br><br>&nbsp; lsa.nLength :=sizeof(SECURITY_ATTRIBUTES);<br>&nbsp; lsa.lpSecurityDescriptor :=nil;<br>&nbsp; lsa.bInheritHandle :=True;<br><br>&nbsp; if CreatePipe(hOutPutReadPipe,hOutPutWritePipe,@lsa,0)=false then<br>&nbsp; begin<br>&nbsp; &nbsp; result:=1;<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br><br>&nbsp; if CreatePipe(hInPutReadPipe,hInPutWritePipe,@lsa,0)=false then<br>&nbsp; begin<br>&nbsp; &nbsp; result:=1;<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br><br>&nbsp; fillchar(si,sizeof(STARTUPINFO),0);<br>&nbsp; si.cb :=sizeof(STARTUPINFO);<br>&nbsp; si.dwFlags :=(STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW);<br>&nbsp; si.wShowWindow :=SW_HIDE;<br>&nbsp; si.hStdInput:=hInPutReadPipe;<br>&nbsp; si.hStdOutput :=hOutPutWritePipe;<br>&nbsp; StrPCopy(fname,Command);<br><br>&nbsp; if CreateProcess( nil, fname, nil, nil, true, 0, nil, nil, si, pi) = False then<br>&nbsp; begin<br>&nbsp; &nbsp; result:=2;<br>&nbsp; &nbsp; FreeMem(ph);<br>&nbsp; &nbsp; FreeMem(fname);<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br><br>&nbsp; AOutPutMemo.Lines.Clear;<br>&nbsp; tk:=GetTickCount;<br>&nbsp; while true do<br>&nbsp; begin<br>&nbsp; &nbsp; application.HandleMessage;<br>&nbsp; &nbsp; if not PeekNamedPipe(hOutPutReadPipe,ph,1,@cchReadBuffer,nil,nil) then<br>&nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; if cchReadBuffer&lt;&gt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if ReadFile(hOutPutReadPipe,ph^,4096,cchReadBuffer,nil)=false then<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; ph[cchReadbuffer]:=chr(0);<br>&nbsp; &nbsp; &nbsp; AOutPutMemo.Lines.Add(ph);<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else if(WaitForSingleObject(pi.hProcess ,0)=WAIT_OBJECT_0) then<br>&nbsp; &nbsp; &nbsp; break<br>&nbsp; &nbsp; else if (ATimeOut&gt;0) and (GetTickCount-tk&gt;ATimeOut) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; TerminateProcess(pi.hProcess, 0);<br>&nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; if Length(inputCMD) &gt; 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; WriteFile(hInPutWritePipe, inputCMD[1], Length(inputCMD), cchWriteBuffer, nil);<br>&nbsp; &nbsp; &nbsp; inputCMD:='';<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br><br>&nbsp; ph[cchReadBuffer]:=chr(0);<br>&nbsp; AOutPutMemo.Lines.Add(ph);<br><br>&nbsp; CloseHandle(hOutPutWritePipe);<br>&nbsp; CloseHandle(hInPutReadPipe);<br>&nbsp; CloseHandle(hOutPutReadPipe);<br>&nbsp; CloseHandle(hInPutWritePipe);<br>&nbsp; CloseHandle(pi.hThread);<br>&nbsp; CloseHandle(pi.hProcess);<br>&nbsp; FreeMem(ph);<br>&nbsp; FreeMem(fname);<br>end;<br><br><br>procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;<br>&nbsp; Shift: TShiftState);<br>begin<br>&nbsp; if key=vk_return then<br>&nbsp; begin<br>&nbsp; &nbsp; inputCMD:=edit1.Text+#13#10;<br>&nbsp; &nbsp; edit1.Text:='';<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; OutPutCmdProText('cmd.exe',memo1);<br>end;<br><br>end.
 
对了 补充下,这个例子我只检测了命令行自己关闭,没有判断从外部关闭,你直接运行可能造成程序无法关闭,建议你把那个OutPutCmdProText放到一个线程里去运行
 
这样好像有点麻烦哈。我只要让我DOS下的应用程序(exe)放到我的Panel上运行就可以了<br>各位还有没有好点的建议啊。 谢谢了!
 
哎!<br>_hwnd:=findwindow('ConsoleWindowClass',nil);<br>seltwindowparent(_hwnd,form1.panel1.handle);
 
后退
顶部