Solved

How to programmatically minimize a window in delphi

Posted on 2011-09-16
12
1,290 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
  • 5
  • 4
  • 3
12 Comments
 
LVL 37

Expert Comment

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

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

0
 
LVL 37

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
 
LVL 37

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now