You will need: Command1 and Label1.
' In general declarations
Private Declare Function PathCompactPath Lib "shlwapi" Alias "PathCompactPathA" (ByVal hDC As Long, ByVal lpszPath As String, ByVal dx As Long) As Long
' On a Form
Private Sub Command1_Click()
Dim lhDC As Long, lCtlWidth As Long
Dim FileSpec As String
FileSpec = "C:\MyFolder\VisualBasic\MyReallyWayTooLongFolderName\ButWhoCares\IhaveTheAPI.doc"
Me.ScaleMode = vbPixels
lCtlWidth = Label1.Width - Me.DrawWidth
lhDC = Me.hDC
PathCompactPath lhDC, FileSpec, lCtlWidth
Label1.Caption = FileSpec
End Sub
Click the button and see that the FileSpec variable is shortened to fit inside the label1's width.
Comments