Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Screen dimensions adjusted for taskbar etc

Posted on 1998-12-08
9
Medium Priority
?
188 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
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 300 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

Industry Leaders: 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!

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

926 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