Results 1 to 6 of 6

Thread: [Resolved] Program Files path

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    [Resolved] Program Files path

    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:
    1. Private Enum CSIDL_VALUES
    2.     CSIDL_PROGRAM_FILES = &H26
    3. End Enum
    4. Private Const SHGFP_TYPE_CURRENT = &H0
    5. Private Const SHGFP_TYPE_DEFAULT = &H1
    6. Private Const MAX_LENGTH = 260
    7. Private Const S_OK = 0
    8. Private Const S_FALSE = 1
    9. Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
    10. 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
    11. 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
    12. Private Const LB_SETTABSTOPS As Long = &H192
    13.  
    14. Private Sub Form_Load()
    15. Dim csidl As Long
    16. Label1.Caption = GetFolderPath(csidl, CSIDL_PROGRAM_FILES)
    17. End Sub
    18.  
    19. Private Function GetFolderPath(csidl As Long, SHGFP_TYPE As Long) As String
    20. Dim buff As String
    21. Dim dwFlags As Long
    22. buff = Space$(MAX_LENGTH)
    23. If SHGetFolderPath(Me.hwnd, csidl Or dwFlags, -1, SHGFP_TYPE, buff) = S_OK Then
    24. GetFolderPath = TrimNull(buff)
    25. End If
    26. End Function
    27. Private Function TrimNull(startstr As String) As String
    28. TrimNull = Left$(startstr, lstrlenW(StrPtr(startstr)))
    29. End Function

    Thanks in advance
    Last edited by BefunMunkToloGen; Mar 31st, 2005 at 02:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width