一些背景( 继续) TLabel和Tome Box Captions Flicker on Resize:
- So, I have an application that loads different plugins and creates a new tab on a TPageControl for each one.
- Each DLL has a TForm associated with it.
- The forms are created with their parent hWnd as the new TTabSheet. Since the TTabSheets aren t a parent of the form as far as VCL is concerned (didn t want to use dynamic RTL, and plugins made in other languages) I have to handle resizes manually.
我似乎正在讨论许多新问题(,但伟大的学习经验),涉及这种“插图”的应用类型。
因此,我目前的斗争正试图把 does带入关塔布特,但将直接改写。
Since this would be easier to explain with a picture: Now I could manually do the alignment and the resize, but I d much rather have the VCL alignment procedures (alClient, alTop, etc) do it for me. That way I would just have to set the plugins alignment on its form without thinking.
在研究了《维也纳条约法公约》的渊源之后,我开始通过《统一守则》和《守则》的呼声。 基本上,TControl获得WM_ RESIZE:
- Call Realign() which calls AlignControl()
- AlignControl() will get the client rect and call AlignControls()
- AlignControls() will call DoAlign() for each TAlignment type in this order: alTop, alBottom, alLeft, alRight, alClient, alCustom, alNone
- DoAlign() will loop through FControls and FWinControls (which are TLists) and will align them appropriately
因此,我的想法是,如果我建立一个新的TWinControl,使其处理原始产品表格(window),并将它列入FControls清单,使之与我的工作适当一致。
Of course I m here, so it failed miserably. I even get an AV when exiting the application about an invalid window handle. My guess is that the TWinControl I created is trying to free the handle of the plugins form (window) which doesn t exist any more.
我尝试的是:
procedure AddHandleToControlList(AHandle: DWORD; Align: TAlign);
var
NewWinControl : TWinControl;
begin
NewWinControl := TWinControl.Create(frmMain);
NewWinControl.WindowHandle := AHandle;
NewWinControl.Align := Align;
NewWinControl.Width := frmMain.ClientWidth;
NewWinControl.Height := 30;
NewWinControl.Parent := frmMain;
end;
procedure AddHandleToControlList(AHandle: DWORD; Align: TAlign);
var
NewWinControl : TWinControl;
begin
NewWinControl := TWinControl.Create(frmMain);
NewWinControl.WindowHandle := AHandle;
NewWinControl.Align := Align;
NewWinControl.Width := frmMain.ClientWidth;
NewWinControl.Height := 30;
TWinControl(frmMain).Insert(NewWinControl);
end;
Soooo, thoughts?
EDIT 1:
Ok, so this correctly adds the control to the list and conforms the the TAlign set (why is it that I spend 8 hours trying to figure something out, I post here, and then the answer just appears...oh well someone might find this question and my ramblings useful):
procedure AddHandleToControlList(AHandle: DWORD; AName: PChar; ATop, ALeft, AWidth, AHeight: Integer; AAlign: TAlign);
var
NewWinControl : TWinControl;
begin
NewWinControl := TWinControl.Create(frmMain);
With NewWinControl Do
begin
Name := AName;
Top := ATop;
Left := ALeft;
Width := AWidth;
Height := AHeight;
Align := AAlign;
WindowHandle := AHandle;
Visible := True;
end;
TWinControl(frmMain).InsertControl(NewWinControl);
end;
现在的问题是,在申请结束时,我就错了AV......。 我将继续!
EDIT 2: Ok, so it is TWinControl.DestroyWindowHandle that raises the AV because the window handle doesn t exist any more. I m trying to think of a clean solution.