Link to home
Start Free TrialLog in
Avatar of LeTay
LeTay

asked on

How to programmatically minimize a window in delphi

I need to programmatically minimze a form in Delphi
The WindowState property gives the state but is read-only
So how do I minimize my form at run time, without user intervention ?
Avatar of Geert G
Geert G
Flag of Belgium image

for the app:
Application.Minimize;

or a separate form:
ShowWindow(Form1.Handle, SW_MINIMIZED);

WindowState Readonly ???
Avatar of LeTay
LeTay

ASKER

Hello Geert : SW_MINIMIZED does not compile
Which unit is it in ?
Thanks
windows

forgot the show

SW_SHOWMINIMIZED
Avatar of LeTay

ASKER

Works but I thought it would react as if you click in the top menu bar on the _ (minimize) button
Is there a way to have the same (so the icon is on the task bar at the botton)
SendMessage(hWin,WM_SYSCOMMAND,SC_MINIMIZE,0);
should work ok.

Avatar of LeTay

ASKER

Hello rinfo, what is hWin ? It does not compile like that
Thanks
Hwin is for Handle of the window.
SOrry for the shortcut snippets
here is what you should be doing

var  Hwin: THandle  ;
begin
  hwin := FindWindow ('TForm1', nil);
  SendMessage(hwin,WM_SYSCOMMAND,SC_MINIMIZE,0);
end;

I have tested it.
Avatar of LeTay

ASKER

Does not work with neither 'TForm1' nor 'Form1'
I have tested it and then posted it.
TForm1 is the name of the form you are using.
If your form name is TForm1 it should work.
Which version of window are you using.Window API works oddly in WIndow7 i will check this in windows t.
Avatar of LeTay

ASKER

Indeed TForm1 is the form class
But it did not work on my PC (Windows Vista)
ASKER CERTIFIED SOLUTION
Avatar of rinfo
rinfo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial