AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Refreshing desktop (icons) upon hotkey event
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
[二oO也



Joined: 22 Feb 2005
Posts: 60
Location: Sweden

PostPosted: Wed Aug 10, 2005 8:12 pm    Post subject: Refreshing desktop (icons) upon hotkey event Reply with quote

I'm looking for a way to refresh the desktop with AHK, (as when you rightclick on desktop and press 'Refresh' in the context menu). The best thing I've come up with so far is this:
Code:

hotkey,!1,Refresh
return

Refresh:
mouseclick, right
sleep 20
send,{ctrl down}u{ctrl up}
return

Embarassed YES i know, it's very crude and I'm desperate to find another solution that is a bit more fool-proof.

I'm convinced that the answer lies in a Send/Postmessage or a Dllcall(), but I'm unfortunately not very familiar to such commands... Confused Sad

Arrow The trick is that pressing F5 does not work in my case, but there has to be another way... Question
_________________
"Make everything as simple as possible, but not simpler."
- Albert Einstein (1879-1955)
Back to top
View user's profile Send private message Visit poster's website
Pasukun



Joined: 16 Dec 2004
Posts: 84

PostPosted: Wed Aug 10, 2005 9:34 pm    Post subject: Reply with quote

Here you go.

Code:
!1::
Send, {F5}
return


Update:
Oh NM, I just realized that you said F5 does not work on your case.
Let me see if there is another way.
_________________

"the things we touch have no permanence. my master would say: there is nothing we can hold onto in this world.. only by letting go can we truly possess what is real..."
Back to top
View user's profile Send private message
Willigis



Joined: 17 Feb 2005
Posts: 23
Location: Frankfurt

PostPosted: Wed Aug 10, 2005 11:29 pm    Post subject: Reply with quote

Here comes a complicated but working solution Very Happy

Code:
;Get the current icon size and change it
RegRead, icon_size, HKEY_CURRENT_USER, Control Panel\Desktop\WindowMetrics, Shell Icon Size
icon_size++

;write changes to registry
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop\WindowMetrics, Shell Icon Size, %icon_size%

;disables redrawing informs the desktop that there are changes
SendMessage, 0x0B, 0, 0,SysListView321,ahk_class Progman
SendMessage, 0x1A, 0, 10000,SysListView321,ahk_class Progman

;changes icon_size back to the original value
icon_size--
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop\WindowMetrics, Shell Icon Size, %icon_size%
   
;enables redrawing. the desktop will be refreshed
SendMessage, 0x1A,0, 10000,SysListView321,ahk_class Progman
SendMessage, 0x0B, 0, 1,SysListView321,ahk_class Progman


So far, I've tested it with XP. It works in most cases but is far from beeing perfectly.
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Fri Aug 12, 2005 11:18 am    Post subject: Reply with quote

Code:
SendMessage, 0x1A,,,, Program Manager
Back to top
[二oO也



Joined: 22 Feb 2005
Posts: 60
Location: Sweden

PostPosted: Fri Aug 12, 2005 8:58 pm    Post subject: Reply with quote

Thank you all for your replys but in some way neither of your suggestions work! Confused Mad Evil or Very Mad

What I'm trying to do is to make a script hide/unhide desktop icons:
Code:

hotkey,!1,Hide
hotkey,!2,Show
return

Hide:
regwrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced,HideIcons, 1
SendMessage, 0x1A,,,, Program Manager ;Supposed to update desktop but only updates the icons                                                    ;themselves, not checking whether they actally are visible
traytip
traytip, Desktop, Icons Hidden!, 5,1
return

Show:
regwrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced,HideIcons, 0
SendMessage, 0x1A,,,, Program Manager
traytip
traytip, Desktop, Icons Unhidden!, 5,1
return

When I run it and press Alt + 1 the icons does not disappear (until I manually press Refresh). Confused
I have Win2k, AHK version 1.0.37.04
But (the most annoying thing) pressing 'Refresh' works fine...

Sorry guys for disappointing you, "Let's help each other out" Wink Smile
_________________
"Make everything as simple as possible, but not simpler."
- Albert Einstein (1879-1955)
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Sat Aug 13, 2005 1:47 pm    Post subject: Reply with quote

Quote:
What I'm trying to do is to make a script hide/unhide desktop icons


Code:
winhide, Program Manager
sleep, 2000
winshow, Program Manager
Back to top
Serenity



Joined: 07 Nov 2004
Posts: 1276

PostPosted: Sat Aug 13, 2005 3:39 pm    Post subject: Reply with quote

I wrote a similar script to show/hide desktop icons. The problem with using winhide/winshow is that it also hides Rainlendar and the desktop wallpaper, and disables the desktop context menu. Using the registry is better as it only affects the icons.
_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
[二oO也



Joined: 22 Feb 2005
Posts: 60
Location: Sweden

PostPosted: Sat Aug 13, 2005 9:25 pm    Post subject: Reply with quote

I agree with Serenity, the only thing I need now is something that refreshes the desktop and its icons. Rolling Eyes

Thanks for your replys, guys! Smile
_________________
"Make everything as simple as possible, but not simpler."
- Albert Einstein (1879-1955)
Back to top
View user's profile Send private message Visit poster's website
Serenity



Joined: 07 Nov 2004
Posts: 1276

PostPosted: Sat Aug 13, 2005 11:35 pm    Post subject: Reply with quote

This VB script suggests there is a 'low level' way to refresh the icons.

Code:
 ' Send HWND_BROADCAST to refresh the icons.
    SendMessageTimeout HWND_BROADCAST, WM_SETTINGCHANGE, _
        SPI_SETNONCLIENTMETRICS, 0&, SMTO_ABORTIFHUNG, _
        10000&, result


From API-Guide:

Quote:
SPI_GETNONCLIENTMETRICS
Retrieves the metrics associated with the nonclient area of nonminimized windows. The pvParam parameter must point to a NONCLIENTMETRICS structure that receives the information.


and from MSDN:

Quote:
To send the WM_SETTINGCHANGE message to all top-level windows, use the SendMessageTimeout function with the hwnd parameter set to HWND_BROADCAST.

If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows. The function does not return until each window has timed out.


Perhaps there is some way to use DllCall to send the WM_SETTINGCHANGE message?
_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Sun Aug 14, 2005 11:14 am    Post subject: Reply with quote

This?

Code:
SendMessage, 0x1A, 42,,, ahk_id 0xFFFF
MsgBox, %errorlevel%


SendMessage Help:

Quote:
To send a message to all windows in the system, including those that are hidden or disabled, specify ahk_id 0xFFFF for WinTitle (0xFFFF is HWND_BROADCAST). This technique should be used only for messages intended to be broadcast, such as the following example: SendMessage, 0x1A,,,, ahk_id 0xFFFF ; 0x1A is WM_SETTINGCHANGE


Google:

42 = SPI_SETNONCLIENTMETRICS
Back to top
[二oO也



Joined: 22 Feb 2005
Posts: 60
Location: Sweden

PostPosted: Sun Aug 14, 2005 2:40 pm    Post subject: Reply with quote

Anonymous wrote:
This?

Code:
SendMessage, 0x1A, 42,,, ahk_id 0xFFFF
MsgBox, %errorlevel%


No, updates desktop but does not affect the icons state of hidden/visible... Confused
Quote:


SendMessage Help:

Quote:
To send a message to all windows in the system, including those that are hidden or disabled, specify ahk_id 0xFFFF for WinTitle (0xFFFF is HWND_BROADCAST). This technique should be used only for messages intended to be broadcast, such as the following example: SendMessage, 0x1A,,,, ahk_id 0xFFFF ; 0x1A is WM_SETTINGCHANGE


Google:

42 = SPI_SETNONCLIENTMETRICS

_________________
"Make everything as simple as possible, but not simpler."
- Albert Einstein (1879-1955)
Back to top
View user's profile Send private message Visit poster's website
UweD



Joined: 14 Sep 2005
Posts: 23
Location: Japan

PostPosted: Sat Oct 01, 2005 2:21 am    Post subject: Update User Settings Reply with quote

Hi,
I am not sure if this works for you too, but after setting a wallpaper I have found following to be effective to update the desktop.
UweD

Quote:
Code:
Runvar=%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
Run %Runvar%
Back to top
View user's profile Send private message
shimanov



Joined: 25 Sep 2005
Posts: 612

PostPosted: Sat Oct 01, 2005 3:43 am    Post subject: Reply with quote

Try the following:

(tested with Windows XP SP2 [and Rainlendar])

Code:

WinGet, hw_program_manager, ID, Program Manager ahk_class Progman
;MsgBox, % hw_program_manager

hw_SHELLDLL_DefView := FindWindowEx( hw_program_manager, 0, "SHELLDLL_DefView", 0 )
;MsgBox, % hw_SHELLDLL_DefView

hw_FolderView := FindWindowEx( hw_SHELLDLL_DefView, 0, "SysListView32", "FolderView" )
;MsgBox, % hw_FolderView

MsgBox, Now you see them ...

WinHide, ahk_id %hw_FolderView%

MsgBox, .. now you dont!

WinShow, ahk_id %hw_FolderView%
return

FindWindowEx( p_hw_parent, p_hw_child, p_class, p_title )
{
   if ( p_title = 0 )
      type_title = uint
   else
      type_title = str

   return, DllCall( "FindWindowEx"
                  , "uint", p_hw_parent
                  , "uint", p_hw_child
                  , "str", p_class
                  , type_title, p_title )
}


I believe the registry setting change is still required to ensure the state is persistent (not tested).
Back to top
View user's profile Send private message
chezduong
Guest





PostPosted: Mon Mar 19, 2007 5:30 pm    Post subject: Re: Update User Settings Reply with quote

UweD wrote:
Hi,
I am not sure if this works for you too, but after setting a wallpaper I have found following to be effective to update the desktop.
UweD

Quote:
Code:
Runvar=%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
Run %Runvar%


@ UweD
This works perfectly for updating the desktop wallpaper! I have been looking for this for hours. Thank you very much!

Just one Q: Because it is accessing System32 directory, do you need Administrator rights?

Thanks again.
Back to top
Grumpy
Guest





PostPosted: Mon Mar 19, 2007 5:54 pm    Post subject: Re: Update User Settings Reply with quote

chezduong wrote:
Just one Q: Because it is accessing System32 directory, do you need Administrator rights?
Short answer: just try!
Longer answer: probably not, otherwise your system wouldn't work! You don't do any change in this dir, just access a system file to make it do one job. Windows is doing this all the time!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group