VicoLaChips2
Messages postés436Date d'inscriptiondimanche 20 janvier 2002StatutMembreDernière intervention 2 février 2010
-
2 juin 2002 à 10:29
farrakis
Messages postés32Date d'inscriptionvendredi 28 janvier 2005StatutMembreDernière intervention12 mai 2013
-
4 juin 2008 à 08:55
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.
farrakis
Messages postés32Date d'inscriptionvendredi 28 janvier 2005StatutMembreDernière intervention12 mai 2013 4 juin 2008 à 08:55
Merci beaucoup ca marche impec :)
Juste modifier cette ligne
PathCourt = PathCourt.Substring(0, lngIPos - 1)
en
PathCourt = PathCourt.Substring(0, lngIPos)
pour que l'extension des mes noms de fichier ne soit pas tronquée..;
Encore une fois merci
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 4 juin 2008 à 04:23
on donne cette reference pour que l'API puisse connaitre la police que nous utilisons
Public Class Form1
Private Declare Function PathCompactPath Lib "shlwapi" Alias "PathCompactPathA" (ByVal hDC As Integer, ByVal lpszPath As String, ByVal dx As Integer) As Integer
Public Function PathCourt(ByVal strPath As String, ByVal lngMaxPixels As Integer, ByVal lngHDC As Integer) As String
Dim lngR, lngIPos As Integer
PathCourt = strPath
lngR = PathCompactPath(lngHDC, PathCourt, lngMaxPixels)
lngIPos = PathCourt.IndexOf(vbNullChar)
If lngIPos > 0 Then
PathCourt = PathCourt.Substring(0, lngIPos - 1)
End If
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oGr As Graphics
oGr = Me.CreateGraphics
Label1.Text = PathCourt("Bonjour, je suis un très très long texte, excusez moi...", Label1.Width, oGr.GetHdc())
oGr.Dispose()
End Sub
End Class
farrakis
Messages postés32Date d'inscriptionvendredi 28 janvier 2005StatutMembreDernière intervention12 mai 2013 3 juin 2008 à 18:56
merci renfield.. mais là ça depasse de bcp mes pauvres capacités en programmation ..
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 3 juin 2008 à 10:52
pas besoin, .Net cause en pixels
faut pas faire du copier coller, ni "traduire", faut adapter...
hDc => Device Context Handle
identifiant de la surface de rendu, en gros
farrakis
Messages postés32Date d'inscriptionvendredi 28 janvier 2005StatutMembreDernière intervention12 mai 2013 3 juin 2008 à 10:34
Bonjour,
je travaille en vb.net et je n'arrive pas à utiliser l'api "PathCompactPath" dont l 'exemple est donné par Dalida...
Je bloque sur lblFichier.Caption = PathCourt(Path, lblFichier.Width/Screen.TwipsPerPixelX, Me.hDC)...
En particulier sur "Screen.TwipsPerPixelX" qui n'est pas reconnu en .net (le traducteur auto donne VB6.TwipsPerPixelX)
et sur Me.hDC sur lequel je bloque total
Si qqn pouvait traduire le VB6 en VB.net (avec les explications de ce à quoi correpond ME.hDC que je me couhe moins bete) je le remercie ...
Merci d'avance
cs_Exploreur
Messages postés4821Date d'inscriptionlundi 11 novembre 2002StatutMembreDernière intervention15 novembre 201615 13 nov. 2006 à 17:56
Coucou Jack..me revoilu...ben...ton code comme celui de Renfield est impécable, vous êtes vraiment complémentaire tout les deux.
C'est cool car avec vous, en autre, on apprend pas mal de chose.
A+
Exploreur.
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 14 mars 2006 à 12:08
l'API PathCompactPathEx est aussi disponible.
celle ci permet de définir le nombre de carctères, plutôt qu'un nombre de Pixels
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 14 mars 2006 à 11:53
DrawText le fait aussi, et on a même le contrôle sur l'ellipse utilisée :
Private Const DT_WORD_ELLIPSIS = &H40000
Private Const DT_PATH_ELLIPSIS = &H4000&
Private Const DT_END_ELLIPSIS = &H8000&
cs_Jack
Messages postés14006Date d'inscriptionsamedi 29 décembre 2001StatutModérateurDernière intervention28 août 201579 24 août 2002 à 02:07
C'est superbe ton truc, Dalida. Chapeau !
Je savais pô qu'il y avait une DLL qui fasse ça.
Merci beaucoup pour la démo. Cool.
Dalida
Messages postés6728Date d'inscriptionmardi 14 mai 2002StatutContributeurDernière intervention11 janvier 2016 23 août 2002 à 22:37
salut,
moi j'utilisais une API
'le boulot n'est pas de moi c'est lui qui l'a fait :
'Auteur: Dombeu Kouam Carlos
'E-Mail: camernet@ifrance.com
'Site: http://camernet.ifrance.com
Option Explicit
Private Declare Function PathCompactPath Lib "shlwapi" Alias "PathCompactPathA" (ByVal hDC As Long, ByVal lpszPath As String, ByVal dx As Long) As Long
Public Function PathCourt(ByVal strPath As String, ByVal lngMaxPixels As Long, ByVal lngHDC As Long) As String
Dim lngR, lngIPos As Long
lngR = PathCompactPath(lngHDC, strPath, lngMaxPixels)
lngIPos = InStr(strPath, Chr$(0))
If lngIPos <> 0 Then
PathCourt = Left$(strPath, lngIPos - 1)
Else
PathCourt = strPath
End If
End Function
VicoLaChips2
Messages postés436Date d'inscriptiondimanche 20 janvier 2002StatutMembreDernière intervention 2 février 20102 2 juin 2002 à 16:11
plus élégant pas forcément :), mais sans le GOTO >> YES :
'à la place de la boucl GOTO :
'faire tant que l'ensemble du résultat à afficher est inférieur à la longueur
Do While TestFonte.TextWidth(Left(Fichier, i) & Fin) < lLongueur
'position du prochain anti - slash
i = InStr(i + 1, Fichier, "")
'si pas de slash restant, concateine et sort
If i 0 Then RépertoireCourt Début & Fin: Exit Do
'pareil après !!
If TestFonte.TextWidth(Left(Fichier, i) & Fin) < lLongueur Then
Début = Left(Fichier, i)
Else
Début = Début & Fin
End If
RépertoireCourt = Début
Loop
cs_Jack
Messages postés14006Date d'inscriptionsamedi 29 décembre 2001StatutModérateurDernière intervention28 août 201579 2 juin 2002 à 13:41
Merci VicoLaChips2
Oui, il y a un Goto
En fait, on peut pas le remplacer par un Do-Loop car le test du "i = Instr(..." peut donner 0 s'il ne trouve rien
Si, dans le même If, on met "i 0 or Left(Fichier, i) ..." et que i 0, la fonction Left sera calculée, et Left(Fichier, 0 ) donnera une erreur.
Donc il faut absolument faire de If imbriqués
D'où le retour avec le Goto
Si tu trouves plus élégant, n'hésite pas à en faire profiter tout le monde ;-)
Jack
VicoLaChips2
Messages postés436Date d'inscriptiondimanche 20 janvier 2002StatutMembreDernière intervention 2 février 20102 2 juin 2002 à 10:29
C'est kool !! Le formatage du code est nickel sauf un truc :) C'est quoi ce GOTO là ?? ya surment un autre moyen !
4 juin 2008 à 08:55
Juste modifier cette ligne
PathCourt = PathCourt.Substring(0, lngIPos - 1)
en
PathCourt = PathCourt.Substring(0, lngIPos)
pour que l'extension des mes noms de fichier ne soit pas tronquée..;
Encore une fois merci
4 juin 2008 à 04:23
Public Class Form1
Private Declare Function PathCompactPath Lib "shlwapi" Alias "PathCompactPathA" (ByVal hDC As Integer, ByVal lpszPath As String, ByVal dx As Integer) As Integer
Public Function PathCourt(ByVal strPath As String, ByVal lngMaxPixels As Integer, ByVal lngHDC As Integer) As String
Dim lngR, lngIPos As Integer
PathCourt = strPath
lngR = PathCompactPath(lngHDC, PathCourt, lngMaxPixels)
lngIPos = PathCourt.IndexOf(vbNullChar)
If lngIPos > 0 Then
PathCourt = PathCourt.Substring(0, lngIPos - 1)
End If
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oGr As Graphics
oGr = Me.CreateGraphics
Label1.Text = PathCourt("Bonjour, je suis un très très long texte, excusez moi...", Label1.Width, oGr.GetHdc())
oGr.Dispose()
End Sub
End Class
3 juin 2008 à 18:56
en gros dans ma form j'écris quoi?
lblFichier.Caption = PathCourt(Path, lblFichier.Width, Me.hDC)
sachant que me.hDC il ne connait pas ??
Merci
3 juin 2008 à 10:52
faut pas faire du copier coller, ni "traduire", faut adapter...
hDc => Device Context Handle
identifiant de la surface de rendu, en gros
3 juin 2008 à 10:34
je travaille en vb.net et je n'arrive pas à utiliser l'api "PathCompactPath" dont l 'exemple est donné par Dalida...
Je bloque sur lblFichier.Caption = PathCourt(Path, lblFichier.Width/Screen.TwipsPerPixelX, Me.hDC)...
En particulier sur "Screen.TwipsPerPixelX" qui n'est pas reconnu en .net (le traducteur auto donne VB6.TwipsPerPixelX)
et sur Me.hDC sur lequel je bloque total
Si qqn pouvait traduire le VB6 en VB.net (avec les explications de ce à quoi correpond ME.hDC que je me couhe moins bete) je le remercie ...
Merci d'avance
13 nov. 2006 à 17:56
C'est cool car avec vous, en autre, on apprend pas mal de chose.
A+
Exploreur.
14 mars 2006 à 12:08
celle ci permet de définir le nombre de carctères, plutôt qu'un nombre de Pixels
14 mars 2006 à 11:53
Private Const DT_WORD_ELLIPSIS = &H40000
Private Const DT_PATH_ELLIPSIS = &H4000&
Private Const DT_END_ELLIPSIS = &H8000&
24 août 2002 à 02:07
Je savais pô qu'il y avait une DLL qui fasse ça.
Merci beaucoup pour la démo. Cool.
23 août 2002 à 22:37
moi j'utilisais une API
'le boulot n'est pas de moi c'est lui qui l'a fait :
'Auteur: Dombeu Kouam Carlos
'E-Mail: camernet@ifrance.com
'Site: http://camernet.ifrance.com
Option Explicit
Private Declare Function PathCompactPath Lib "shlwapi" Alias "PathCompactPathA" (ByVal hDC As Long, ByVal lpszPath As String, ByVal dx As Long) As Long
Private Const DT_BOTTOM = &H8&
Private Const DT_CENTER = &H1&
Private Const DT_LEFT = &H0&
Private Const DT_CALCRECT = &H400&
Private Const DT_WORDBREAK = &H10&
Private Const DT_VCENTER = &H4&
Private Const DT_TOP = &H0&
Private Const DT_TABSTOP = &H80&
Private Const DT_SINGLELINE = &H20&
Private Const DT_RIGHT = &H2&
Private Const DT_NOCLIP = &H100&
Private Const DT_INTERNAL = &H1000&
Private Const DT_EXTERNALLEADING = &H200&
Private Const DT_EXPANDTABS = &H40&
Private Const DT_CHARSTREAM = 4&
Private Const DT_NOPREFIX = &H800&
Private Const DT_EDITCONTROL = &H2000&
Private Const DT_PATH_ELLIPSIS = &H4000&
Private Const DT_END_ELLIPSIS = &H8000&
Private Const DT_MODIFYSTRING = &H10000
Private Const DT_RTLREADING = &H20000
Private Const DT_WORD_ELLIPSIS = &H40000
Public Function PathCourt(ByVal strPath As String, ByVal lngMaxPixels As Long, ByVal lngHDC As Long) As String
Dim lngR, lngIPos As Long
lngR = PathCompactPath(lngHDC, strPath, lngMaxPixels)
lngIPos = InStr(strPath, Chr$(0))
If lngIPos <> 0 Then
PathCourt = Left$(strPath, lngIPos - 1)
Else
PathCourt = strPath
End If
End Function
ça donne :
lblFichier.Caption = PathCourt(Path, lblFichier.Width Screen.TwipsPerPixelX, Me.hDC)
2 juin 2002 à 16:11
'à la place de la boucl GOTO :
'faire tant que l'ensemble du résultat à afficher est inférieur à la longueur
Do While TestFonte.TextWidth(Left(Fichier, i) & Fin) < lLongueur
'position du prochain anti - slash
i = InStr(i + 1, Fichier, "")
'si pas de slash restant, concateine et sort
If i 0 Then RépertoireCourt Début & Fin: Exit Do
'pareil après !!
If TestFonte.TextWidth(Left(Fichier, i) & Fin) < lLongueur Then
Début = Left(Fichier, i)
Else
Début = Début & Fin
End If
RépertoireCourt = Début
Loop
2 juin 2002 à 13:41
Oui, il y a un Goto
En fait, on peut pas le remplacer par un Do-Loop car le test du "i = Instr(..." peut donner 0 s'il ne trouve rien
Si, dans le même If, on met "i 0 or Left(Fichier, i) ..." et que i 0, la fonction Left sera calculée, et Left(Fichier, 0 ) donnera une erreur.
Donc il faut absolument faire de If imbriqués
D'où le retour avec le Goto
Si tu trouves plus élégant, n'hésite pas à en faire profiter tout le monde ;-)
Jack
2 juin 2002 à 10:29
Bonne continuation @+