Board index » delphi » Restoring iconized window

Restoring iconized window

Hi All,

How can I restore an iconized window?

I have the following code in my project to prevent users from starting it
twice on one computer. When I run my program, minimize it and then run it
for the second time, the first copy is restored but it's minimize button
doesn't work anymore...

var
  HWnd: THandle;

begin
  HWnd := FindWindow ('TfrmSVMain',WinTitle);
  if HWnd = 0 then begin
    {Start the program}
  end else begin {Make the previous copy active}
    if IsIconic(Hwnd) then ShowWindow(Hwnd, SW_RESTORE);
    ShowWindow(Hwnd, SW_SHOWMAXIMIZE);
  end;
end.

Regards,
Arjan

Arjan J. Moraal                |  PGP key? Send empty msg to
Paninaro Development           |  pgp-ajmor...@paninaro.xs4all.nl
Groningen, The Netherlands     |

 

Re:Restoring iconized window


ajmor...@paninaro.xs4all.nl (Arjan J. Moraal) wrote:

Quote
>Hi All,

>How can I restore an iconized window?

>I have the following code in my project to prevent users from starting it
>twice on one computer. When I run my program, minimize it and then run it
>for the second time, the first copy is restored but it's minimize button
>doesn't work anymore...

If you restore the form window, then Windows still thinks that the
_application_ is still iconized. You need to restore the _application_
window, not the _form_ window.
This code works for both D1 and D2.

begin
  { find the application window }
  Wnd:=FindWindow(nil,'Insurance Calculator');
  If Wnd<>0 then begin
    { Is the application window an icon? The form window will restore
as well }
    if IsIconic(wnd) then begin
      Application.Restore;
      ShowWindow(Wnd,SW_RESTORE);
    end;
    { Find the form window and bring it on top and active }
    Wnd:=FindWindow(nil,'Proplan Insurance Calculator');
    BringWindowToTop(Wnd);
    SetActiveWindow(Wnd);
  end
  else begin
    Application.Title := 'Insurance Calculator';
    Application.CreateForm(TForm1, Form1);
    Application.Run;
  end;
end.

==
Bob Small

Other Threads