用LockWindowUpdate锁定屏幕后创建MDI子窗体时,子窗体依然闪烁(刷新),奇怪!?
鐵蛋 2007-11-19 08:05:59 我做的一个MDI程序,一主窗体加上很多MDI子窗体,但是在子窗体的创建过程中会出现:创建(空白窗体)--->组件创建并显示--->窗体最大化这一过程,即所谓的窗体闪烁现象,在创建的过程中我已经锁定了屏幕,但还是没效果,创建子窗体的代码如下:
这是一个通用函数,我们公司的代码就是这样写的,它就不闪烁,而我做的这个例子就会出现这种情况,很疑惑!有没有遇到这个问题并解决的高人
procedure RunMDIChild( MDIChildFormClass: TFormClass ;var Reference);
var
MDIChildForm: TForm;
i:Integer;
begin
with Application.MainForm do
begin
for i:=0 to MDIChildCount-1 do
begin
//如果所调用的窗体存在,显示该窗体
if MDIChildren[i].ClassType = MDIChildFormClass then
begin
RestoreWindow(MDIChildren[i].Handle);//API
Exit;
end;
end;
try
LockWindowUpdate(GetDeskTopWindow);//锁定屏幕,API
Application.CreateForm(MDIChildFormClass,Reference);//创建子窗体
finally
Screen.Cursor:=crDefault;
end;
try
LockWindowUpdate(GetDeskTopWindow);//锁定屏幕
MDIChildForm:=TForm(Reference);
MainForm.AddToWindowList(MDIChildForm);//不用管这行代码
MDIChildForm.WindowState:= wsMaximized;
finally
LockWindowUpdate(0);//解除锁定API
end;
end;
end;