既存のパスにファイル名を追加          <TOP>


PathAppend 既存のパスにファイル名を追加
 

 

'================================================================
'= 既存のパスにファイル名を追加
'=    (PathAppend.bas)
'================================================================
#include "Windows.bi"

' 既存のパスにファイル名を追加
Declare Function Api_PathAppend& Lib "shlwapi" Alias "PathAppendA" (ByVal pszPath$, ByVal pMore$)

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

Edit1.Attach GetDlgItem("Edit1") : Edit1.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:\testpath\dir"
End Sub

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var sSave As String
    Var Ret As Long

    sSave = Edit1.GetWindowText & String$(100, 0)

    Ret = Api_PathAppend(sSave, "myfile.tst")
    
    Text1.SetWindowText TrimNull(sSave)
End Sub

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