Solved

How to programmatically minimize a window in delphi

Posted on 2011-09-16
12
1,322 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 157
Working with hours 3 65
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 44
Multi-layered image in FireMonkey 9 49
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 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