Solved

How to find the position of the taskbar

Posted on 1998-11-02
1
449 Views
Last Modified: 2010-04-06
Hi,

I would like to position my window directly next to the taskbar. So how can I get the position and size of the taskbar?

Thanks,
pivar
0
Comment
Question by:pivar
[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
1 Comment
 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
ID: 1345451
Hi pivar,

some ways I found on the net :

Accessing Windows desktop properties


> Firstly, I would like to set my form's height to maximum so that it
> wouldn't go beyond the Windows taskbar (which is exactly what happens if I
> do a Form.Height := Screen.Height;). How do I find out where the taskbar
> starts? Is there something like Screen.ClientHeight?

> Secondly, I would like to set a scrollbox's width so that it would fit an
> image even if its vertical scrollbar is on. How do I get the scrollbar's
> width?


The following will take care of both problems:

procedure TForm1.Button1Click(Sender: TObject);
var FullScreenHeight,
    AvailableHeight,
    TaskBarHeight,
    ScrollBarWidth: integer;
begin
  FullScreenHeight := GetSystemMetrics(SM_CYSCREEN);    { height of
total screen }
  AvailableHeight := GetSystemMetrics(SM_CYFULLSCREEN);      { height of
screen minus taskbar }
  TaskBarHeight := FullScreenHeight - AvailableHeight;      { calculates
height of taskbar }
 
  ScrollBarWidth := StringGrid1.Width - StringGrid1.ClientWidth;
end;

This works in both D1 and D2.

Lanny

--------------------------------------

I answered the same question on DDj-THREAD a while back.
I think this works better as the user might not have the taskbar where you expec
This takes care of that plus it will return the true size of the workarea even i

Getting the workarea of the desktop:
uses Windows,Shellapi,....

var R,R2:TRect;A:TAppBarData;
begin
  A.cbSize := SizeOf(TAppBarData);
  SHAppBarMessage(ABM_GETTASKBARPOS, A);
  GetWindowRect(GetDesktopWindow,R2);
  SubtractRect(R,R2,A.rc);
  ShowMessage(Format('Workarea is %d x %d',[R.Right-R.Left,R.Bottom-R.Top]));
end;
 
the reason to call ShAppBarMessage is that unless the user has Always On
top selected, SPI_GETWORKAREA will return the
entire screen as the workarea (well it is, isn't it?). ABM_GETTASKBARPOS
returns the size of the taskbar, regardless of the settings on the taskbar
properties menu.

If you know that the user has Always on top checked or you want to adjust
to the current settings (allowing programs to overlap your taskbar etc),
you could call:

SystemParametersInfo(SPI_GETWORKAREA,0,@R,0);

instead. The return value adjusts according to the current settings

Regards, Peter

-------------------------------

Another method, that gives you the size of the taskbar in a tRect so that

var
   hand:  hWnd;
   r:     tRect;
begin
   hand := findWindow ('Shell_TrayWnd', nil);
   if hand = 0 then { there's no task bar };
   if hand <> 0 then begin
      getWindowRect (hand, r);
      { r.left, r.right, r.top, and r.bottom give you the bounds of
        the task bar}
      { r.bottom - r.top gives you the height of the task bar }
      { if height <= 6, then it's autohide }
   end;
end;

Sid Gudes
Santa Fe & Vallecitos, New Mexico
cougar@roadrunner.com

Author: Lanny G. Grim


Regards, Zif.

Personally, example 2 is my favorite.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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
Run video youtube webbrowse 10 74
FMX and jaudiotracker playing memory stream 29 98
enhance the following code 3 42
Delphi: sending SMS on android platform 1 69
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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