作成するパスなどをある程度決め撃ちしているので、汎用性はないです(^ ^;)
汎用性を持たせようと拡張している途中で挫折していますが、
このままでもある程度は使用可能なので公開させていただきます。
好き勝手に改造してやってください。
コード: 全て選択
'APIの宣言
Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (lpAppName As BytePtr, lpKeyName As BytePtr, nDefault As Long, lpFileName As BytePtr) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (lpAppName As BytePtr, lpKeyName As BytePtr, lpDefault As BytePtr, pReturnedString As BytePtr, nSize As DWord, lpFileName As BytePtr) As DWord
'Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (lpAppName As BytePtr, lpReturnedString As BytePtr, nSize As DWord, lpFileName As BytePtr) As DWord
'Declare Function GetPrivateProfileSectionNames Lib "kernel32" Alias "GetPrivateProfileSectionNamesA" (lpszReturnBuffer As BytePtr, nSize As DWord, lpFileName As BytePtr) As DWord
Declare Function GetPrivateProfileStruct Lib "kernel32" Alias "GetPrivateProfileStructA" (lpszSection As BytePtr,lpszKey As BytePtr,lpStruct As VoidPtr,uSizeStruct As DWord,szFile As BytePtr) As Long
Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (lpAppName As BytePtr, lpString As BytePtr, lpFileName As BytePtr) As Long
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (lpAppName As BytePtr, lpKeyName As BytePtr, lpString As BytePtr, lpFileName As BytePtr) As Long
Declare Function WritePrivateProfileStruct Lib "kernel32" Alias "WritePrivateProfileStructA" (lpszSection As BytePtr, lpszKey As BytePtr, lpStruct As VoidPtr, uSizeStruct As DWord, szFile As BytePtr) As Long
'クラス
Class PRIVATEPROFILE
Private
Path[512-1] As Byte 'プロファイルのパス
Section[64-1] As Byte 'セクション名
Public
'プロファイルの設定
Function SetPrivateProfile(lpFileName As BytePtr) As Long
dim i As Long, l As Long, buf[128-1] As Byte
i=GetModuleFileName(GetModuleHandle(0),Path,512)
Select Case lpFileName
Case 0
Path[i-3]=105
Path[i-2]=110
Path[i-1]=105
' Case Else
' GetFileTitle(Path,buf,128)
' l=lstrlen(buf)
' Path[i-l-1]=0
' lstrcat(Path,lpFileName)
End Select
End Function
'セクションの設定
Function SetSection(lpAppName As BytePtr) As Long
lstrcpy(Section,lpAppName)
End Function
'数値の読み込み
Function ReadInt(lpKeyName As BytePtr,nDefault As Long) As Long
ReadInt=GetPrivateProfileInt(Section,lpKeyName,nDefault,Path)
End Function
'文字列の読み込み
Function ReadString(lpKeyName As BytePtr,nDefault As BytePtr) As BytePtr
dim buf[512-1] As Byte
GetPrivateProfileString(Section,lpKeyName,nDefault,buf,512,Path)
ReadString=buf
End Function
'構造体の読み込み
Function ReadStruct(lpKeyName As BytePtr, lpStruct As VoidPtr, uSizeStruct As DWord) As Long
GetPrivateProfileStruct(Section,lpKeyName,lpStruct,uSizeStruct,Path)
End Function
'セクションの書き込み
Function WriteSection(lpAppName As BytePtr) As Long
WritePrivateProfileSection(lpAppName,"",Path)
lstrcpy(Section,lpAppName)
End Function
'数値の書き込み
Function WriteInt(lpKeyName As BytePtr,lpValue As Long) As Long
dim buf[64-1] As Byte
lstrcpy(buf,Str$(lpValue))
WritePrivateProfileString(Section,lpKeyName,buf,Path)
End Function
'文字列の書き込み
Function WriteString(lpKeyName As BytePtr,lpString As BytePtr) As Long
WritePrivateProfileString(Section,lpKeyName,lpString,Path)
End Function
'構造体の書き込み
Function WriteStruct(lpKeyName As BytePtr, lpStruct As VoidPtr, uSizeStruct As DWord) As Long
WritePrivateProfileStruct(Section,lpKeyName,lpStruct,uSizeStruct,Path)
End Function
End Class
読み込み
コード: 全て選択
Function IniLoad()
dim pPP As PRIVATEPROFILE, wp as RECT, i As Long, buf[512-1] As Byte
pPP.SetSection("Main")
wp.left=pPP.ReadInt("PosX",0)
wp.top=pPP.ReadInt("PosY",0)
lstrcpy(buf,pPP.ReadString("FilePath",""))
SetDlgItemText(hMainWnd,eb_exe_path,buf)
End Function
コード: 全て選択
Function IniSave()
dim pPP As PRIVATEPROFILE, wp as RECT, i As Long, buf[512-1] As Byte
GetWindowRect(hMainWnd,wp)
pPP.SetSection("Main")
pPP.WriteInt("PosX",wp.left)
pPP.WriteInt("PosY",wp.top)
GetDlgItemText(hMainWnd,eb_exe_path,buf,512)
pPP.WriteString("FilePath",buf)
End Function