• 插入窗体到别的程序里


    Form1代码

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses Unit2;
    
    procedure TForm1.FormCreate(Sender: TObject);
    var
      h: HWND;
      s : string;
    begin
      h := 0;
    //  s := 'USB cable serial number manager 1.00';
    //  s := 'ir-750 Interface Program Ver1.02';
      s := 'PDF-XChange viewer';
      h := FindWindow(nil,PChar(s));
      if h <> 0 then
      begin
        Form2 := TForm2.CreateParented(h);//关键
        Form2.Show;
      end
      else
      begin
        ShowMessage('未找到宿主程序,程序无法继续进行。');
        Application.Terminate;
      end;
    end;
    
    end.
    

    Form2代码

    unit Unit2;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
    
    type
      TForm2 = class(TForm)
        Label1: TLabel;
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form2: TForm2;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Application.Terminate;
    end;
    
    procedure TForm2.FormCreate(Sender: TObject);
    begin
    
    end;
    
    end.
    
  • 相关阅读:
    4K
    4J
    4C
    I2C总线的仲裁机制
    Linux C中strcpy , strncpy , strlcpy 的区别
    Linux下的USB总线驱动(一)
    C/C++ 语言中的表达式求值
    const变量通过指针修改问题
    关于协议栈XDATA,内存溢出的小结
    Ubuntu安装ssh,及失败解决方案
  • 原文地址:https://www.cnblogs.com/cxp2009/p/2249528.html
Copyright © 2020-2023  润新知