vb获得系统时间:如何用VB获得Windows各类系统目录来源: 发布时间:星期五, 2008年12月26日 浏览:221次 评论:0
现在有很多有关如何用VB获得Windows目录
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 先向大家介绍两个API ![]() ![]() ![]() ![]() ![]() ![]() ![]() Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long ![]() SHGetSpecialFolderLocation:获得某个特殊目录在特殊目录列表中 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() &H0& '桌面 &H2& ' ![]() &H5& '我 ![]() &H6& '收藏夹 &H7& '启动 &H8& '最近打开 ![]() &H9& '发送 &HB& '开始菜单 &H13& '网上邻居 &H14& '字体 &H15& 'ShellNew &H1A& 'Application Data &H1B& 'Pr ![]() &H20& '网页临时文件 &H21& 'Cookies目录 &H22& '历史 第 3个参数是获得 ![]() ![]() ![]() SHGetPathFromIDList:根据某特殊目录在特殊目录列表中 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 比如:为了获得DeskTop ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 下面是我编写 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Private Declare Function Get ![]() ![]() Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long Const MAX_LEN = 200 ' ![]() Const DESKTOP = &H0& '桌面 Const PROGRAMS = &H2& ' ![]() Const MYDOCUMENTS = &H5& '我 ![]() Const MYFAVORITES = &H6& '收藏夹 Const STARTUP = &H7& '启动 Const RECENT = &H8& '最近打开 ![]() Const SENDTO = &H9& '发送 Const STARTMENU = &HB& '开始菜单 Const NETHOOD = &H13& '网上邻居 Const FONTS = &H14& '字体 Const SHELLNEW = &H15& 'ShellNew Const APPDATA = &H1A& 'Application Data Const PRINTHOOD = &H1B& 'Pr ![]() Const PAGETMP = &H20& '网页临时文件 Const COOKIES = &H21& 'Cookies目录 Const HISTORY = &H22& '历史 Private Sub Command2_Click ![]() End End Sub Private Sub Form_Load ![]() Dim sTmp As String * MAX_LEN '存放结果 ![]() ![]() ![]() Dim nLength As Long ' ![]() ![]() Dim pidl As Long '某特殊目录在特殊目录列表中 ![]() '*************************获得Windows目录********************************** Length = GetWindowsDirectory(sTmp, MAX_LEN) txtWin.Text = Left(sTmp, Length) '*************************获得 ![]() Length = Get ![]() txt ![]() '*************************获得Temp目录*********************************** Length = GetTempPath(MAX_LEN, sTmp) txtTemp.Text = Left(sTmp, Length) '*************************获得DeskTop目录********************************** SHGetSpecialFolderLocation 0, DESKTOP, pidl SHGetPathFromIDList pidl, sTmp txtDesktop.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得发送到目录********************************** SHGetSpecialFolderLocation 0, SENDTO, pidl SHGetPathFromIDList pidl, sTmp txtSendTo.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得我 ![]() SHGetSpecialFolderLocation 0, MYDOCUMENTS, pidl SHGetPathFromIDList pidl, sTmp txtDocument.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得 ![]() SHGetSpecialFolderLocation 0, PROGRAMS, pidl SHGetPathFromIDList pidl, sTmp txtProgram.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得启动目录************************************* SHGetSpecialFolderLocation 0, STARTUP, pidl SHGetPathFromIDList pidl, sTmp txtStart.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得开始菜单目录********************************* SHGetSpecialFolderLocation 0, STARTMENU, pidl SHGetPathFromIDList pidl, sTmp txtStartMenu.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得收藏夹目录*********************************** SHGetSpecialFolderLocation 0, MYFAVORITES, pidl SHGetPathFromIDList pidl, sTmp txtFavorites.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '**********************获得最后打开 ![]() SHGetSpecialFolderLocation 0, RECENT, pidl SHGetPathFromIDList pidl, sTmp txtRecent.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得网上邻居目录********************************* SHGetSpecialFolderLocation 0, NETHOOD, pidl SHGetPathFromIDList pidl, sTmp txtNetHood.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得字体目录********************************** SHGetSpecialFolderLocation 0, FONTS, pidl SHGetPathFromIDList pidl, sTmp txtFonts.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得Cookies目录********************************** SHGetSpecialFolderLocation 0, COOKIES, pidl SHGetPathFromIDList pidl, sTmp txtCookies.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得历史目录********************************** SHGetSpecialFolderLocation 0, HISTORY, pidl SHGetPathFromIDList pidl, sTmp txtHistory.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '***********************获得网页临时文件目录******************************* SHGetSpecialFolderLocation 0, PAGETMP, pidl SHGetPathFromIDList pidl, sTmp txtPageTmp.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得ShellNew目录********************************* SHGetSpecialFolderLocation 0, SHELLNEW, pidl SHGetPathFromIDList pidl, sTmp txtShellNew.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '***********************获得Application Data目录***************************** SHGetSpecialFolderLocation 0, APPDATA, pidl SHGetPathFromIDList pidl, sTmp txtAppData.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1) '*************************获得Pr ![]() SHGetSpecialFolderLocation 0, PRINTHOOD, pidl SHGetPathFromIDList pidl, sTmp txtPr ![]() End Sub 0
相关文章
读者评论发表评论 |