Page 1 of 2
DesktopIcons() : Hide / Show Desktop Icons
Posted: 13 May 2020, 11:00
by SKAN
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.
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 13 May 2020, 13:01
by burque505
@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
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 13 May 2020, 13:44
by r2997790
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!
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 13 May 2020, 14:00
by SKAN
@burque505
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?
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 08 Jun 2020, 17:33
by SKAN
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.
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 25 Feb 2021, 00:10
by iPhilip
Hi @SKAN,
Thank you for this function. Can you comment on the second parameter (hWnd)? It seems unnecessary to me.
- iPhilip
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 25 Feb 2021, 00:43
by SKAN
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)
}
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 25 Feb 2021, 00:48
by Xeo786
Thanks you ...!
I have been using this code when I was new to ahk
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
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 25 Feb 2021, 01:14
by SKAN
@Xeo786
Thanks for sharing.
The registry won't reflect changes in the method you've used.
Not sure if that is a problem, though.
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 25 Feb 2021, 14:02
by iPhilip
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
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 26 Jun 2021, 05:17
by Kotte
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 =)
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 29 Jun 2021, 04:35
by SKAN
@Kotte
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 05 Sep 2021, 13:09
by SKAN
Code updated.
The function was already compatible in AutoHotkey V2, yet I re-wrote it to be readable.
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 20 Sep 2021, 12:21
by WoundedWolf
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.
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 20 Sep 2021, 14:36
by SKAN
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?
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)
}
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 21 Sep 2021, 01:58
by WoundedWolf
worked absolutely beautiful
@SKAN
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.
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 26 Jun 2022, 03:59
by Dahu
@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
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 24 Aug 2022, 07:57
by burque505
@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.
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 17 Oct 2022, 14:45
by Skrell
Any way to get them to "fade in" and out?
Re: DesktopIcons() : Hide / Show Desktop Icons
Posted: 10 Feb 2023, 03:22
by eagerahk
Hi, SKAN
Thank you for implementing such a nice piece of code!!