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 ?
LVL 1
LeTayAsked:
Who is Participating?
 
rinfoCommented:
yeah i think the issue is with vista and window 7 as Microsoft explains it
"User Interface Privilege Isolation (UIPI) implements restrictions in the windows subsystem that prevents lower-privilege applications from sending window messages or installing hooks in higher-privilege processes. Higher-privilege applications are permitted to send window messages to lower-privilege processes. The restrictions are implemented in the SendMessage and related window message functions.
"
so a work around could be
first declare a function
function ChangeWindowMessageFilter(msg: Cardinal; action: Word): BOOL; stdcall;
    external 'user32.dll';

And in the form on create event call thiis function
ChangeWindowMessageFilter(WM_COMMAND, 1)

and its alternative is
function ChangeWindowMessageFilterEX(msg: Cardinal; action: Word): BOOL; stdcall;
    external 'user32.dll';

ChangeWindowMessageFiltereX(WM_COMMAND, 1)
 Besides this i have no clue as to how this can be achieved in  Vista.


1
 
Geert GOracle dbaCommented:
for the app:
Application.Minimize;

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

0
 
Geert GOracle dbaCommented:
WindowState Readonly ???
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
LeTayAuthor Commented:
Hello Geert : SW_MINIMIZED does not compile
Which unit is it in ?
Thanks
0
 
Geert GOracle dbaCommented:
windows

forgot the show

SW_SHOWMINIMIZED
0
 
LeTayAuthor Commented:
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)
0
 
rinfoCommented:
SendMessage(hWin,WM_SYSCOMMAND,SC_MINIMIZE,0);
should work ok.

1
 
LeTayAuthor Commented:
Hello rinfo, what is hWin ? It does not compile like that
Thanks
0
 
rinfoCommented:
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.
1
 
LeTayAuthor Commented:
Does not work with neither 'TForm1' nor 'Form1'
0
 
rinfoCommented:
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.
0
 
LeTayAuthor Commented:
Indeed TForm1 is the form class
But it did not work on my PC (Windows Vista)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.