Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1463

Code Snippet: Getting folder settings with SHGetSettings

$
0
0
So there's not a single result for SHGetSettings, and this is an odd function, so I just wanted to post a working method of using it. SHGetSetSettings isn't supported above XP, so even if it's still working you might want to use this function.

The way you'd think to use it would be using the structure SHELLFLAGSTATE, but whether ByRef or VarPtr, that doesn't seem to work. Apparently it's a bitfield, and you can pass it an Integer. The Mask can be passed as normal.

Code:

Public Declare Function SHGetSettings Lib "shell32" (lpsfs As Integer, ByVal dwMask As SFS_MASK) As Long

Public Enum SFS_MASK
    SSF_SHOWALLOBJECTS = &H1
    SSF_SHOWEXTENSIONS = &H2
    SSF_SHOWCOMPCOLOR = &H8
    SSF_SHOWSYSFILES = &H20
    SSF_DOUBLECLICKINWEBVIEW = &H80
    SSF_SHOWATTRIBCOL = &H100
    SSF_DESKTOPHTML = &H200
    SSF_WIN95CLASSIC = &H400
    SSF_DONTPRETTYPATH = &H800
    SSF_SHOWINFOTIP = &H2000
    SSF_MAPNETDRVBUTTON = &H1000
    SSF_NOCONFIRMRECYCLE = &H8000
    SSF_HIDEICONS = &H4000
End Enum

The structure that's supposed to be returned looks like this:
Code:

Public Type SHELLFLAGSTATE
  fShowAllObjects  As Boolean
  fShowExtensions  As Boolean
  fNoConfirmRecycle  As Boolean
  fShowSysFiles  As Boolean
  fShowCompColor  As Boolean
  fDoubleClickInWebView  As Boolean
  fDesktopHTML  As Boolean
  fWin95Classic  As Boolean
  fDontPrettyPath  As Boolean
  fShowAttribCol  As Boolean
  fMapNetDrvBtn  As Boolean
  fShowInfoTip  As Boolean
  fHideIcons  As Boolean
  fAutoCheckSelect  As Boolean
  fIconsOnly  As Boolean
  fRestFlags  As Long
End Type

Instead, we're not going to use that structure at all, but its members represent bits (and fRestFlags isn't used for anything), so their order matters. fShowAllObjects is 2^0, fShowExtensions is 2^1, etc.

Code:

Public Function ExplorerSettingEnabled(lSetting As SFS_MASK) As Boolean
Dim lintg As Integer
Call SHGetSettings(lintg, lSetting)
Select Case lSetting
    Case SSF_SHOWALLOBJECTS
        ExplorerSettingEnabled = lintg And 2 ^ 0 'fShowAllObjects
    Case SSF_SHOWEXTENSIONS
        ExplorerSettingEnabled = lintg And 2 ^ 1 'fShowExtensions
    Case SSF_NOCONFIRMRECYCLE
        ExplorerSettingEnabled = lintg And 2 ^ 2 'fNoConfirmRecycle
    Case SSF_SHOWSYSFILES
        ExplorerSettingEnabled = lintg And 2 ^ 3 'fShowSysFiles
    Case SSF_SHOWCOMPCOLOR
        ExplorerSettingEnabled = lintg And 2 ^ 4 'fShowCompColor
    Case SSF_DOUBLECLICKINWEBVIEW
        ExplorerSettingEnabled = lintg And 2 ^ 5 'fDoubleClickInWebView
    Case SSF_DESKTOPHTML
        ExplorerSettingEnabled = lintg And 2 ^ 6 'fDesktopHTML
    Case SSF_WIN95CLASSIC
        ExplorerSettingEnabled = lintg And 2 ^ 7 'fWin95Classic
    Case SSF_DONTPRETTYPATH
        ExplorerSettingEnabled = lintg And 2 ^ 8 'fDontPrettyPath
    Case SSF_SHOWATTRIBCOL
        ExplorerSettingEnabled = lintg And 2 ^ 9 'fShowAttribCol
    Case SSF_MAPNETDRVBUTTON
        ExplorerSettingEnabled = lintg And 2 ^ 10 'fMapNetDrvButton
    Case SSF_SHOWINFOTIP
        ExplorerSettingEnabled = lintg And 2 ^ 11 'fShowInfoTip
    Case SSF_HIDEICONS
        ExplorerSettingEnabled = lintg And 2 ^ 12 'fHideIcons
   
End Select
End Function


Viewing all articles
Browse latest Browse all 1463

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>