Solved

How to programmatically minimize a window in delphi

Posted on 2011-09-16
12
1,313 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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
 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi : could not find program, '...exe' 2 168
Intraweb download file link ? 1 132
Print Graphic and Text to Epson TM-T88v 12 250
how to update exe applicatio from internet ? 6 77
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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