Solved

How to find the position of the taskbar

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month6 days, 19 hours left to enroll

623 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