子窗体的创建方法如下:
procedure TFrm.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.WndParent := GetDesktopWindow;
  Params.ExStyle := Params.ExStyle or WS_EX_TOOLWINDOW;
end;子窗体的显示方法如下:
procedure TFrm.ShowWindow(Rect: TRect);
begin
  Location(Rect);
  Self.Visible := True;
  SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE);
end;子窗体根据某一条件显示和隐蔽,但是当调用showwindow方法时,有的时候不显示出来,要点击主窗体(主窗体就是创建子窗体的窗体)时子窗体才显示出来,这是为什么?要怎么解决?

解决方案 »

  1.   

    GetDesktopWindow; 
    用 ActiveForm  吧,不然如果主窗體不是激活窗體,就不對了。
      

  2.   

    楼主的Params.WndParent := GetDesktopWindow; 有问题,你设置了父窗体关系,简单办法改为Params.WndParent := Application.MainForm.Handle就可以了。
      

  3.   

    Params.WndParent := GetDesktopWindow 是把窗体的父窗体设置为桌面,不是程序主窗体,因为我主窗体要一直缩小到托盘区运行
      

  4.   

    ShowWindow把SetForegroundWindow(Handle)设置焦点试一下
      

  5.   

    回复6楼,我就是这样弄的,但有时还是会回复7楼,加上SetForegroundWindow后有所改善,但还有发生!
      

  6.   

    这个问题应该是你程序没有焦点,你把SetForegroundWindow(Handle)改成SetForegroundWindow(Application.Handle)试一下。
      

  7.   

    Handle和Application.Handle有什么区别?
      

  8.   

    Application.Handle是哪个隐藏窗体的句柄,Handle是当前窗体的句柄。
      

  9.   

    哦!我是在要显示的窗体中调用SetForegroundWindow方法的,也就是定义为Params.WndParent := GetDesktopWindow; Params.ExStyle := Params.ExStyle or WS_EX_TOOLWINDOW;的窗体!你的意思是要让主窗体SetForegroundWindow一下,然后在子窗体SetForegroundWindow,我试试吧,主窗体是最小化的