線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1785
推到 Plurk!
推到 Facebook!

ShellExecute函式調用

尚未結案
lovearies
一般會員


發表:1
回覆:0
積分:0
註冊:2013-07-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2013-07-26 12:01:32 IP:111.235.xxx.xxx 訂閱
 各位好,小弟才疏學淺在Panel中調用TELNET.EXE時遇到了一些問題,想像各位請益.
小弟是用ShellExecute來呼叫telnet.exe 想要把呼叫出來的程序崁在panel中執行,
結果是可以的~但總是會多呼叫一個telnet視窗出來,造成主程式的panel內有一個telnet程序,
另外桌面又多跑出了一個telnet程序
是不是小弟哪邊搞錯了?

[code delphi]
procedure TNEW_COB.CallTelnet(PanelEX:TPanel);
var
SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
EnumData: TEnumData;

procedure ReSizePage(page: TPanel);
var
hwnd: Windows.HWND;
Rect: TRect;
begin
hwnd := Page.Tag;
Rect := Page.ClientRect;
Windows.MoveWindow(hwnd, Rect.Left, Rect.Top, Rect.Right-Rect.Left, Rect.Bottom-Rect.Top, True);
Windows.ShowWindow(hwnd,SW_SHOWNORMAL);
end;

function EnumWindowsProc(hwnd: HWND; var data: TEnumData ): BOOL; stdcall;
var
ProcessId: DWORD;
begin
GetWindowThreadProcessId(hwnd, ProcessId);
if data.ProcessID = ProcessID then
begin
data.hwnd := hwnd;
Result := False;
exit;
end;
Result := True;
end;
begin
try
PanelEX.SetFocus;
FillChar(SEInfo, SizeOf(SEInfo), 0) ;
SEInfo.cbSize := SizeOf(TShellExecuteInfo);
with SEInfo do
begin
lpVerb := 'open';
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := self.Handle;

lpFile := PwideChar('telnet.exe');
nShow := SW_SHOWNORMAL;
lpParameters := PChar(TelnetPath);
end;
if ShellExecuteEx(@SEInfo) then
begin
EnumData.hwnd := 0;
repeat
Application.ProcessMessages;
if EnumData.hwnd = 0 then
begin
EnumData.ProcessID := GetProcessId(SEInfo.hProcess);
EnumWindows(@EnumWindowsProc, LPARAM(@EnumData));
Panel1.Tag := EnumData.hwnd;
Windows.SetParent(EnumData.hwnd, PanelEX.Handle);
ReSizePage(PanelEX);
ProcessHandleID := EnumData.hwnd;
end;
GetExitCodeProcess(SEInfo.hProcess, ExitCode);
ShowWindow(ProcessHandleID, SW_MAXIMIZE);
until (ExitCode <> STILL_ACTIVE) or Application.Terminated;

end
else
begin
;
end;
except
on E : Exception do
begin

end;
end;
end;
[/code]

附加檔案:51f1f49c16c26_1名.png
系統時間:2024-04-26 5:24:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!