J
jiang5460
Unregistered / Unconfirmed
GUEST, unregistred user!
功能说明如下:
将要用的窗体封装到一个工程的DLL里,另一个工程窗体上的控件比如:Panel,通过调用DLL的窗体锁定到这个控件上。并显示。
我是可以显示,但存在问题:
如下:
1、从DLL调用到的窗体不能马上显示在Panel上,
2、出现错误:Control 'Edit2' has no parent window.,其中Edit2是只鼠标在Edit2上右击或双击出错。其他控件类似。
搞这个已经搞一天了,还是没有结果;
以下是我的具体代码:
DLL工程方面:
library DllDesk;
uses
Windows,
SysUtils,
Classes,
Controls,
Forms,
UDllDesk in 'UDllDesk.pas' {Frm_DllDesk},
UFranDesk in 'UFranDesk.pas' {Frm_Framdesk: TFrame};
{$R *.res}
var
DllDeskApp: TApplication;
procedure DLLDeskUnloadProc(Reason: Integer); register;
begin
// DLL_PROCESS_DETACH dll在进程中被卸载
if Reason = DLL_PROCESS_DETACH then Application := DllDeskApp;
end;
procedure ShowDesk(DeskApp: TApplication; FCarrier: TWincontrol; ParentForm: TForm); export; stdcall;
begin
if not Assigned(Frm_DllDesk) then
begin
Application := DeskApp;
Frm_DllDesk := TFrm_DllDesk.Create(nil);
Frm_DllDesk.ManualDock(FCarrier, nil, alClient);
Frm_DllDesk.Show();
end;
end;
exports
ShowDesk;
begin
DllDeskApp := Application;
DLLProc := @DLLDeskUnloadProc; //设置dll的事件处理函数过程为DLLDeskUnloadProc
end.
DLL里的窗体如下:
unit UDllDesk;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TFrm_DllDesk = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Memo1: TMemo;
TabSheet3: TTabSheet;
Edit3: TEdit;
Button3: TButton;
Button2: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Frm_DllDesk: TFrm_DllDesk;
implementation
{$R *.dfm}
procedure TFrm_DllDesk.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
Frm_DllDesk := nil;
end;
procedure TFrm_DllDesk.FormDestroy(Sender: TObject);
begin
self.Release;
end;
procedure TFrm_DllDesk.Button1Click(Sender: TObject);
begin
close;
end;
end.
调用主窗体代码如下:
unit UMaindesk;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls;
type
T_ShowDeskFM = procedure(DeskApp: TApplication; FCarrier: TWincontrol; ParentForm: TForm); stdcall;
TFrm_Desk = class(TForm)
Panel1: TPanel;
Button1: TButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
pnlMain: TPanel;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
function LoadDll(DllName, FuncName: string): FarProc;
{ Public declarations }
end;
var
DllDeskHandle: HMODULE; //dll桌面句柄
ShowDesk: T_ShowDeskFM;
Frm_Desk: TFrm_Desk;
implementation
{$R *.dfm}
{ TFrm_Desk }
function TFrm_Desk.LoadDll(DllName, FuncName: string): FarProc;
begin
try
DllDeskHandle := 0;
DllDeskHandle := LoadLibrary(PChar(DllName));
if DllDeskHandle <> 0 then
begin
Result := GetProcAddress(DllDeskHandle, PChar(FuncName)); //初始化过程变量
end;
except
Result:=nil;
FreeLibrary(DllDeskHandle);
end;
end;
procedure TFrm_Desk.Button1Click(Sender: TObject);
begin
@ShowDesk := LoadDll('DllDesk.dll', 'ShowDesk');
ShowDesk(Application, pnlMain, Frm_Desk);
end;
procedure TFrm_Desk.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FreeLibrary(DllDeskHandle);
Action:=caFree;
Frm_Desk:=nil;
end;
end.
将要用的窗体封装到一个工程的DLL里,另一个工程窗体上的控件比如:Panel,通过调用DLL的窗体锁定到这个控件上。并显示。
我是可以显示,但存在问题:
如下:
1、从DLL调用到的窗体不能马上显示在Panel上,
2、出现错误:Control 'Edit2' has no parent window.,其中Edit2是只鼠标在Edit2上右击或双击出错。其他控件类似。
搞这个已经搞一天了,还是没有结果;
以下是我的具体代码:
DLL工程方面:
library DllDesk;
uses
Windows,
SysUtils,
Classes,
Controls,
Forms,
UDllDesk in 'UDllDesk.pas' {Frm_DllDesk},
UFranDesk in 'UFranDesk.pas' {Frm_Framdesk: TFrame};
{$R *.res}
var
DllDeskApp: TApplication;
procedure DLLDeskUnloadProc(Reason: Integer); register;
begin
// DLL_PROCESS_DETACH dll在进程中被卸载
if Reason = DLL_PROCESS_DETACH then Application := DllDeskApp;
end;
procedure ShowDesk(DeskApp: TApplication; FCarrier: TWincontrol; ParentForm: TForm); export; stdcall;
begin
if not Assigned(Frm_DllDesk) then
begin
Application := DeskApp;
Frm_DllDesk := TFrm_DllDesk.Create(nil);
Frm_DllDesk.ManualDock(FCarrier, nil, alClient);
Frm_DllDesk.Show();
end;
end;
exports
ShowDesk;
begin
DllDeskApp := Application;
DLLProc := @DLLDeskUnloadProc; //设置dll的事件处理函数过程为DLLDeskUnloadProc
end.
DLL里的窗体如下:
unit UDllDesk;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TFrm_DllDesk = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Memo1: TMemo;
TabSheet3: TTabSheet;
Edit3: TEdit;
Button3: TButton;
Button2: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Frm_DllDesk: TFrm_DllDesk;
implementation
{$R *.dfm}
procedure TFrm_DllDesk.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
Frm_DllDesk := nil;
end;
procedure TFrm_DllDesk.FormDestroy(Sender: TObject);
begin
self.Release;
end;
procedure TFrm_DllDesk.Button1Click(Sender: TObject);
begin
close;
end;
end.
调用主窗体代码如下:
unit UMaindesk;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls;
type
T_ShowDeskFM = procedure(DeskApp: TApplication; FCarrier: TWincontrol; ParentForm: TForm); stdcall;
TFrm_Desk = class(TForm)
Panel1: TPanel;
Button1: TButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
pnlMain: TPanel;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
function LoadDll(DllName, FuncName: string): FarProc;
{ Public declarations }
end;
var
DllDeskHandle: HMODULE; //dll桌面句柄
ShowDesk: T_ShowDeskFM;
Frm_Desk: TFrm_Desk;
implementation
{$R *.dfm}
{ TFrm_Desk }
function TFrm_Desk.LoadDll(DllName, FuncName: string): FarProc;
begin
try
DllDeskHandle := 0;
DllDeskHandle := LoadLibrary(PChar(DllName));
if DllDeskHandle <> 0 then
begin
Result := GetProcAddress(DllDeskHandle, PChar(FuncName)); //初始化过程变量
end;
except
Result:=nil;
FreeLibrary(DllDeskHandle);
end;
end;
procedure TFrm_Desk.Button1Click(Sender: TObject);
begin
@ShowDesk := LoadDll('DllDesk.dll', 'ShowDesk');
ShowDesk(Application, pnlMain, Frm_Desk);
end;
procedure TFrm_Desk.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FreeLibrary(DllDeskHandle);
Action:=caFree;
Frm_Desk:=nil;
end;
end.