如何压缩较长的全路径文件名中的路径 (Path) 字串长度?
压缩前的全路径文件名:
C:\MyFolder\VisualBasic\MyReallyWayTooLongFolderName\ButWhoCares\IhaveTheAPI.doc
压缩后的全路径文件名:
C:\MyFolder\VisualBasic\MyR...\IhaveTheAPI.doc
新建From1(窗体),新建Command1(按钮CommandButton),Label1(Label),代码:
Private Declare Function PathCompactPath Lib "shlwapi" Alias "PathCompactPathA" (ByVal hDC As Long, ByVal lpszPath As String, ByVal dx As Long) As Long
'hDC:device context handle。
'lpszPath:the address of the pathname。
'dx:the width in pixels of the spot in which you want the pathname to fit。
Private Sub Command1_Click()
Dim lhDC As Long, lCtlWidth As Long
Dim FileSpec As String
lhDC = Me.hDC
FileSpec = "C:\MyFolder\VisualBasic\MyReallyWayTooLongFolderName\"
FileSpec = FileSpec & "ButWhoCares\IhaveTheAPI.doc"
Me.ScaleMode = vbPixels
lCtlWidth = Label1.Width - Me.DrawWidth
PathCompactPath lhDC, FileSpec, lCtlWidth
Label1.Caption = FileSpec
End Sub