文字数に収まるようにパスの一部を省略          <TOP>


PathCompactPathEx 文字数に収まるようにパスの一部を省略
 

 

'================================================================
'= 文字数に収まるようにパスの一部を省略
'=    (PathCompactPathEx.bas)
'================================================================
#include "Windows.bi"

' 文字数に収まるようにパスの一部を省略
Declare Function Api_PathCompactPathEx& Lib "shlwapi" Alias "PathCompactPathExA" (ByVal pszOut$, ByVal pszSrc$, ByVal cchMax&, ByVal dwFlags&)

Var Shared Edit1 As Object
Var Shared Edit2 As Object
Var Shared Text1 As Object
Var Shared Button1 As Object

Edit1.Attach GetDlgItem("Edit1") : Edit1.SetFontSize 12
Edit2.Attach GetDlgItem("Edit2") : Edit2.SetFontSize 14
Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

'================================================================
'= Chr$(0)を取り除く
'================================================================
Declare Function TrimNull (item As String) As String
Function TrimNull(item As String) As String
    Var ePos As Integer

    ePos = Instr(item, Chr$(0))
    If ePos Then
        TrimNull = Left$(item, ePos - 1)
    Else
        TrimNull = item
    End If
End Function

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Edit1.SetWindowText "C:\MyFolder\FBasic\MyReallyWayTooLongFolderName\ButWhoCares\IhaveTheAPI.doc"
    Edit2.SetWindowText "25"
End Sub

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var nTxt As Integer
    Var sSave As String
    Var Buff As String
    Var Ret As Long
    
    Buff = String$(100, 0)
    sSave = Edit1.GetWindowtext
    nTxt = Val(Edit2.GetWindowText)
    
    Ret = Api_PathCompactPathEx(Buff, sSave, nTxt, 0)
    Text1.SetWindowText TrimNull(Buff)
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End