DesktopIcons() : Hide / Show Desktop Icons

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

DesktopIcons() : Hide / Show Desktop Icons

13 May 2020, 11:00

Function compatible with V1.1 / V2
 

Code: Select all

DesktopIcons( Show:=-1 )                  ; By SKAN for ahk/ah2 on D35D/D495 @ tiny.cc/desktopicons
{
    Local hProgman := WinExist("ahk_class WorkerW", "FolderView") ? WinExist()
                   :  WinExist("ahk_class Progman", "FolderView")

    Local hShellDefView := DllCall("user32.dll\GetWindow", "ptr",hProgman,      "int",5, "ptr")
    Local hSysListView  := DllCall("user32.dll\GetWindow", "ptr",hShellDefView, "int",5, "ptr")

    If ( DllCall("user32.dll\IsWindowVisible", "ptr",hSysListView) != Show )
         DllCall("user32.dll\SendMessage", "ptr",hShellDefView, "ptr",0x111, "ptr",0x7402, "ptr",0)
}
 
Usage: DesktopIcons(True) to show, DesktopIcons(False) to hide, DesktopIcons() to toggle the current state.
My Scripts and Functions: V1  V2
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: DesktopIcons() : Hide / Show Desktop Icons

13 May 2020, 13:01

@SKAN, that is really handy, thank you. I need to show/hide the desktop icons pretty frequently - this will save me lots of mouse clicks. I've got it set up with a hotkey to toggle per your instructions.
Regards,
burque505
r2997790
Posts: 71
Joined: 02 Feb 2017, 02:46

Re: DesktopIcons() : Hide / Show Desktop Icons

13 May 2020, 13:44

Skan, this is handy for sure! Thank you. Oddly they disappear in milliseconds but take a while to re-render but that could be because I have 6 million icons on my desktop.

Nice tool. Thank you!
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: DesktopIcons() : Hide / Show Desktop Icons

13 May 2020, 14:00

@burque505 :) :thumbup:


r2997790 wrote: Oddly they disappear in milliseconds but take a while to re-render but that could be because I have 6 million icons on my desktop.
DllCall("SendMessage","Ptr",hWnd, "Ptr",0x111, "Ptr",0x7402, "Ptr",0) << This WM_COMMAND is equivalent to desktop right-click menu : View > Show desktop icons.
Does the icons reappear fast when done from the menu?
My Scripts and Functions: V1  V2
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: DesktopIcons() : Hide / Show Desktop Icons

08 Jun 2020, 17:33

Title post updated with following note:

Important: DetectHiddenWindows should be OFF while this function is being called.
This is not a problem when you call this function with a Hotkey, but does matter if you call it in any other way.
My Scripts and Functions: V1  V2
iPhilip
Posts: 791
Joined: 02 Oct 2013, 12:21

Re: DesktopIcons() : Hide / Show Desktop Icons

25 Feb 2021, 00:10

Hi @SKAN,

Thank you for this function. Can you comment on the second parameter (hWnd)? It seems unnecessary to me.

- iPhilip
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: DesktopIcons() : Hide / Show Desktop Icons

25 Feb 2021, 00:43

Thank you for this function. Can you comment on the second parameter (hWnd)? It seems unnecessary to me.
Hi @iPhilip
hWnd is a very common variable name and instead of declaring it local, i'm saving one line by specifying it as a parameter.
It could/should've be done as follows:

Code: Select all

DesktopIcons(Show:=-1) {                    ; By SKAN on D35D @ tiny.cc/desktopicons
Local hWnd ; Declare hWnd as local instead of a parameter
If ! hWnd := DllCall("GetWindow", "Ptr",WinExist("ahk_class Progman"), "UInt",5, "Ptr")
     hWnd := DllCall("GetWindow", "Ptr",WinExist("ahk_class WorkerW"), "UInt",5, "Ptr")
If DllCall("IsWindowVisible", "Ptr",DllCall("GetWindow","Ptr",hWnd, "UInt",5, "Ptr")) != Show
   DllCall("SendMessage","Ptr",hWnd, "Ptr",0x111, "Ptr",0x7402, "Ptr",0)
}
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: DesktopIcons() : Hide / Show Desktop Icons

25 Feb 2021, 00:48

Thanks you ...!
I have been using this code when I was new to ahk :D
don't remember where did I borrowed this code,

Code: Select all

#F11::
ControlGet, HWND, Hwnd,, SysListView321, ahk_class Progman
If HWND =
	ControlGet, HWND, Hwnd,, SysListView321, ahk_class WorkerW
If DllCall("IsWindowVisible", UInt, HWND)
	WinHide, ahk_id %HWND%
Else
	WinShow, ahk_id %HWND%
Return
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: DesktopIcons() : Hide / Show Desktop Icons

25 Feb 2021, 01:14

@Xeo786

Thanks for sharing. :thumbup:
The registry won't reflect changes in the method you've used.
Not sure if that is a problem, though.
iPhilip
Posts: 791
Joined: 02 Oct 2013, 12:21

Re: DesktopIcons() : Hide / Show Desktop Icons

25 Feb 2021, 14:02

SKAN wrote:
25 Feb 2021, 00:43
hWnd is a very common variable name and instead of declaring it local, i'm saving one line by specifying it as a parameter.
Hi @SKAN,

Thank you for the explanation.

- iPhilip
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
Kotte
Posts: 45
Joined: 03 May 2021, 08:33

Re: DesktopIcons() : Hide / Show Desktop Icons

26 Jun 2021, 05:17

