Organize Favorites : Favorites Dialog « Windows « VB.Net Tutorial






Organize Favorites
Imports System.Runtime.InteropServices


public class OrganizeFavorites
    Public Shared Sub Main

        Dim lpszRootFolder As String
        Dim lpszPath As String
        Dim dwReturn As Integer
    
        dwReturn = SHGetFolderPath(0, CSIDL_FAVORITES, 0, &H0S, lpszPath)
    
        If dwReturn = 0 Then
          lpszRootFolder = lpszPath.Substring(0, lpszPath.IndexOf(vbNullChar))
        End If
    
        DoOrganizeFavDlg(0, lpszRootFolder)

    
    End Sub

End Class



Module Module1
  Public Const CSIDL_PROGRAMS As Short = &H2S
  ' My Documents
  Public Const CSIDL_PERSONAL As Short = &H5S
  Public Const CSIDL_FAVORITES As Short = &H6S
  Public Const CSIDL_STARTUP As Short = &H7S
  Public Const CSIDL_STARTMENU As Short = &HBS
  Public Const CSIDL_DESKTOPDIRECTORY As Short = &H10S
  ' {Windows}\ShellNew
  Public Const CSIDL_TEMPLATES As Short = &H15S
  Public Const CSIDL_COMMON_STARTMENU As Short = &H16S
  Public Const CSIDL_COMMON_PROGRAMS As Short = &H17S
  Public Const CSIDL_COMMON_STARTUP As Short = &H18S
  Public Const CSIDL_COMMON_DESKTOPDIRECTORY As Short = &H19S
  Public Const CSIDL_APPDATA As Short = &H1AS
  Public Const CSIDL_COMMON_FAVORITES As Short = &H1FS
  ' All Users\Application Data Windows NT
  Public Const CSIDL_COMMON_APPDATA As Short = &H23S

  ' nShowCmd
  Public Const SW_HIDE As Short = 0
  Public Const SW_SHOWNORMAL As Short = 1
  Public Const SW_SHOWMINIMIZED As Short = 2
  Public Const SW_SHOWMAXIMIZED As Short = 3
  Public Const SW_MAXIMIZE As Short = 3
  Public Const SW_SHOWNOACTIVATE As Short = 4
  Public Const SW_SHOW As Short = 5
  Public Const SW_MINIMIZE As Short = 6
  Public Const SW_SHOWMINNOACTIVE As Short = 7
  Public Const SW_SHOWNA As Short = 8
  Public Const SW_RESTORE As Short = 9

  ' Error Code
  Public Const ERROR_FILE_NOT_FOUND As Short = 2
  Public Const ERROR_PATH_NOT_FOUND As Short = 3
  Public Const ERROR_BAD_FORMAT As Short = 11

  Public Const SE_ERR_FNF As Short = 2
  Public Const SE_ERR_PNF As Short = 3
  Public Const SE_ERR_ACCESSDENIED As Short = 5
  Public Const SE_ERR_OOM As Short = 8
  Public Const SE_ERR_SHARE As Short = 26
  Public Const SE_ERR_ASSOCINCOMPLETE As Short = 27
  Public Const SE_ERR_DDETIMEOUT As Short = 28
  Public Const SE_ERR_DDEFAIL As Short = 29
  Public Const SE_ERR_DDEBUSY As Short = 30
  Public Const SE_ERR_NOASSOC As Short = 31
  Public Const SE_ERR_DLLNOTFOUND As Short = 32

  Public Declare Function DoOrganizeFavDlg Lib "shdocvw.dll" (ByVal hWnd As Integer, ByVal lpszRootFolder As String) As Integer

  Public Declare Function SHGetFolderPath Lib "shfolder.dll" Alias "SHGetFolderPathA" (ByVal hwndOwner As Integer, ByVal nFolder As Integer, ByVal hToken As Integer, ByVal dwReserved As Integer, ByVal lpszPath As String) As Integer
End Module








24.13.Favorites Dialog
24.13.1.'Add to Favorites' dialog
24.13.2.Organize FavoritesOrganize Favorites