Solved

Screen dimensions adjusted for taskbar etc

Posted on 1998-12-08
9
180 Views
Last Modified: 2010-04-04
Screen.Width and Screen.Height report the dimensions of the desktop window.

How can one obtain what might be described as its client area?

By client area I mean that part of the desktop window not occupied by the TaskBar or dockable windows such as ICQ.

The best I've been able to come up with so far is maximising a window and inspecting its width and height. This works, but there MUST be a better way.

References to MSDN would be welcome.
0
Comment
Question by:wamoz
  • 3
  • 3
  • 3
9 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1349994
Use GetSystemMetrics with the SM_CXMAXIMIZED and SM_CYMAXIMIZED flags.

0
 
LVL 2

Expert Comment

by:gallaghe
ID: 1349995
You could also use the following

(Place in the interface section of the form/unit)
MyRec = record
  iLeft:Integer;
  iTop:Integer;
  iRight:Integer;
  iBottom:Integer;
end;

procedure TfrmMain.Button1Click(Sender: TObject);
var
  R:MyRec;
begin
  if SystemParametersInfo(SPI_GETWORKAREA,0,@R,0) then
    ShowMessage('Desktop specs' + #13 +
      Format('Left %d Top %d Right %d Bottom %d',
      [R.iLeft,
       R.iTop,
       R.iRight,
       R.iBottom]));
end;

From MyRec members you can now know the client area not used by stuff like WinDoz taskbar or MS-Office toolbar

Kevin S. Gallagher
0
 
LVL 1

Author Comment

by:wamoz
ID: 1349996
The information provided was not in fact correct. However, researching the suggested function lead directly to the discovery of the necessary information. Here is an excerpt from MSDN


SM_CXFULLSCREEN, SM_CYFULLSCREEN

Width and height of the client area for a full-screen window on the primary display monitor. To get the coordinates of the portion of the screen not obscured by the system taskbar or by application desktop toolbars, call the SystemParametersInfo function with the SPI_GETWORKAREA value.  

Although normally I would accept this answer because it gives me something with which to work, gallaghe's comment not only is completely correct but also includes source code that works as advertised.

Therefore I must reject rwilson's answer and ask ghallaghe to restate his comment as a proposed answer so that I can accept it.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1349997
You know, its strange how you read things. I initially saw the fullscreen ones but rejected them because I thought they would include the task bar etc (which they do) but didn't read down to the bit about SyspemParametersInfo :-(

Cheers,

Raymond.

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

by:wamoz
ID: 1349998
Never mind, Ray. It happens to me all the time. I dithered for quite a while before deciding to reject your answer. As I said, I only did so because someone else had already tendered complete and correct info. I really appreciate your effort.
-----------------------------------
Peter Routtier-Wone
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1349999
No problems - his was the correct answer.

Cheers,

Raymond.
0
 
LVL 2

Accepted Solution

by:
gallaghe earned 100 total points
ID: 1350000
As requested, I am posting this as an answer

You could also use the following

(Place in the interface section of the form/unit)
MyRec = record
  iLeft:Integer;
  iTop:Integer;
  iRight:Integer;
  iBottom:Integer;
end;

procedure TfrmMain.Button1Click(Sender: TObject);
var
  R:MyRec;
begin
  if SystemParametersInfo(SPI_GETWORKAREA,0,@R,0) then
    ShowMessage('Desktop specs' + #13 +
      Format('Left %d Top %d Right %d Bottom %d',
      [R.iLeft,
       R.iTop,
       R.iRight,
       R.iBottom]));
end;

From MyRec members you can now know the client area not used by stuff like WinDoz taskbar or MS-Office toolbar

Kevin S. Gallagher
 
 

0
 
LVL 2

Expert Comment

by:gallaghe
ID: 1350001
A nice clean method besides "SystemParametersInfo" would be to have a component that gives you the information asked for. Jump to http://www.pobox.com/~bstowers/delphi/ were Brad Stowers has TTaskBarInfo component. The only thing you need to do is drop the control on a form and ask questions via it;s properties. Brad utilizes "SHAppBarMessage" to work with the Taskbar along with stuff like "GetWindowRect" for getting the TaskBar;s rect.

Sample dynamic call:
procedure TForm1.Button1Click(Sender: TObject);
var
  S:String ;
begin
  with TTaskBarInfo.Create(Self) do begin
    case BarPosition of
      abeBottom:  S := 'Bottom' ;
      abeLeft:    S := 'Left' ;
      abeRight:   S := 'Right' ;
      abeTop:     S := 'Top' ;
    end ;

    ShowMessage('The TaskBar is on the ' + S + #13 +
      Format('TaskBar Rec: Top %d Left %d Bottom %d Right %d',
        [BarRect.Top,BarRect.Left,BarRect.Bottom,BarRect.Right])) ;
    Free ;
  end ;

end;

Kevin S. Gallagher

0
 
LVL 1

Author Comment

by:wamoz
ID: 1350002
I've been pursuing the SHAppBarMessage line of inquiry myself, since our first exchange on this topic.

I've been having a bit of grief converting the C to Delphi, mostly because the mechanism of the sample code is not in the slightest part object oriented.

MS programmers have a nasty habit of writing their code as friend functions that break encapsulation. I wish they'd create helper objects that take an object as a parameter.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Master Detail with TADODataset 4 96
Save pdf file to other location 3 72
How to convert wav to mp3 in delphi 9 137
Magic Software info 18 105
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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

22 Experts available now in Live!

Get 1:1 Help Now