T
Tintin
Unregistered / Unconfirmed
GUEST, unregistred user!
我将一个Child Form 放在Dll中调用,可是调出后其菜单项不能够与MDI主
Form的菜单融合,我使用Api函数SETPARENT指定ParentForm也不行,不知
错误在那里。请列位大虾帮帮忙,谢了先。源码贴在下面
//---------------------------------------------------------
dll 的项目文件
------
library Dll;
uses
SysUtils,
Classes,
windows,
forms,
ChildForm in 'ChildForm.pas' {Form2};
{$R *.RES}
var
OldApplication: TApplication;
procedure DllExit;
begin
Application:=OldApplication;
end;
procedure DLLEntryPoint(dwReason : DWord);
begin
Case dwReason of //此处还可以加入线程入口
DLL_PROCESS_ATTACH : //载入DLL
begin
OldApplication:=Application;
end;
DLL_PROCESS_DETACH : //卸载DLL
begin
DllExit;
end;
end;
end;
Procedure InitDll(AppHandle: TApplication;
Parient : TForm);stdcall;
begin
Application := AppHandle;
Form2 := TForm2.Create(nil);
// SetParent(Form2.Handle, Parient.Handle);
Form2.Show;
end;
exports
InitDll;
begin
DLLProc := @DLLEntryPoint;
{初始时调用此过程}
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.
//------------------------------------------------------------
dll的中的Form文件 Pas
--------
unit ChildForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus;
type
TForm2 = class(TForm)
MainMenu1: TMainMenu;
Test1: TMenuItem;
aaa1: TMenuItem;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
end;
end.
//----Form 文本
object Form2: TForm2
Left = 165
Top = 162
Width = 544
Height = 375
Caption = 'Form2'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsMDIChild
Menu = MainMenu1
OldCreateOrder = False
Position = poDefault
Visible = True
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object MainMenu1: TMainMenu
Left = 168
Top = 60
object Test1: TMenuItem
Caption = 'Test'
object aaa1: TMenuItem
Caption = 'aaa'
end
end
end
end
//——---------————————————————————————
调用端的主窗体
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
CreateMDIForm1: TMenuItem;
bbbb1: TMenuItem;
procedure CreateMDIForm1Click(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
InitDll = Procedure(AppHandle:TApplication;
Parent :TForm);stdcall;
var
Form1: TForm1;
Dlladdress : Integer;
implementation
{$R *.DFM}
procedure TForm1.CreateMDIForm1Click(Sender: TObject);
begin
Dlladdress := LoadLibrary('Dll.dll');
InitDll(GetProcAddress(Dlladdress,'InitDll'))(Application, Self);
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
FreeLibrary(Dlladdress);
end;
end.
窗体文件
object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsMDIForm
Menu = MainMenu1
OldCreateOrder = False
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object MainMenu1: TMainMenu
Left = 220
Top = 12
object CreateMDIForm1: TMenuItem
Caption = 'CreateMDIForm'
OnClick = CreateMDIForm1Click
end
object bbbb1: TMenuItem
Caption = 'bbbb'
end
end
end
//—————————————————————————————————
就这样了,帮我分析分析吧,我是不得其解
Form的菜单融合,我使用Api函数SETPARENT指定ParentForm也不行,不知
错误在那里。请列位大虾帮帮忙,谢了先。源码贴在下面
//---------------------------------------------------------
dll 的项目文件
------
library Dll;
uses
SysUtils,
Classes,
windows,
forms,
ChildForm in 'ChildForm.pas' {Form2};
{$R *.RES}
var
OldApplication: TApplication;
procedure DllExit;
begin
Application:=OldApplication;
end;
procedure DLLEntryPoint(dwReason : DWord);
begin
Case dwReason of //此处还可以加入线程入口
DLL_PROCESS_ATTACH : //载入DLL
begin
OldApplication:=Application;
end;
DLL_PROCESS_DETACH : //卸载DLL
begin
DllExit;
end;
end;
end;
Procedure InitDll(AppHandle: TApplication;
Parient : TForm);stdcall;
begin
Application := AppHandle;
Form2 := TForm2.Create(nil);
// SetParent(Form2.Handle, Parient.Handle);
Form2.Show;
end;
exports
InitDll;
begin
DLLProc := @DLLEntryPoint;
{初始时调用此过程}
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.
//------------------------------------------------------------
dll的中的Form文件 Pas
--------
unit ChildForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus;
type
TForm2 = class(TForm)
MainMenu1: TMainMenu;
Test1: TMenuItem;
aaa1: TMenuItem;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
end;
end.
//----Form 文本
object Form2: TForm2
Left = 165
Top = 162
Width = 544
Height = 375
Caption = 'Form2'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsMDIChild
Menu = MainMenu1
OldCreateOrder = False
Position = poDefault
Visible = True
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object MainMenu1: TMainMenu
Left = 168
Top = 60
object Test1: TMenuItem
Caption = 'Test'
object aaa1: TMenuItem
Caption = 'aaa'
end
end
end
end
//——---------————————————————————————
调用端的主窗体
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
CreateMDIForm1: TMenuItem;
bbbb1: TMenuItem;
procedure CreateMDIForm1Click(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
InitDll = Procedure(AppHandle:TApplication;
Parent :TForm);stdcall;
var
Form1: TForm1;
Dlladdress : Integer;
implementation
{$R *.DFM}
procedure TForm1.CreateMDIForm1Click(Sender: TObject);
begin
Dlladdress := LoadLibrary('Dll.dll');
InitDll(GetProcAddress(Dlladdress,'InitDll'))(Application, Self);
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
FreeLibrary(Dlladdress);
end;
end.
窗体文件
object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsMDIForm
Menu = MainMenu1
OldCreateOrder = False
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object MainMenu1: TMainMenu
Left = 220
Top = 12
object CreateMDIForm1: TMenuItem
Caption = 'CreateMDIForm'
OnClick = CreateMDIForm1Click
end
object bbbb1: TMenuItem
Caption = 'bbbb'
end
end
end
//—————————————————————————————————
就这样了,帮我分析分析吧,我是不得其解