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 : 16/02/2007 18:20:53
Vue : 5968
Catégorie(s) : API, Trucs & Astuces
Langages dispo pour ce code :
- Delphi 5
- Delphi 5
- Delphi 5
- Delphi 5
- C



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;
}

// ...


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
...

{Javascript / DHTML} FENETRE MULTIPLE
des fenêtres dans le navigateur que l'on déplace a la sourie dans lesquelles tout contenu peut être ...

{Delphi} COULEURS SYSTÈME
Petit programme sans prétention qui utilise les fonctions du SDK pour gérer les couleurs du système ...

{Delphi} VISIOMEM - AFFICHER VOTRE MÉMOIRE
Bonjour, cette application permet d'afficher une barre dans le coin inferieur droit de votre écran,...

{C / C++ / C++.NET} VOIR UNE IMAGE GIF C/C++
load un fichier gif ou load comme ressource et fait l animation de l image avec un simple boite d...

{C / C++ / C++.NET} RACOURCI SHORTCUT
un autre source sur la creation de racouci 2 fonction facile pour creer un racourci ou on veut ...

{Python} OPTI2 OU COMMENT OPTIMISER WINDOWS XP ET/2000 EN QUELQUES CLICS
Opti2 est un soft d'optimisation de windows xp et/ou 2000. Il comprend une vingtaine d'optimisati...