从VCL可以看到, 方法1:DestroyHandle之后Create了新的,2:没有.所以第一种方式会出现闪烁
procedure TCustomForm.SetFormStyle(Value: TFormStyle);
var
OldStyle: TFormStyle;
begin
if FFormStyle <> Value then
begin
if (Value = fsMDIChild) and (Position = poDesigned) then
Position := poDefault;
if not (csDesigning in ComponentState) then DestroyHandle;
OldStyle := FFormStyle;
FFormStyle := Value;
if ((Value = fsMDIForm) or (OldStyle = fsMDIForm)) and not Ctl3d then
Color := NormalColor;
if not (csDesigning in ComponentState) then UpdateControlState;
if Value = fsMDIChild then Visible := True;
end;
end;
....
procedure TCustomForm.CreateWnd;
var
ClientCreateStruct: TClientCreateStruct;
begin
inherited CreateWnd;
if NewStyleControls then
if BorderStyle <> bsDialog then
SendMessage(Handle, WM_SETICON, 1, GetIconHandle) else
SendMessage(Handle, WM_SETICON, 1, 0);
if not (csDesigning in ComponentState) then
case FormStyle of
fsMDIForm:
begin
with ClientCreateStruct do
begin
idFirstChild := $FF00;
hWindowMenu := 0;
if FWindowMenu <> nil then hWindowMenu := FWindowMenu.Handle;
end;
FClientHandle := Windows.CreateWindowEx(WS_EX_CLIENTEDGE, 'MDICLIENT',
nil, WS_CHILD or WS_VISIBLE or WS_GROUP or WS_TABSTOP or
WS_CLIPCHILDREN or WS_HSCROLL or WS_VSCROLL or WS_CLIPSIBLINGS or
MDIS_ALLCHILDSTYLES, 0, 0, ClientWidth, ClientHeight, Handle, 0,
HInstance, @ClientCreateStruct);
FClientInstance := Classes.MakeObjectInstance(ClientWndProc);
FDefClientProc := Pointer(GetWindowLong(FClientHandle, GWL_WNDPROC));
SetWindowLong(FClientHandle, GWL_WNDPROC, Longint(FClientInstance));
end;
fsStayOnTop:
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or
SWP_NOSIZE or SWP_NOACTIVATE);
end;
end;
procedure TCustomForm.SetFormStyle(Value: TFormStyle);
var
OldStyle: TFormStyle;
begin
if FFormStyle <> Value then
begin
if (Value = fsMDIChild) and (Position = poDesigned) then
Position := poDefault;
if not (csDesigning in ComponentState) then DestroyHandle;
OldStyle := FFormStyle;
FFormStyle := Value;
if ((Value = fsMDIForm) or (OldStyle = fsMDIForm)) and not Ctl3d then
Color := NormalColor;
if not (csDesigning in ComponentState) then UpdateControlState;
if Value = fsMDIChild then Visible := True;
end;
end;
....
procedure TCustomForm.CreateWnd;
var
ClientCreateStruct: TClientCreateStruct;
begin
inherited CreateWnd;
if NewStyleControls then
if BorderStyle <> bsDialog then
SendMessage(Handle, WM_SETICON, 1, GetIconHandle) else
SendMessage(Handle, WM_SETICON, 1, 0);
if not (csDesigning in ComponentState) then
case FormStyle of
fsMDIForm:
begin
with ClientCreateStruct do
begin
idFirstChild := $FF00;
hWindowMenu := 0;
if FWindowMenu <> nil then hWindowMenu := FWindowMenu.Handle;
end;
FClientHandle := Windows.CreateWindowEx(WS_EX_CLIENTEDGE, 'MDICLIENT',
nil, WS_CHILD or WS_VISIBLE or WS_GROUP or WS_TABSTOP or
WS_CLIPCHILDREN or WS_HSCROLL or WS_VSCROLL or WS_CLIPSIBLINGS or
MDIS_ALLCHILDSTYLES, 0, 0, ClientWidth, ClientHeight, Handle, 0,
HInstance, @ClientCreateStruct);
FClientInstance := Classes.MakeObjectInstance(ClientWndProc);
FDefClientProc := Pointer(GetWindowLong(FClientHandle, GWL_WNDPROC));
SetWindowLong(FClientHandle, GWL_WNDPROC, Longint(FClientInstance));
end;
fsStayOnTop:
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or
SWP_NOSIZE or SWP_NOACTIVATE);
end;
end;
Delphi\Source\里什么都有,VCL是Open source的,你可以自己改的,不过最好别改VCL
非常感谢! [email protected]
非常感谢! [email protected]