Solved

Screen dimensions adjusted for taskbar etc

Posted on 1998-12-08
9
181 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

16 Experts available now in Live!

Get 1:1 Help Now