查看: 398  |  回复: 0
  VB6 压缩较长的全路径文件名中的路径
楼主
发表于 2023年4月21日 15:46

如何压缩较长的全路径文件名中的路径 (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


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2024 MaNongKu.com