网上搜索到一个帖子,说了方法,但我执行的时候没反应,希望大哥大姐帮助看下,谢谢~~
form中代码如下:
Private Const SW_SHOWNORMAL = 1
Private Const CSIDL_SENDTO = &H9 '{user name}\SendTo
Private Const CSIDL_BITBUCKET = &HA '{desktop}\Recycle Bin
Private Const CSIDL_STARTMENU = &HB '{user name}\Start Menu
Private Const CSIDL_DESKTOPDIRECTORY = &H10 '{user name}\Desktop
Private Const CSIDL_DRIVES = &H11 'My Computer
Private Const CSIDL_NETWORK = &H12 'Network Neighborhood
Private Const CSIDL_WINDOWS = &H24 'GetWindowsDirectory()
Private Const CSIDL_SYSTEM = &H25 'GetSystemDirectory()
Private Const CSIDL_PROGRAM_FILES = &H26 'C:\Program FilesPrivate Const MAX_PATH = 260
Private Const S_OK = 0Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As LongPrivate Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As LongPrivate Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)Private Function GetSpecialFolderLocation(CSIDL As Long) As String
Dim sPath As String
Dim pidl As Long
'fill the idl structure with the specified folder itemIf SHGetSpecialFolderLocation(0, CSIDL, pidl) = S_OK Then'if the pidl is returned, initialize
'and get the path from the id list
sPath = Space$(MAX_PATH)
'Msgbox sPathIf SHGetPathFromIDList(pidl, sPath) Then
Msgbox SHGetPathFromIDList(pidl, sPath)
'return the path
GetSpecialFolderLocation = Left(sPath, InStr(sPath, Chr$(0)) - 1)
End If
'free the pidl
Call CoTaskMemFree(pidl)
End If
End Function调用例子:打开我的电脑的
Private Sub xpcmdbutton10_Click()
'ShellExecute Me.hwnd, "open", vbNull, vbNull, GetSpecialFolderLocation(CSIDL_DRIVES), SW_SHOWNORMAL
'ShellExecute Me.hwnd, "Open", "explorer.exe", "/e,\", "C:\", SW_NORMAL
Dim str As String
str = GetSpecialFolderLocation(CSIDL_DRIVES)
ShellExecute Me.hwnd, "open", vbNull, vbNull, str, SW_SHOWNORMAL
'ShellExecute 0, "explore", "", "", GetSpecialFolderLocation(CSIDL_DRIVES),SW_SHOWNORMAL
End Sub点击按钮执行时,GetSpecialFolderLocation中取的sPath 为空,请指点,谢谢~~
form中代码如下:
Private Const SW_SHOWNORMAL = 1
Private Const CSIDL_SENDTO = &H9 '{user name}\SendTo
Private Const CSIDL_BITBUCKET = &HA '{desktop}\Recycle Bin
Private Const CSIDL_STARTMENU = &HB '{user name}\Start Menu
Private Const CSIDL_DESKTOPDIRECTORY = &H10 '{user name}\Desktop
Private Const CSIDL_DRIVES = &H11 'My Computer
Private Const CSIDL_NETWORK = &H12 'Network Neighborhood
Private Const CSIDL_WINDOWS = &H24 'GetWindowsDirectory()
Private Const CSIDL_SYSTEM = &H25 'GetSystemDirectory()
Private Const CSIDL_PROGRAM_FILES = &H26 'C:\Program FilesPrivate Const MAX_PATH = 260
Private Const S_OK = 0Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As LongPrivate Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As LongPrivate Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)Private Function GetSpecialFolderLocation(CSIDL As Long) As String
Dim sPath As String
Dim pidl As Long
'fill the idl structure with the specified folder itemIf SHGetSpecialFolderLocation(0, CSIDL, pidl) = S_OK Then'if the pidl is returned, initialize
'and get the path from the id list
sPath = Space$(MAX_PATH)
'Msgbox sPathIf SHGetPathFromIDList(pidl, sPath) Then
Msgbox SHGetPathFromIDList(pidl, sPath)
'return the path
GetSpecialFolderLocation = Left(sPath, InStr(sPath, Chr$(0)) - 1)
End If
'free the pidl
Call CoTaskMemFree(pidl)
End If
End Function调用例子:打开我的电脑的
Private Sub xpcmdbutton10_Click()
'ShellExecute Me.hwnd, "open", vbNull, vbNull, GetSpecialFolderLocation(CSIDL_DRIVES), SW_SHOWNORMAL
'ShellExecute Me.hwnd, "Open", "explorer.exe", "/e,\", "C:\", SW_NORMAL
Dim str As String
str = GetSpecialFolderLocation(CSIDL_DRIVES)
ShellExecute Me.hwnd, "open", vbNull, vbNull, str, SW_SHOWNORMAL
'ShellExecute 0, "explore", "", "", GetSpecialFolderLocation(CSIDL_DRIVES),SW_SHOWNORMAL
End Sub点击按钮执行时,GetSpecialFolderLocation中取的sPath 为空,请指点,谢谢~~
是打开资源管理器,相当于我的电脑了吧,有知道打开我的文档,我的IE什么的怎么写吗?
ShellExecute Me.hWnd, "open", "explorer", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", vbNullString, SW_SHOWNORMAL
我的电脑
ShellExecute Me.hWnd, "open", "explorer", vbNullString, vbNullString, SW_SHOWNORMAL
我的文档
ShellExecute Me.hWnd, "open", "explorer", "::{208D2C60-3AEA-1069-A2D7-08002B30309D}", vbNullString, SW_SHOWNORMAL
网上邻居
ShellExecute Me.hWnd, "open", "explorer", "::{645FF040-5081-101B-9F08-00AA002F954E}", vbNullString, SW_SHOWNORMAL
回收站
ShellExecute Me.hWnd, "open", "iexplore.exe", vbNullString, vbNullString, SW_SHOWNORMAL
IE
ShellExecute Me.hWnd, "open", App.Path + "\Resources\help.chm", vbNullString, vbNullString, SW_SHOWNORMAL
应用程序路径下的帮助文件,呵呵~~