跪求!~请问如何将其它程序嵌入自己程序的窗体中~如能实现最加500!例如程序启动后,在个GroupBox控件中显示一个外部程序,最好能改变外部程序的尺寸(如去掉标题栏),当移动自己程序的窗体时,外部程序跟着移动好像听说可以用findwindow找到窗口handle后,windows.setparent为自己的窗口,movewindows到自己的窗口不懂!!!!!跪求大家赐教啊,也可把简单实例源码发给我: [email protected] 或 [email protected]~如能实现追加500!
~如能实现追加500!

解决方案 »

  1.   

    等于把别人程序给"包装"一下是吧.好像该程序必须支持OLE才可以.
      

  2.   

    对方不支持OLE的根本就没可能做到http://lysoft.7u7.net
      

  3.   

    to : longtusoft(神灯之主)/ly_liuyang(Liu Yang) 谢谢!对方不支持OLE的不能实现嵌入,那能否只改变外部程序的显示位置、尺寸呢
    (外部程序不必加入资源文件)跪求大家赐教啊,也可把简单实例源码发给我: [email protected] 或 [email protected]~如能实现追加500!
    ~如能实现追加500!
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      h: HWND;
    begin
      h := WIndows.FindWindow(nil, '计算器');
      Windows.SetParent(h, Self.Panel1.Handle);
      Windows.MoveWindow(h, 0, 0, 200, 200, true);
    end;这样即可,你开个计算器,再执行~~~
      

  5.   

    我给你一个,你看有没有用,我试过,基本和你的要求一个样
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      PProcessWindow = ^TProcessWindow;
      TProcessWindow = record
        TargetProcessID: Cardinal;
        FoundWindow: hWnd;
      end;
      TForm1 = class(TForm)
        Button1: TButton;
        OpenD: TOpenDialog;
        Panel1: TPanel;
        procedure Button1Click(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      hWin: HWND = 0;
    implementation{$R *.dfm}function EnumWindowsProc(Wnd: hWnd; ProcWndInfo: PProcessWindow): BOOL; stdcall;
    var
      WndProcessID: Cardinal;
    begin
      GetWindowThreadProcessId(Wnd, @WndProcessID);
      if WndProcessID = ProcWndInfo^.TargetProcessID then begin
        ProcWndInfo^.FoundWindow := Wnd;
        Result := False; // This tells EnumWindows to stop enumerating since we've already found a window.
      end else Result := True; // Keep searching
    end;function GetProcessWindow(TargetProcessID: Cardinal): hWnd;
    var
      ProcWndInfo: TProcessWindow;
    begin
      ProcWndInfo.TargetProcessID := TargetProcessID;
      ProcWndInfo.FoundWindow := 0;
      EnumWindows(@EnumWindowsProc, Integer(@ProcWndInfo));
      Result := ProcWndInfo.FoundWindow;
    end;function RunAppInPanel(const AppName: string; PanelHandle: HWND): boolean;
    var
      si: STARTUPINFO;
      pi: TProcessInformation;
    begin
      FillChar(si, SizeOf(si), 0);
      si.cb := SizeOf(si);
      si.wShowWindow := SW_SHOW;
      result := CreateProcess(nil, PChar(AppName), nil,
        nil, true, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, si, pi);  if not result then exit;  WaitForInputIdle(pi.hProcess, 10000); // let process start!  hWin := GetProcessWindow(pi.dwProcessID);
      if hWin > 0 then begin
        Windows.SetParent(hWin, PanelHandle);
        SetWindowPos(hWin, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOZORDER);
        result := true;
      end;  // we don't need the handles so we close them
      CloseHandle(pi.hProcess);
      CloseHandle(pi.hThread);
    end;
    procedure Delay(msecs:integer);var
    FirstTickCount:longint;beginFirstTickCount:=GetTickCount;
    repeat
    Application.ProcessMessages;
    until ((GetTickCount-FirstTickCount) >= Longint(msecs));end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      delay(4000);
      if OpenD.Execute then begin
        if hWin > 0 then PostMessage(hWin, WM_CLOSE, 0, 0); // close any app currently opened
        if not RunAppInPanel(OpenD.FileName, Panel1.Handle) then ShowMessage('App not found');
      end;
    end;
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      if hWin > 0 then
        PostMessage(hWin, WM_CLOSE, 0, 0);
    end;end.
      

  6.   

    guolvguolv(guolvguolv) :你写的程序是干什么用的呀,一点反应都没有呀!
      

  7.   

    有呀,我给你的邮箱发一个完整的例子吧,我到别的地方down的
      

  8.   

    guolvguolv(guolvguolv) 不要乱贴程序好不好?我用三行完成的功能,你贴了那么一大堆,还一点用都没有。
      

  9.   

    很好很好,!严重!感谢大家,特别感谢 mikespook(懒猫开始新生活)/guolvguolv(guolvguolv)
    两位的代码都能实现!初步满足我的想法!to : mikespook(懒猫开始新生活) 
         简洁的三行便实现了外部程序的嵌入,强(我菜:-))!
         有点不足就是不能动态获取外部程序的类名:
         即WIndows.FindWindow(nil, '计算器')中的'nil'.
         最加得分~200to : guolvguolv(guolvguolv)
         感谢你发来的代码包!
         由于程序能在运行后,嵌入随便选择的外部程序,证明实现了以上说所的功能.
         最加得分~300我重新发贴,请两位尽快来拿分,以免被删!(刷新一下或查找我的贴)拿分处:
    mikespook(懒猫开始新生活): 
      http://community.csdn.net/Expert/TopicView.asp?id=3469964
      http://community.csdn.net/Expert/TopicView.asp?id=3469969
    guolvguolv(guolvguolv):
      http://community.csdn.net/Expert/TopicView.asp?id=3469974
      http://community.csdn.net/Expert/TopicView.asp?id=3469978
      http://community.csdn.net/Expert/TopicView.asp?id=3469982不好意思,本来想每人加500的,100一个贴的话我绝对被封IP了.以后再提问的时候请两位再来捧个场,绝对高分奉上!