Les Snippets

Connexion

Récupérer la hauteur de la barre des tâches

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 11/02/2007 23:04:01 et initié par WhiteHippo [Liste]
Date de mise à jour : 30/09/2009 12:34:31
Vue : 16036
Catégorie(s) : API, Trucs & Astuces
Langages dispo pour ce code :
- Delphi 5
- Delphi 5
- Delphi 5
- Delphi 5
- C
- VB6, VBA



Langage : Delphi 5
Date ajout : 11/02/2007
Posté par WhiteHippo [Liste]
function HauteurBarreDeTache : integer ;
var
  hBarreDeTache : HWND  ;
  R             : TRect ;
begin
  Result := -1 ;
  // Recherche de la fenêtre dont le nom de classe est "Shell_TrayWnd"
  //  c'est à dire la barre des tâches.
  hBarreDeTache := FindWindow( 'Shell_TrayWnd', '' ) ;
  // Vérification que le handle est valide
  if ( hBarreDeTache <> 0 ) then
  begin
    // Récupération du rectangle représentant la totalité de la barre des tâches
    GetWindowRect( hBarreDeTache, R ) ;
    // Bottom - Top car le 0 se trouve en haut de l'écran
    Result := R.Bottom - R.Top;
  end ;
end ;

Langage : Delphi 5
Date ajout : 16/02/2007
Posté par f0xi [Liste]
DateMAJ : 16/02/2007
{**
   Petite variante par rapport au code de WhiteHippo 
   permet de recuperer : 
   origine (LxT) de la barre des taches
   taille (WxH) de la barre des taches
   handle de la barre des taches
   position (L, T, R, B) de la barre des taches
**}

const
  { utilisé pour la valeur du flag TTaskBarInfo.Position }
  TASKBAR_POSITION_UNKNOW = byte($00);
  TASKBAR_POSITION_LEFT   = byte($01); 
  TASKBAR_POSITION_TOP    = byte($02);
  TASKBAR_POSITION_RIGHT  = byte($03);
  TASKBAR_POSITION_BOTTOM = byte($04);

type
  { utilisé par la fonction GetTaskBarInfos }
  TTaskBarInfo = record
     Left     : integer;
     Top      : integer;
     Width    : integer;
     Height   : integer;
     Position : byte;
     Handle   : HWND;
  end;

{ GetTaskBarInfos
   
  Recupere les informations (origine, taille, position, handle) de la barre des
  taches de windows.
  Params
     tbi [O] TTaskBarInfo structure
  Return
     boolean, true si reussite de l'operation
}
function GetTaskBarInfos(var tbi : TTaskBarInfo) : boolean;
var R : TRect;
    DL,DT,DW,DH : integer;
begin
  with tbi do
  begin
    Handle := FindWindow('Shell_TrayWnd',''); { @User32.FindWindowA }
    result := Handle <> INVALID_HANDLE_VALUE;
    if result then
    begin
      result := GetWindowRect(Handle, R); { @User32.GetWindowRect}
      if result then
      begin
        Left   := R.Left;
        Top    := R.Top;
        Width  := R.Right - R.Left;
        Height := R.Bottom - R.Top;
        DL     := Screen.DesktopLeft;
        DT     := screen.DesktopTop;
        DW     := screen.DesktopWidth;
        DH     := Screen.DesktopHeight;
        if (Left = DL) and (Top = DT) and (Width = DW) and (Height < DH) then
           Position := TASKBAR_POSITION_TOP
        else
        if (Left = DL) and (Top > DT) and (Width = DW) and (Height < DH) then
           Position := TASKBAR_POSITION_BOTTOM
        else
        if (Left = DL) and (Top = DT) and (Width < DW) and (Height = DH) then
           Position := TASKBAR_POSITION_LEFT
        else
        if (Left > DL) and (Top = DT) and (Width < DW) and (Height = DH) then
           Position := TASKBAR_POSITION_RIGHT
        else
           Position := TASKBAR_POSITION_UNKNOW;
      end;
    end;
  end;
end;

Langage : Delphi 5
Date ajout : 16/02/2007
Posté par f0xi [Liste]
{**
  Variante de mon code precedent en utilisant pas l'objet TScreen mais
  la fonction GetWindowDesktop.
**}

function GetTaskBarInfos(var tbi : TTaskBarInfo) : boolean;
var TR : TRect;
    DR : TRect;
    DL,DT,DW,DH : integer;
begin
  with tbi do
  begin
    Handle := FindWindow('Shell_TrayWnd',''); { @User32.FindWindowA }
    result := Handle <> INVALID_HANDLE_VALUE;
    if result then
    begin
      result := GetWindowRect(Handle, TR); { @User32.GetWindowRect}
      if result then
      begin
        Left   := TR.Left;
        Top    := TR.Top;
        Width  := TR.Right - TR.Left;
        Height := TR.Bottom - TR.Top;
        GetWindowRect(GetDesktopWindow, DR); { @User32.GetDesktopWindow }
        DL     := DR.Left;
        DT     := DR.Top;
        DW     := DR.Right-DR.Left;
        DH     := DR.Bottom-DR.Top;
        if (Left = DL) and (Top = DT) and (Width = DW) and (Height < DH) then
           Position := TASKBAR_POSITION_TOP
        else
        if (Left = DL) and (Top > DT) and (Width = DW) and (Height < DH) then
           Position := TASKBAR_POSITION_BOTTOM
        else
        if (Left = DL) and (Top = DT) and (Width < DW) and (Height = DH) then
           Position := TASKBAR_POSITION_LEFT
        else
        if (Left > DL) and (Top = DT) and (Width < DW) and (Height = DH) then
           Position := TASKBAR_POSITION_RIGHT
        else
           Position := TASKBAR_POSITION_UNKNOW;
      end;
    end;
  end;
