Hi, i'm trying to make a label's caption say the computers program files dir but the code i'm using just makes the caption say the desktop dir...?
Heres the code
VB Code:
Private Enum CSIDL_VALUES CSIDL_PROGRAM_FILES = &H26 End Enum Private Const SHGFP_TYPE_CURRENT = &H0 Private Const SHGFP_TYPE_DEFAULT = &H1 Private Const MAX_LENGTH = 260 Private Const S_OK = 0 Private Const S_FALSE = 1 Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long Private Declare Function SHGetFolderPath Lib "shfolder.dll" Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwReserved As Long, ByVal lpszPath As String) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const LB_SETTABSTOPS As Long = &H192 Private Sub Form_Load() Dim csidl As Long Label1.Caption = GetFolderPath(csidl, CSIDL_PROGRAM_FILES) End Sub Private Function GetFolderPath(csidl As Long, SHGFP_TYPE As Long) As String Dim buff As String Dim dwFlags As Long buff = Space$(MAX_LENGTH) If SHGetFolderPath(Me.hwnd, csidl Or dwFlags, -1, SHGFP_TYPE, buff) = S_OK Then GetFolderPath = TrimNull(buff) End If End Function Private Function TrimNull(startstr As String) As String TrimNull = Left$(startstr, lstrlenW(StrPtr(startstr))) End Function
Thanks in advance




Reply With Quote