|
-
Mar 31st, 2005, 01:37 AM
#1
Thread Starter
Lively Member
[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:
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
Last edited by BefunMunkToloGen; Mar 31st, 2005 at 02:19 AM.
-
Mar 31st, 2005, 02:09 AM
#2
Re: Program Files path
Have a look at this thread: http://www.vbforums.com/showthread.php?t=219859
It talks about finding the 'My Documents' folder, but I think it is also applicable to 'Program Files'.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Mar 31st, 2005, 02:15 AM
#3
Re: Program Files path
I just had a play with the code you posted and this appears to work:
VB Code:
Option Explicit
Private Const CSIDL_PROGRAM_FILES As Long = &H26
Private Const MAX_LENGTH = 260
Private Const S_OK = 0
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 Sub Form_Load()
Dim csidl As Long
Label1.Caption = GetFolderPath(CSIDL_PROGRAM_FILES)
End Sub
Private Function GetFolderPath(SHGFP_TYPE As Long) As String
Dim buff As String
buff = Space$(MAX_LENGTH)
If SHGetFolderPath(Me.hwnd, SHGFP_TYPE, -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
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Mar 31st, 2005, 02:16 AM
#4
Thread Starter
Lively Member
Re: Program Files path
Thanks but that doesn't really help. I can get it work with lists just not message boxes or labels?
Edit: Lol you must have posted that like 2 seconds ago , ill check it out thanks
-
Mar 31st, 2005, 02:18 AM
#5
Thread Starter
Lively Member
Re: Program Files path
Beautiful! Thanks mate! Will help my programme alot
-
Mar 31st, 2005, 02:21 AM
#6
Re: [Resolved] Program Files path
No sweat. Glad to help.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|