Thanks for this! This is exactly what I've been looking for! I've been tinkering with my desktop/taskbar for a while now and finally there is only one minor fix left =)
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: DesktopIcons() : Hide / Show Desktop Icons

05 Sep 2021, 13:09

Code updated.
The function was already compatible in AutoHotkey V2, yet I re-wrote it to be readable.
WoundedWolf
Posts: 2
Joined: 19 Sep 2021, 17:04

Re: DesktopIcons() : Hide / Show Desktop Icons

20 Sep 2021, 12:21

hi @SKAN ,

I'm kinda new to all of this. recently started playing around with ahk. could you please help me out how can i use your code for the following function:
double-click on desktop to show/hide icons

Thanks.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: DesktopIcons() : Hide / Show Desktop Icons

20 Sep 2021, 14:36

WoundedWolf wrote:
20 Sep 2021, 12:21
double-click on desktop to show/hide icons
That will hide/show icons whenever I try to launch by clicking on any icon? :roll:
I have restricted double-click detection to to left or top edges on primary monitor. Modify it to your need.
Code stolen from: https://autohotkey.com/board/topic/82196-solved-double-click-on-the-desktop/

Code: Select all

#NoEnv
#Warn
#SingleInstance, Force

GroupAdd, DeskGroup, ahk_class Progman
GroupAdd, DeskGroup, ahk_class WorkerW

#IfWinActive ahk_group DeskGroup
~LButton::
  If ( A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500 )
  {
      MouseGetPos X, Y
      If ( X=0 Or Y=0 )
           DesktopIcons( Show:=-1 )
  }
Return
#IfWinActive


DesktopIcons( Show:=-1 )                  ; By SKAN for ahk/ah2 on D35D/D495 @ tiny.cc/desktopicons
{
    Local hProgman := WinExist("ahk_class WorkerW", "FolderView") ? WinExist()
                   :  WinExist("ahk_class Progman", "FolderView")

    Local hShellDefView := DllCall("user32.dll\GetWindow", "ptr",hProgman,      "int",5, "ptr")
    Local hSysListView  := DllCall("user32.dll\GetWindow", "ptr",hShellDefView, "int",5, "ptr")

    If ( DllCall("user32.dll\IsWindowVisible", "ptr",hSysListView) != Show )
         DllCall("user32.dll\SendMessage", "ptr",hShellDefView, "ptr",0x111, "ptr",0x7402, "ptr",0)
}
WoundedWolf
Posts: 2
Joined: 19 Sep 2021, 17:04

Re: DesktopIcons() : Hide / Show Desktop Icons

21 Sep 2021, 01:58

SKAN wrote:
20 Sep 2021, 14:36
That will hide/show icons whenever I try to launch by clicking on any icon? :roll:
I have restricted double-click detection to to left or top edges on primary monitor. Modify it to your need.
Code stolen from: https://autohotkey.com/board/topic/82196-solved-double-click-on-the-desktop/
worked absolutely beautiful @SKAN :dance:
the idea of triggering with mouse position was really nice.
1 question for flexibility would be how to make it trigger on desktop blank spot?! regardless of mouse position!
btw i did look into the link you mentioned and they were talking blank spot solution. but i failed implementing myself.
Dahu
Posts: 3
Joined: 21 Jun 2022, 14:14

Re: DesktopIcons() : Hide / Show Desktop Icons

26 Jun 2022, 03:59

@SKAN
Thank you for such an amazing script.
It works but not perfectly, so I modified it to fix a few things:
1. I think it didn't work with DetectHiddenWindows because ahk_group DeskGroup, so I wrote it another way.
2. Removed unnecessary lines that send errors, like MouseGetPos
3. Also removed ahk_class Progman because it makes it work in any window, not just on the desktop.

Code: Select all

{
#If WinActive("ahk_class WorkerW")		; Just on the desktop.
^LButton::		; Ctrl + 2*LButton
  If ( A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500 )
{
           DesktopIcons( Show:=-1 )
}
DesktopIcons( Show:=-1 )                  ; By SKAN for ahk/ah2 on D35D/D495 @ tiny.cc/desktopicons
{
    Local hProgman := WinExist("ahk_class WorkerW", "FolderView") ? WinExist()
                   :  WinExist("ahk_class Progman", "FolderView")

    Local hShellDefView := DllCall("user32.dll\GetWindow", "ptr",hProgman,      "int",5, "ptr")
    Local hSysListView  := DllCall("user32.dll\GetWindow", "ptr",hShellDefView, "int",5, "ptr")

    If ( DllCall("user32.dll\IsWindowVisible", "ptr",hSysListView) != Show )
         DllCall("user32.dll\SendMessage", "ptr",hShellDefView, "ptr",0x111, "ptr",0x7402, "ptr",0)
}
Return
}
#If
I hope it works perfectly for everyone.
Thanks again for your contribution @SKAN
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: DesktopIcons() : Hide / Show Desktop Icons

24 Aug 2022, 07:57

@SKAN , thanks once again for your great script. Works great with v2.0-beta.7 and - to my pleasant surprise - with the as-yet unreleased Keysharp.
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: DesktopIcons() : Hide / Show Desktop Icons

17 Oct 2022, 14:45

Any way to get them to "fade in" and out?
eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

Re: DesktopIcons() : Hide / Show Desktop Icons

10 Feb 2023, 03:22

Hi, SKAN

Thank you for implementing such a nice piece of code!! :bravo:

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Spawnova, TheNaviator and 81 guests