• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1744
  • Last Modified:

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 ?
1
LeTay
Asked:
LeTay
  • 5
  • 4
  • 3
1 Solution
 
Geert GruwezOracle dbaCommented:
for the app:
Application.Minimize;

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

0
 
Geert GruwezOracle dbaCommented:
WindowState Readonly ???
0
 
LeTayAuthor Commented:
Hello Geert : SW_MINIMIZED does not compile
Which unit is it in ?
Thanks
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
Geert GruwezOracle 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
 
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now