自分自身のファイル名を取得          <TOP>


GetModuleFileName ロードされている実行モジュールのフルパス名を取得
GetFileTitle パスからファイル名を取得
 

'================================================================
'= 自分自身のファイル名を取得
'=    (GetModuleFileName.bas)
'================================================================
#include "Windows.bi"

' ロードされている実行モジュールのフルパス名を取得
Declare Function Api_GetModuleFileName& Lib "Kernel32" Alias "GetModuleFileNameA" (ByVal hModule&, ByVal lpFileName$, ByVal nSize&)

' パスからファイル名を取得
Declare Function Api_GetFileTitle& Lib "comdlg32" Alias "GetFileTitleA" (ByVal lpszFile$, ByVal lpszTitle$, ByVal cbBuf%)

Var Shared Text1 As Object
Var Shared Button1 As Object

Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var Buffer As String
    Var PathName As String
    Var FileName As String
    Var Ret As Long

    'パス名を取得
    Buffer = String$(260, Chr$(0))
    Ret = Api_GetModuleFileName(0, Buffer, Len(Buffer))
    PathName = Left$(Buffer, InStr(1, Buffer, Chr$(0)) - 1)

    'パス名からファイル名を抜き出す
    Buffer = String$(260, Chr$(0))
    Ret = Api_GetFileTitle(PathName, Buffer, Len(Buffer))
    FileName = Left$(Buffer, InStr(1, Buffer, Chr$(0)) - 1)

    Text1.SetWindowText FileName
End Sub

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