Partager via


PathCompactPathA, fonction (shlwapi.h)

Tronque un chemin d’accès de fichier pour qu’il s’adapte à une largeur de pixel donnée en remplaçant les composants de chemin par des points de suspension.

Syntaxe

BOOL PathCompactPathA(
  [in]      HDC   hDC,
  [in, out] LPSTR pszPath,
  [in]      UINT  dx
);

Paramètres

[in] hDC

Type : HDC

Handle du contexte d’appareil utilisé pour les métriques de police. Cette valeur peut être NULL.

[in, out] pszPath

Type : LPTSTR

Pointeur vers une chaîne terminée par un caractère Null de longueur MAX_PATH qui contient le chemin d’accès à modifier. Au retour, cette mémoire tampon contient la chaîne modifiée.

[in] dx

Type : UINT

Largeur, en pixels, dans laquelle la chaîne doit tenir.

Valeur retournée

Type : BOOL

Retourne TRUE si le chemin a été correctement compacté à la largeur spécifiée. Retourne FALSE en cas d’échec, ou si la partie de base du chemin d’accès ne correspond pas à la largeur spécifiée.

Remarques

Cette fonction utilise la police actuellement sélectionnée dans hDC pour calculer la largeur du texte. Cette fonction ne compacte pas le chemin au-delà du nom de fichier de base précédé d’ellipses.

Exemples

#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"

HDC hdc;  /* display DC handle to current font metrics */ 

void main( void )
{
// String path name 1.
char buffer_1[MAX_PATH] = "C:\\path1\\path2\\sample.txt";
char *lpStr1;
lpStr1 = buffer_1;

// String path name 2.
char buffer_2[MAX_PATH] = "C:\\path1\\path2\\sample.txt";
char *lpStr2;
lpStr2 = buffer_2;

// String path name 3.
char buffer_3[MAX_PATH] = "C:\\path1\\path2\\sample.txt";
char *lpStr3;
lpStr3 = buffer_3;

// String path name 4.
char buffer_4[MAX_PATH] = "C:\\path1\\path2\\sample.txt";
char *lpStr4;
lpStr4 = buffer_4;

// Variable to get the return from "PathCompactPath".
int retval;

cout << "The un-truncated path is                " << lpStr1 << endl;

retval = PathCompactPath(hdc,lpStr1,125);
cout << "The truncated path at 125 pixels is :   " << lpStr1 << endl;

retval = PathCompactPath(hdc,lpStr2,120);
cout << "The truncated path at 120 pixels is :   " << lpStr2 << endl;

retval = PathCompactPath(hdc,lpStr3,110);
cout << "The truncated path at 110 pixels is :   " << lpStr3 << endl;

retval = PathCompactPath(hdc,lpStr4,25);
cout << "The truncated path at  25 pixels is :   " << lpStr4 << endl;
}

OUTPUT:
===========
The un-truncated path is                C:\path1\path2\sample.txt
The truncated path at 125 pixels is :   C:\path1\...\sample.txt
The truncated path at 120 pixels is :   C:\pat...\sample.txt
The truncated path at 110 pixels is :   C:\p...\sample.txt
The truncated path at  25 pixels is :   ...\sample.txt

Notes

L’en-tête shlwapi.h définit PathCompactPath en tant qu’alias qui sélectionne automatiquement la version ANSI ou Unicode de cette fonction en fonction de la définition de la constante de préprocesseur UNICODE. La combinaison de l’utilisation de l’alias neutre en encodage avec du code qui n’est pas neutre en encodage peut entraîner des incompatibilités qui entraînent des erreurs de compilation ou d’exécution. Pour plus d’informations, consultez Conventions pour les prototypes de fonction.

Configuration requise

Condition requise Valeur
Client minimal pris en charge Windows 2000 Professionnel, Windows XP [applications de bureau uniquement]
Serveur minimal pris en charge Windows 2000 Server [applications de bureau uniquement]
Plateforme cible Windows
En-tête shlwapi.h
Bibliothèque Shlwapi.lib
DLL Shlwapi.dll (version 4.71 ou ultérieure)