Solved

How to find the position of the taskbar

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

11 Experts available now in Live!

Get 1:1 Help Now