最近在弄个DLL嵌入主窗体Panel碰到EXE主窗体改变尺寸时,窗体中的Panel也会跟着变(Panel.Align设为了alClient),但其中嵌入的DLL窗体不会跟着变,
网上解决方法(我不知道FChildWindowList怎么来。看不懂。谁能帮我解释下。或者提供其他方法):
http://www.cnblogs.com/bridge/archive/2009/06/05/1497142.html
//exe窗口接收消息并改变子窗体大小
//FChildWindowList为TList,子窗体的结构信息列表
Type
//子窗体一些信息的结构体
PFormInfo = ^TFormInfo;
TFormInfo = record
Handle : HWND;
Parent : HWND;
Style : HWND;
end; TfrmExe = class(TForm)
private
procedure WMSize(var Message:TWMSize);message WM_Size;
end;procedure TfrmExe.WMSize(var Message: TWMSize);
//ReSize消息
var
i : Integer;
rc : TRect;
begin
inherited;
if GetWindowRect(panWorkSpace.Handle,rc) then
if Assigned(FChildWindowList) then
for i := 0 to FChildWindowList.Count - 1 do
SetWindowPos(PFormInfo(FChildWindowList[i]).Handle, 0,
0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top,
SWP_NOACTIVATE);
end;
网上解决方法(我不知道FChildWindowList怎么来。看不懂。谁能帮我解释下。或者提供其他方法):
http://www.cnblogs.com/bridge/archive/2009/06/05/1497142.html
//exe窗口接收消息并改变子窗体大小
//FChildWindowList为TList,子窗体的结构信息列表
Type
//子窗体一些信息的结构体
PFormInfo = ^TFormInfo;
TFormInfo = record
Handle : HWND;
Parent : HWND;
Style : HWND;
end; TfrmExe = class(TForm)
private
procedure WMSize(var Message:TWMSize);message WM_Size;
end;procedure TfrmExe.WMSize(var Message: TWMSize);
//ReSize消息
var
i : Integer;
rc : TRect;
begin
inherited;
if GetWindowRect(panWorkSpace.Handle,rc) then
if Assigned(FChildWindowList) then
for i := 0 to FChildWindowList.Count - 1 do
SetWindowPos(PFormInfo(FChildWindowList[i]).Handle, 0,
0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top,
SWP_NOACTIVATE);
end;
用这个方法是可以的,只要按照你窗口的Z序,找到dll窗口的Handle,然后再用SetWindowPos函数就可以:procedure TformMain.WMSize(var Message: TWMSize);
var
h, h2: THandle;
rc: TRect;
begin
inherited;
h := FindWindowEx(Handle, 0, 'TPanel', nil);
if h = 0 then
exit; h := FindWindowEx(h, 0, 'TPanel', nil);
if h = 0 then
exit; h := FindWindowEx(h, 0, 'TfDllform', 'fDllform');
if h = 0 then
exit; h2 := FindWindowEx(h, 0, 'TfmMain', nil);
if h2 = 0 then
exit; GetWindowRect(PanelParent.Handle, rc);
SetWindowPos(h, HWND_TOP, 0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top, SWP_NOACTIVATE);
SetWindowPos(h2, HWND_TOP, 0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top, SWP_NOACTIVATE);
end;
主窗体融合dll窗体, 大小随父控件变化, 只需修改Dll窗体的Align := alClient;
这样不行的啊,改变主窗口的大小,dll窗口的大小不会变化。
Delphi XE下测试通过///////////////////////////DLL项目
library FormInDll;uses
forms,
Windows,
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}function GetDLLForm(AParent:HWND) : Integer;
begin
Result := -1;
try
with TForm1.Create(Application) do
begin
ParentWindow := AParent;
Show;
end;
except on E: Exception do
Result := 0;
end;
end;exports
GetDLLForm;
begin
end.
///////////////////////////Dll窗体, Create事件
procedure TForm1.FormCreate(Sender: TObject);
begin
BorderStyle := bsNone;
Align := alClient;
end;
///////////////////////////静态调用Dll窗体
//静态调用 Begin
function GetDLLForm(AParent:HWND) : Integer; external 'FormInDll.dll';
procedure TForm14.btn3Click(Sender: TObject);
var
n : integer;
begin
n := GetDLLForm(pnl2.Handle); n := GetDLLForm(pnl3.Handle);end;
//静态调用 End