Solved

How to programmatically minimize a window in delphi

Posted on 2011-09-16
12
1,404 Views
Last Modified: 2012-05-12
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 ?
0
Comment
Question by:LeTay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 36549032
for the app:
Application.Minimize;

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

0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 36549053
WindowState Readonly ???
0
 

Author Comment

by:LeTay
ID: 36549095
Hello Geert : SW_MINIMIZED does not compile
Which unit is it in ?
Thanks
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 36549178
windows

forgot the show

SW_SHOWMINIMIZED
0
 

Author Comment

by:LeTay
ID: 36549219
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
 
LVL 9

Expert Comment

by:rinfo
ID: 36553808
SendMessage(hWin,WM_SYSCOMMAND,SC_MINIMIZE,0);
should work ok.

0
 

Author Comment

by:LeTay
ID: 36554009
Hello rinfo, what is hWin ? It does not compile like that
Thanks
0
 
LVL 9

Expert Comment

by:rinfo
ID: 36554089
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.
0
 

Author Comment

by:LeTay
ID: 36554114
Does not work with neither 'TForm1' nor 'Form1'
0
 
LVL 9

Expert Comment

by:rinfo
ID: 36555556
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
 

Author Comment

by:LeTay
ID: 36556034
Indeed TForm1 is the form class
But it did not work on my PC (Windows Vista)
0
 
LVL 9

Accepted Solution

by:
rinfo earned 500 total points
ID: 36556160
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.


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question