Solved

Screen dimensions adjusted for taskbar etc

Posted on 1998-12-08
9
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
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…

752 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