end;

Langage : Delphi 5
Date ajout : 17/02/2007
Posté par cirec [Liste]
(*Autre méthode (plus directe)
  
  Elle donne : 
                        La position de la barre des tâches
                        Sa taille
                        Et si elle est en AutoHide où non
 
 Il existe d'autres possibilités voir dans l'aide de Delphi sous SHAppBarMessage 
*)
Uses ShellApi; 
procedure TForm1.Button1Click(Sender: TObject);
Var  AppData: TAppBarData;
     PosString: string;
begin
  AppData.cbSize := sizeof(AppData);
  AppData.hWnd := FindWindow('Shell_TrayWnd', nil);
  SHAppBarMessage(ABM_GETTASKBARPOS, AppData);
  With AppData.rc do
    PosString := Format(' [%d, %d];[%d, %d] ', [Left, Top, Right, Bottom]);
  If SHAppBarMessage(ABM_GETAUTOHIDEBAR, AppData) = AppData.hWnd Then
    PosString := PosString + 'AutoHide' Else
    PosString := PosString + 'NonAutoHide';
  case AppData.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;
(* Simple ... non ? *)
end;


Langage : C
Date ajout : 06/03/2007
Posté par Ombitious_Developper [Liste]
/**
  * GetToolBarHeight ()
  *
  * Calcule la hauteur de la barre des tâches.
  *
  * @return -1 en cas d'erreur sinon la hauteur de la barre d'outils.
  */
#include <Windows.h>
LONG GetToolBarHeight () {
    HWND hWnd = FindWindow ("Shell_TrayWnd", NULL);
    
    if (hWnd == NULL)
        return (LONG)-1;
    RECT windowRect;
    if (GetWindowRect (hWnd, &windowRect)) {
        // Succès
        return (windowRect.bottom - windowRect.top);
    }
    
    // Echéc
    return (LONG)-1;
}

// ...

Langage : VB6 , VBA
Date ajout : 30/09/2009
Posté par peug [Liste]
DateMAJ : 30/09/2009

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, ByRef pData As APPBARDATA) As Long
Private Const ABM_GETSTATE = &H4
Private Const ABM_GETTASKBARPOS = &H5
Private Type APPBARDATA
    cbSize As Long
    hWnd As Long
    uCallbackMessage As Long
    uEdge As Long
    rc As RECT
    lParam As Long
End Type

Public Function Height_TaskBar() As Long
    Dim ABD As APPBARDATA, ret As Long
    
    SHAppBarMessage ABM_GETTASKBARPOS, ABD
    
    Select Case ABD.uEdge 'position in screen
    Case 0 'left
        Height_TaskBar = (ABD.rc.Right * Screen.TwipsPerPixelX)
    Case 1, 3 'Top or bottom
        Height_TaskBar = ((ABD.rc.Bottom - ABD.rc.Top) * Screen.TwipsPerPixelY)
    Case 2 'right
        Height_TaskBar = ((ABD.rc.Right - ABD.rc.Left) * Screen.TwipsPerPixelX)

    End Select
End Function

Remarque :
Fonctionne jusque Vista

Snippets en rapport avec : Barre, Tâches, Windows, Hauteur



Codes sources en rapport avec : Barre, Tâches, Windows, Hauteur

{C / C++ / C++.NET} MODIFIER LA HAUTEUR DE LA BARRE DE TACHES
problème: quelle que soit la hauteur de la barre de tache avant l'extinction de Windows XP, celle-...

{JAVA / J2EE} PLEIN ECRAN EN TENANT COMPTE DE LA BARRE DES TACHES
Apparement c'est une question récurente dans le forum alors voila un petit bout de code ;)...

{C / C++ / C++.NET} ICONE DANS LA BARRE DES TACHES AVEC MENU (VC++)
Illustration pour mettre et enlever une icone dans la barre de taches avec gestion d'un menu. J'ai ...

{Visual Basic, VB6, VB.NET, VB 2005} MASQUER LA BARRE DES TÂCHES WINDOWS
...

{PHP} PHPREPOGENERATOR + REPO (WIN)
J'ai souhaitais créer ma propre source Cydia pour stocker mes Packages (Tweaks et autre). J'ai en...

{Visual Basic, VB6, VB.NET, VB 2005} MODIFICATION DATE DE WINDOWS EN VB.NET ET VBA
La modification de la date courante du système en vb.net est tout sauf simple ! Et cela se complique...

{C / C++ / C++.NET} POUR AFFICHER LES CARACTÈRES ACCENTUÉS SOUS WINDOWS EN MODE CONSOLE
Le code ASCII de base a été mis au point pour la langue anglaise, il ne contient donc pas de caractè...

{Javascript / DHTML} COLONNES ADAPTABLES EN HAUTEUR
Ce script permet d'homogénéiser la hauteur de plusieurs colonnes en fonction du contenu. Inutile de...

{Visual Basic, VB6, VB.NET, VB 2005} MODIFICATEUR D'INDICE DE PERFORMANCE WINDOWS 7
Yopla! J'ai pas testé sur Windows Vista, ça se peut très bien que ceci ne fonctionne pas car l'as...

{C / C++ / C++.NET} SOKOBAN EN C POUR DÉBUTANT (VERSION AMÉLIORÉE BASÉE SUR LE TUTORIEL DU SITE DU ZÉRO)
Bonjour, je vous propose ma première source en C. Je débute et me suis basé sur le tutoriel début...