APIを使っての特殊フォルダーのパス名の取得 |
APIを使っての特殊フォルダーのパス名の取得 (126) | |
Option Explicit 'SampleNo=126 WindowsXP VB6.0(SP5) 2002.03.29 Private Const CSIDL_ALTSTARTUP = &H1D Private Const CSIDL_APPDATA = &H1A Private Const CSIDL_BITBUCKET = &HA Private Const CSIDL_COMMON_ALTSTARTUP = &H1E Private Const CSIDL_COMMON_DESKTOPDIRECTORY = &H19 Private Const CSIDL_COMMON_FAVORITES = &H1F Private Const CSIDL_COMMON_PROGRAMS = &H17 Private Const CSIDL_COMMON_STARTMENU = &H16 Private Const CSIDL_COMMON_STARTUP = &H18 Private Const CSIDL_CONTROLS = &H3 Private Const CSIDL_COOKIES = &H21 Private Const CSIDL_DESKTOP = &H0 Private Const CSIDL_DESKTOPDIRECTORY = &H10 Private Const CSIDL_DRIVES = &H11 Private Const CSIDL_FAVORITES = &H6 Private Const CSIDL_FONTS = &H14 Private Const CSIDL_HISTORY = &H22 Private Const CSIDL_INTERNET = &H1 Private Const CSIDL_INTERNET_CACHE = &H20 Private Const CSIDL_NETHOOD = &H13 Private Const CSIDL_NETWORK = &H12 Private Const CSIDL_PERSONAL = &H5 Private Const CSIDL_PRINTERS = &H4 Private Const CSIDL_PRINTHOOD = &H1B Private Const CSIDL_PROGRAMS = &H2 Private Const CSIDL_RECENT = &H8 Private Const CSIDL_SENDTO = &H9 Private Const CSIDL_STARTMENU = &HB Private Const CSIDL_STARTUP = &H7 Private Const CSIDL_TEMPLATES = &H15 Private Const MAX_PATH = 260 '特殊フォルダーのパスを取得する(P714) Private Declare Function SHGetSpecialFolderPath Lib "SHELL32" _ Alias "SHGetSpecialFolderPathA" (ByVal hwndOwner As Long, _ ByVal lpszPath As String, ByVal nFolder As Long, _ ByVal fCreate As Long) As Long Private Sub SpecialFolder(FolderNo As Integer) Dim Result As Long Dim nFolder As Long Dim lpszPath As String 'フォルダー名を設定 (私の環境で表示したフォルダーのパス) Select Case FolderNo Case 0 nFolder = CSIDL_ALTSTARTUP Case 1 'C:\WINDOWS\Application Data nFolder = CSIDL_APPDATA Case 2 nFolder = CSIDL_BITBUCKET Case 3 nFolder = CSIDL_COMMON_ALTSTARTUP Case 4 'C:\WINDOWS\All Users\デスクトップ nFolder = CSIDL_COMMON_DESKTOPDIRECTORY Case 5 'C:\Documents and Settings\All Users\Favorites nFolder = CSIDL_COMMON_FAVORITES Case 6 'C:\Documents and Settings\All Users\ ’スタートメニュー\プログラム nFolder = CSIDL_COMMON_PROGRAMS Case 7 'C:\Documents and Settings\All Users\スタートメニュー nFolder = CSIDL_COMMON_STARTMENU Case 8 'C:\Documents and Settings\All Users\ ’スタートメニュー\プログラム\スタートアップ nFolder = CSIDL_COMMON_STARTUP Case 9 nFolder = CSIDL_CONTROLS Case 10 'C:\WINDOWS\Cookies nFolder = CSIDL_COOKIES Case 11 'C:\WINDOWS\デスクトップ nFolder = CSIDL_DESKTOP Case 12 'C:\WINDOWS\デスクトップ nFolder = CSIDL_DESKTOPDIRECTORY Case 13 nFolder = CSIDL_DRIVES Case 14 'C:\WINDOWS\Favorites nFolder = CSIDL_FAVORITES Case 15 'C:\WINDOWS\FONTS nFolder = CSIDL_FONTS Case 16 'C:\WINDOWS\History nFolder = CSIDL_HISTORY Case 17 nFolder = CSIDL_INTERNET Case 18 'C:\WINDOWS\Temporary Internet Files nFolder = CSIDL_INTERNET_CACHE Case 19 'C:\WINDOWS\NetHood nFolder = CSIDL_NETHOOD Case 20 nFolder = CSIDL_NETWORK Case 21 'C:\My Documents nFolder = CSIDL_PERSONAL Case 22 nFolder = CSIDL_PRINTERS Case 23 'C:\WINDOWS\PrintHood nFolder = CSIDL_PRINTHOOD Case 24 'C:\WINDOWS\スタート メニュー\プログラム nFolder = CSIDL_PROGRAMS Case 25 'C:\WINDOWS\Recent nFolder = CSIDL_RECENT Case 26 'C:\WINDOWS\SendTo nFolder = CSIDL_SENDTO Case 27 'C:\WINDOWS\スタート メニュー nFolder = CSIDL_STARTMENU Case 28 'C:\WINDOWS\スタート メニュー\プログラム\スタートアップ nFolder = CSIDL_STARTUP Case 29 'C:\WINDOWS\ShellNew nFolder = CSIDL_TEMPLATES End Select 'パス名を受け取るバッファーを確保 lpszPath = String$(MAX_PATH, vbNullChar) '関数の実行 Result = SHGetSpecialFolderPath(Me.hWnd, lpszPath, nFolder, 0) 'フォルダー名の取得 Text1.Text = Left$(lpszPath, InStr(lpszPath, vbNullChar) - 1) End Sub Private Sub Form_Load() List1.AddItem " CSIDL_ALTSTARTUP" List1.AddItem " CSIDL_APPDATA" List1.AddItem " CSIDL_BITBUCKET" List1.AddItem " CSIDL_COMMON_ALTSTARTUP" List1.AddItem " CSIDL_COMMON_DESKTOPDIRECTORY" List1.AddItem " CSIDL_COMMON_FAVORITES" List1.AddItem " CSIDL_COMMON_PROGRAMS" List1.AddItem " CSIDL_COMMON_STARTMENU" List1.AddItem " CSIDL_COMMON_STARTUP" List1.AddItem " CSIDL_CONTROLS" List1.AddItem " CSIDL_COOKIES" List1.AddItem " CSIDL_DESKTOP" List1.AddItem " CSIDL_DESKTOPDIRECTORY" List1.AddItem " CSIDL_DRIVES" List1.AddItem " CSIDL_FAVORITES" List1.AddItem " CSIDL_FONTS" List1.AddItem " CSIDL_HISTORY" List1.AddItem " CSIDL_INTERNET" List1.AddItem " CSIDL_INTERNET_CACHE" List1.AddItem " CSIDL_NETHOOD" List1.AddItem " CSIDL_NETWORK" List1.AddItem " CSIDL_PERSONAL" List1.AddItem " CSIDL_PRINTERS" List1.AddItem " CSIDL_PRINTHOOD" List1.AddItem " CSIDL_PROGRAMS" List1.AddItem " CSIDL_RECENT" List1.AddItem " CSIDL_SENDTO" List1.AddItem " CSIDL_STARTMENU" List1.AddItem " CSIDL_STARTUP" List1.AddItem " CSIDL_TEMPLATES" End Sub Private Sub List1_Click() SpecialFolder CLng(List1.ListIndex) End Sub |
2002/03/29