Solved

How to find the position of the taskbar

Posted on 1998-11-02
1
443 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
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

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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

861 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