whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

25 Visitors Online


 
...determine the position of the taskbar?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (9):  
     


{1. With SHAppBarMessage }

uses
  
ShellAPI;

procedure TForm1.Button1Click(Sender: TObject);
var
  
tabd: TAppBarData;
  PosString: string;
begin
  
FillChar(tabd, SizeOf(TAppBarData), 0);
  tabd.cbSize := SizeOf(TAppBarData);
  if SHAppBarMessage(ABM_GETTASKBARPOS, Tabd) = 0 then Exit;
  with Tabd.rc do
    
PosString := Format(' (%d, %d);(%d, %d) ', [Left, Top, Right, Bottom]);
  case tabd.uEdge of
    
ABE_LEFT: ShowMessage('Left Position' + PosString);
    ABE_TOP: ShowMessage('Top Position' + PosString);
    ABE_RIGHT: ShowMessage('Right Position' + PosString);
    ABE_BOTTOM: ShowMessage('Bottom Position' + PosString);
  end;
end;

{2. With FindWindow, GetWindowRect }

type
  
TTaskBarPos = (_TOP, _BOTTOM, _LEFT, _RIGHT, _NONE);

function GetTaskBarPos: TTaskBarPos;
var
  
hTaskbar: HWND;
  T: TRect;
  scrW, scrH: integer;
begin
  
hTaskBar := FindWindow('Shell_TrayWnd', nil);
  if hTaskbar <> 0 then
  begin
    
GetWindowRect(hTaskBar, T);
    ScrW := Screen.Width;
    ScrH := Screen.Height;
    if (T.Top > scrH div 2) and (T.Right >= scrW) then
      
Result := _BOTTOM
    else if (T.Top < scrH div 2) and (T.Bottom <= scrW div 2) then
      
Result := _TOP
    else if (T.Left < scrW div 2) and (T.Top <= 0) then
      
Result := _LEFT
    else // the last "if" is not really needed
    
if T.Left >= ScrW div then
      
Result := _RIGHT;
  end;
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  
TaskBarPos: TTaskBarPos;
begin
  
TaskBarPos := GetTaskBarPos;
  case TaskBarPos of
    
_LEFT: ShowMessage('Left Position');
    _TOP: ShowMessage('Top Position');
    _RIGHT: ShowMessage('Right Position');
    _BOTTOM: ShowMessage('Bottom Position');
  end;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners