Code : Tout sélectionner
Structure SHELLSTATE Align #PB_Structure_AlignC
Data1.l ; fShowAllObjects (1 bit) ; TRUE to show all objects, including hidden files and folders. FALSE to hide hidden files and folders
; ShowExtensions (1 bit) ; TRUE to show file name extensions, FALSE to hide them.
; NoConfirmRecycle (1 bit) ; TRUE to show no confirmation dialog box when deleting items to the Recycle Bin, FALSE to display the confirmation dialog box.
; fShowSysFiles (1 bit) ; TRUE to show system files, FALSE to hide them.
; fShowCompColor (1 bit) ; TRUE to show encrypted or compressed NTFS files in color.
; fDoubleClickInWebView (1 bit) ; TRUE to require a double-click to open an item when in web view.
; fDesktopHTML (1 bit) ; TRUE to use Active Desktop, FALSE otherwise.
; fWin95Classic (1 bit) ; TRUE to enforce Windows 95 Shell behavior and restrictions.
; fDontPrettyPath (1 bit) ; TRUE to prevent the conversion of the path to all lowercase characters.
; fShowAttribCol (1 bit) ; 0 ou 1
; fMapNetDrvBtn (1 bit) ; TRUE to display a Map Network Drive button.
; fShowInfoTip (1 bit) ; TRUE to show a pop-up description for folders and files.
; fHideIcons (1 bit) ; TRUE to hide desktop icons, FALSE to show them.
; fWebView (1 bit) ; TRUE to display as a web view.
; fFilter (1 bit) ; Not used.
; fShowSuperHidden (1 bit) ; TRUE to show operating system files.
; fNoNetCrawling (1 bit) ; TRUE to disable automatic searching for network folders and printers
dwWin95Unused.l ; Not used.
uWin95Unused.l ; Not used.
lParamSort.l ; The column to sort by.
iSortDirection.l ; Alphabetical sort direction for the column specified by lParamSort. Use 1 for an ascending sort, -1 for a descending sort.
version.l ; Not used.
uNotUsed.l ; Not used.
SData2.l ; fSepProcess (1 bit) ; TRUE to launch folder windows in separate processes, FALSE to launch in the same process.
; fStartPanelOn (1 bit) ; Windows XP only. TRUE To use the Windows XP-style Start menu, FALSE To use the classic Start menu.
; fShowStartPage (1 bit) ; Not used.
; fAutoCheckSelect (1 bit) ; Introduced in Windows Vista. TRUE to use the Windows Vista-style checkbox folder views, FALSE to use the classic views.
; fIconsOnly (1 bit) ; 0 ou 1
; fShowTypeOverlay (1 bit) ; 0 ou 1
; fShowStatusBar (1 bit) ; Introduced in Windows 8. TRUE to show the status bar; otherwise, FALSE.
; fSpareFlags (9 bit) ; Not used.
EndStructure
#SSF_SHOWALLOBJECTS = $00000001 ; The fShowAllObjects member is being requested.
#SSF_SHOWEXTENSIONS = $00000002 ; The fShowExtensions member is being requested.
#SSF_HIDDENFILEEXTS = $00000004 ; Not used.
#SSF_SERVERADMINUI = $00000004 ; Not used.
#SSF_SHOWCOMPCOLOR = $00000008 ; The fShowCompColor member is being requested.
#SSF_SORTCOLUMNS = $00000010 ; The lParamSort And iSortDirection members are being requested.
#SSF_SHOWSYSFILES = $00000020 ; The fShowSysFiles member is being requested.
#SSF_DOUBLECLICKINWEBVIEW = $00000080 ; The fDoubleClickInWebView member is being requested.
#SSF_SHOWATTRIBCOL = $00000100 ; The fShowAttribCol member is being requested. Windows Vista: Not used.
#SSF_DESKTOPHTML = $00000200 ; The fDesktopHTML member is being requested. Set is Not available. Instead, For versions of Windows prior To Windows XP, enable desktop HTML by IActiveDesktop. The use of IActiveDesktop For this purpose, however, is Not recommended For Windows XP And later versions of Windows, And is deprecated in Windows Vista.
#SSF_WIN95CLASSIC = $00000400 ; The fWin95Classic member is being requested.
#SSF_DONTPRETTYPATH = $00000800 ; The fDontPrettyPath member is being requested.
#SSF_MAPNETDRVBUTTON = $00001000 ; The fMapNetDrvBtn member is being requested.
#SSF_SHOWINFOTIP = $00002000 ; The fShowInfoTip member is being requested.
#SSF_HIDEICONS = $00004000 ; The fHideIcons member is being requested.
#SSF_NOCONFIRMRECYCLE = $00008000 ; The fNoConfirmRecycle member is being requested.
#SSF_FILTER = $00010000 ; The fFilter member is being requested. Windows Vista: Not used.
#SSF_WEBVIEW = $00020000 ; The fWebView member is being requested.
#SSF_SHOWSUPERHIDDEN = $00040000 ; The fShowSuperHidden member is being requested.
#SSF_SEPPROCESS = $00080000 ; The fSepProcess member is being requested.
#SSF_NONETCRAWLING = $00100000 ; Windows XP And later. The fNoNetCrawling member is being requested.
#SSF_STARTPANELON = $00200000 ; Windows XP And later. The fStartPanelOn member is being requested.
#SSF_SHOWSTARTPAGE = $00400000 ; Not used.
#SSF_AUTOCHECKSELECT = $00800000 ; Windows Vista And later. The fAutoCheckSelect member is being requested.
#SSF_ICONSONLY = $01000000 ; Windows Vista And later. The fIconsOnly member is being requested.
#SSF_SHOWTYPEOVERLAY = $02000000 ; Windows Vista And later. The fShowTypeOverlay member is being requested.
#SSF_SHOWSTATUSBAR = $04000000 ; Windows 8 And later: The fShowStatusBar member is being requested.
; Constante créée pour notre utilisation
#Get_Shell_Settings = 0
#Set_Shell_Settings = 1
Global HdesktopIcons.i
Procedure.l IsDesktopIconsHide()
Protected SHELLSTATE.SHELLSTATE
Protected Resultat.l
SHGetSetSettings_(@SHELLSTATE.SHELLSTATE, #SSF_HIDEICONS, #Get_Shell_Settings)
Resultat = SHELLSTATE\Data1 & 4096 ; %0000000000000000001000000000000
If Resultat = 0
ProcedureReturn 0
Else
ProcedureReturn 1
EndIf
EndProcedure
ExamineDesktops()
Structure Desktop
HSHELLDLL_DefView.i
HLevelparent.i
EndStructure
Procedure.l EnumProc(hWnd.i, *lParam.Desktop)
Protected ParentRootClass.s, ClassName.s
Protected Title.s, Rect.RECT, hancestror.i
ClassName = Space(1024)
GetClassName_(hWnd, @ClassName, 1024)
If LCase(ClassName) = LCase("SHELLDLL_DefView")
hancestror.i = GetAncestor_(hWnd, #GA_ROOTOWNER)
If hancestror <> hwnd
ParentRootClass = Space(1024)
GetClassName_(hancestror, @ParentRootClass, 1024)
If LCase(ParentRootClass) = LCase("Progman") Or LCase(ParentRootClass) = LCase("WorkerW")
GetClientRect_(hancestror, @Rect.RECT)
If DesktopWidth(0) = Rect\right
If DesktopHeight(0) = Rect\bottom
*lParam\HSHELLDLL_DefView = hwnd
*lParam\HLevelparent = hancestror
ProcedureReturn #False
EndIf
EndIf
EndIf
EndIf
EndIf
ProcedureReturn #True
EndProcedure
hWnd = GetDesktopWindow_()
If hWnd <> 0
EnumChildWindows_(hWnd, @EnumProc(), @Hdesktop.Desktop)
EndIf
Procedure WinCallback(hWnd, uMsg, WParam, LParam)
Debug uMsg
Select uMsg
Case #WM_SETTINGCHANGE
Debug "#WM_SETTINGCHANGE"
If IsDesktopIconsHide() = 0
SetGadgetText(0, "Cacher les icônes")
Else
SetGadgetText(0, "Afficher les icônes")
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(0, 200, 200, 200, 200, "PureBasic Window", #PB_Window_SystemMenu)
SetWindowCallback(@WinCallback(), 0)
ButtonGadget(0, 30, 50, 140, 40, "Toggle Icons Desktop")
If Hdesktop\HSHELLDLL_DefView = 0
DisableGadget(0, 1)
Else
If IsDesktopIconsHide() = 0
SetGadgetText(0, "Cacher les icônes")
Else
SetGadgetText(0, "Afficher les icônes")
EndIf
EndIf
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
SendMessageTimeout_(Hdesktop\HSHELLDLL_DefView, #WM_COMMAND, 29698, 0, #SMTO_ABORTIFHUNG, 1000, @Result)
If IsDesktopIconsHide() = 0
SetGadgetText(0, "Cacher les icônes")
Else
SetGadgetText(0, "Afficher les icônes")
EndIf
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf
End
Une deuxième méthode, la fenêtre que l'on recherche est toujours vers la fin de la liste, donc là on commence la recherche par la fin, si on trouve une classe SHELLDLL_DefView, on vérifie les dimensions et si c'est bon, on s'arrête, pas de contrôle sur le parent mais on le récupère pour pouvoir épingler des fenêtres.
Code : Tout sélectionner
Structure SHELLSTATE Align #PB_Structure_AlignC
Data1.l ; fShowAllObjects (1 bit) ; TRUE to show all objects, including hidden files and folders. FALSE to hide hidden files and folders
; ShowExtensions (1 bit) ; TRUE to show file name extensions, FALSE to hide them.
; NoConfirmRecycle (1 bit) ; TRUE to show no confirmation dialog box when deleting items to the Recycle Bin, FALSE to display the confirmation dialog box.
; fShowSysFiles (1 bit) ; TRUE to show system files, FALSE to hide them.
; fShowCompColor (1 bit) ; TRUE to show encrypted or compressed NTFS files in color.
; fDoubleClickInWebView (1 bit) ; TRUE to require a double-click to open an item when in web view.
; fDesktopHTML (1 bit) ; TRUE to use Active Desktop, FALSE otherwise.
; fWin95Classic (1 bit) ; TRUE to enforce Windows 95 Shell behavior and restrictions.
; fDontPrettyPath (1 bit) ; TRUE to prevent the conversion of the path to all lowercase characters.
; fShowAttribCol (1 bit) ; 0 ou 1
; fMapNetDrvBtn (1 bit) ; TRUE to display a Map Network Drive button.
; fShowInfoTip (1 bit) ; TRUE to show a pop-up description for folders and files.
; fHideIcons (1 bit) ; TRUE to hide desktop icons, FALSE to show them.
; fWebView (1 bit) ; TRUE to display as a web view.
; fFilter (1 bit) ; Not used.
; fShowSuperHidden (1 bit) ; TRUE to show operating system files.
; fNoNetCrawling (1 bit) ; TRUE to disable automatic searching for network folders and printers
dwWin95Unused.l ; Not used.
uWin95Unused.l ; Not used.
lParamSort.l ; The column to sort by.
iSortDirection.l ; Alphabetical sort direction for the column specified by lParamSort. Use 1 for an ascending sort, -1 for a descending sort.
version.l ; Not used.
uNotUsed.l ; Not used.
SData2.l ; fSepProcess (1 bit) ; TRUE to launch folder windows in separate processes, FALSE to launch in the same process.
; fStartPanelOn (1 bit) ; Windows XP only. TRUE To use the Windows XP-style Start menu, FALSE To use the classic Start menu.
; fShowStartPage (1 bit) ; Not used.
; fAutoCheckSelect (1 bit) ; Introduced in Windows Vista. TRUE to use the Windows Vista-style checkbox folder views, FALSE to use the classic views.
; fIconsOnly (1 bit) ; 0 ou 1
; fShowTypeOverlay (1 bit) ; 0 ou 1
; fShowStatusBar (1 bit) ; Introduced in Windows 8. TRUE to show the status bar; otherwise, FALSE.
; fSpareFlags (9 bit) ; Not used.
EndStructure
#SSF_SHOWALLOBJECTS = $00000001 ; The fShowAllObjects member is being requested.
#SSF_SHOWEXTENSIONS = $00000002 ; The fShowExtensions member is being requested.
#SSF_HIDDENFILEEXTS = $00000004 ; Not used.
#SSF_SERVERADMINUI = $00000004 ; Not used.
#SSF_SHOWCOMPCOLOR = $00000008 ; The fShowCompColor member is being requested.
#SSF_SORTCOLUMNS = $00000010 ; The lParamSort And iSortDirection members are being requested.
#SSF_SHOWSYSFILES = $00000020 ; The fShowSysFiles member is being requested.
#SSF_DOUBLECLICKINWEBVIEW = $00000080 ; The fDoubleClickInWebView member is being requested.
#SSF_SHOWATTRIBCOL = $00000100 ; The fShowAttribCol member is being requested. Windows Vista: Not used.
#SSF_DESKTOPHTML = $00000200 ; The fDesktopHTML member is being requested. Set is Not available. Instead, For versions of Windows prior To Windows XP, enable desktop HTML by IActiveDesktop. The use of IActiveDesktop For this purpose, however, is Not recommended For Windows XP And later versions of Windows, And is deprecated in Windows Vista.
#SSF_WIN95CLASSIC = $00000400 ; The fWin95Classic member is being requested.
#SSF_DONTPRETTYPATH = $00000800 ; The fDontPrettyPath member is being requested.
#SSF_MAPNETDRVBUTTON = $00001000 ; The fMapNetDrvBtn member is being requested.
#SSF_SHOWINFOTIP = $00002000 ; The fShowInfoTip member is being requested.
#SSF_HIDEICONS = $00004000 ; The fHideIcons member is being requested.
#SSF_NOCONFIRMRECYCLE = $00008000 ; The fNoConfirmRecycle member is being requested.
#SSF_FILTER = $00010000 ; The fFilter member is being requested. Windows Vista: Not used.
#SSF_WEBVIEW = $00020000 ; The fWebView member is being requested.
#SSF_SHOWSUPERHIDDEN = $00040000 ; The fShowSuperHidden member is being requested.
#SSF_SEPPROCESS = $00080000 ; The fSepProcess member is being requested.
#SSF_NONETCRAWLING = $00100000 ; Windows XP And later. The fNoNetCrawling member is being requested.
#SSF_STARTPANELON = $00200000 ; Windows XP And later. The fStartPanelOn member is being requested.
#SSF_SHOWSTARTPAGE = $00400000 ; Not used.
#SSF_AUTOCHECKSELECT = $00800000 ; Windows Vista And later. The fAutoCheckSelect member is being requested.
#SSF_ICONSONLY = $01000000 ; Windows Vista And later. The fIconsOnly member is being requested.
#SSF_SHOWTYPEOVERLAY = $02000000 ; Windows Vista And later. The fShowTypeOverlay member is being requested.
#SSF_SHOWSTATUSBAR = $04000000 ; Windows 8 And later: The fShowStatusBar member is being requested.
; Constante créée pour notre utilisation
#Get_Shell_Settings = 0
#Set_Shell_Settings = 1
ExamineDesktops()
Structure Desktop
HSHELLDLL_DefView.i
HLevelparent.i
EndStructure
Global Dim Hshellview.i(100)
Global EnumDesktop.Desktop
Procedure.l IsDesktopIconsHide()
Protected SHELLSTATE.SHELLSTATE
Protected Resultat.l
SHGetSetSettings_(@SHELLSTATE.SHELLSTATE, #SSF_HIDEICONS, #Get_Shell_Settings)
Resultat = SHELLSTATE\Data1 & 4096 ; %0000000000000000001000000000000
If Resultat = 0
ProcedureReturn 0
Else
ProcedureReturn 1
EndIf
EndProcedure
Procedure.l EnumProc(hWnd.i, *lParam.long)
Protected ClassName.s
Static a
If *lParam\l = -2
*lParam\l = -1
a = 0
EndIf
ClassName = Space(1024)
GetClassName_(hWnd, @ClassName, 1024)
If LCase(ClassName) = LCase("SHELLDLL_DefView")
Hshellview(a) = hwnd
*lParam\l = a
a = a +1
EndIf
ProcedureReturn #True
EndProcedure
Procedure.l GetSHELLDLL_DefView(Nombre.l)
Protected a.l, Retl.l = 0
For a = Nombre To 0 Step - 1
GetClientRect_(Hshellview(a), @Rect.RECT)
If DesktopWidth(0) = Rect\right
If DesktopHeight(0) = Rect\bottom
Retl = 1
Break
EndIf
EndIf
Next a
If Retl = 1
EnumDesktop\HSHELLDLL_DefView = Hshellview(a)
EnumDesktop\HLevelparent = GetAncestor_(EnumDesktop\HSHELLDLL_DefView, #GA_ROOTOWNER)
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
Procedure.l GetHandleDesktopShell()
Protected hwnd.i, Nombre.l = -2
hWnd = GetDesktopWindow_()
If hWnd <> 0
EnumChildWindows_(hWnd, @EnumProc(), @Nombre)
Else
ProcedureReturn 0
EndIf
Debug nombre
If Nombre > -1
ReDim Hshellview(nombre)
If GetSHELLDLL_DefView(Nombre) = 1
ProcedureReturn 1
EndIf
EndIf
ProcedureReturn 0
EndProcedure
Procedure WinCallback(hWnd, uMsg, WParam, LParam)
Debug uMsg
Select uMsg
Case #WM_SETTINGCHANGE
Debug "#WM_SETTINGCHANGE"
If IsDesktopIconsHide() = 0
SetGadgetText(0, "Cacher les icônes")
Else
SetGadgetText(0, "Afficher les icônes")
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(0, 200, 200, 200, 200, "PureBasic Window", #PB_Window_SystemMenu)
SetWindowCallback(@WinCallback(), 0)
ButtonGadget(0, 30, 50, 140, 40, "Toggle Icons Desktop")
If GetHandleDesktopShell()= 0
DisableGadget(0, 1)
Else
If IsDesktopIconsHide() = 0
SetGadgetText(0, "Cacher les icônes")
Else
SetGadgetText(0, "Afficher les icônes")
EndIf
EndIf
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
SendMessageTimeout_(EnumDesktop\HSHELLDLL_DefView, #WM_COMMAND, 29698, 0, #SMTO_ABORTIFHUNG, 1000, @Result)
If IsDesktopIconsHide() = 0
SetGadgetText(0, "Cacher les icônes")
Else
SetGadgetText(0, "Afficher les icônes")
EndIf
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf
End