Solved

How to find the position of the taskbar

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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