Jump to content

I can't get my head around this (refresh windows explorer )


GeekIT
 Share

Recommended Posts

this script works fine for the desktop, but if i open e.g. the folder "c:" and i click a button, i still don't see changes, nothing refreshes until i hit F5.

its a small tool for my dad to quickly show or hide hidden files with a button in a gui...

for some reason the F5 key (with sendkeys) doesn't work so 'sendkeys("F5")' is not an option...

any help is welcome! :sweating:

#NoTrayIcon


#Region
#AutoIt3Wrapper_Icon=X.ico
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#EndRegion


#include <Process.au3>


; Quit with message box if app is already running
$numberOfAppInstances = ProcessList(_ProcessGetName(@AutoItPID))
$numberOfAppInstances = $numberOfAppInstances[0][0]
If $numberOfAppInstances > 1 Then
    MsgBox(48+4096, "Exiting...", "ShowHide application already running!")
    Exit
EndIf


Func _IsRegistryExist($sKeyName, $sValueName)
    RegRead($sKeyName, $sValueName)
    Return Number(@error = 0)
EndFunc   ;==>_IsRegistryExist


If _IsRegistryExist("HKEY_CLASSES_ROOT\Folder\shell\MapOptiesSH_V4\command", "") = 0 Then
MsgBox(262208,"Menu.","Hi there!" & @CRLF & "This is the first time you start ShowHide so there will be a new item in the folder context menu...")
RegWrite("HKEY_CLASSES_ROOT\Folder\shell\MapOptiesSH_V4\command", "", "REG_SZ", "C:\\ShowHide_4.exe")
EndIf


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>


;################################################################################################;


Global $hidden_reg_show = 1
Global $supper_hidden_reg_show = 1
Global $ext_reg_show = 0


Global $hidden_reg_hide = 2
Global $supper_hidden_reg_hide = 0
Global $ext_reg_hide = 1


Global $hidden_reg = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden")
Global $Shidden_reg = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowSuperHidden")
Global $ext_reg = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt")


;################################################################################################;


Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown.
TraySetState(2)


;################################################################################################;


Func tik($byval)
SoundPlay('C:\snd.wav', $byval)
EndFunc   ;==>tik


;################################################################################################;


global $form = GUICreate("ShowHide", 432, 264, -1, -1, $WS_POPUP, $WS_EX_LAYERED)


global $RESET = GUICtrlCreateLabel('', 35, 203, 266, 38)
GUICtrlSetCursor(-1, 0)
global $TRAY = GUICtrlCreateLabel('', 311, 203, 98, 38)
GUICtrlSetCursor(-1, 0)


global $GUI = GUICtrlCreatePic("C:\gui.bmp", 0, 36, 432, 228)
GUICtrlSetState(-1, $GUI_DISABLE)


global $b1 = GUICtrlCreatePic('C:\f1.bmp', 35, 47, 266, 38)
GUICtrlSetCursor(-1, 0)
global $b2 = GUICtrlCreatePic('C:\s1.bmp', 35, 95, 266, 38)
GUICtrlSetCursor(-1, 0)
global $b3 = GUICtrlCreatePic('C:\x1.bmp', 35, 143, 266, 38)
GUICtrlSetCursor(-1, 0)


global $STOP = GUICtrlCreateLabel('', 395, 11, 26, 14)
GUICtrlSetCursor(-1, 0)


global $MIN = GUICtrlCreateLabel('', 359, 11, 26, 14)
GUICtrlSetCursor(-1, 0)


global $DRAG = GUICtrlCreatePic("drag.bmp", 0, 0, 432, 36, -1, $GUI_WS_EX_PARENTDRAG)


GUISetState(@SW_SHOW)


;################################################################################################;


If $hidden_reg = $hidden_reg_show Then
Global $box1 = "aan"
buttonset(1, $box1)
Else
Global $box1 = "uit"
buttonset(1, $box1)
EndIf
If $Shidden_reg = $supper_hidden_reg_show Then
Global $box2 = "aan"
buttonset(2, $box2)
Else
Global $box2 = "uit"
buttonset(2, $box2)
EndIf
If $ext_reg = $ext_reg_show Then
Global $box3 = "aan"
buttonset(3, $box3)
Else
Global $box3 = "uit"
buttonset(3, $box3)
EndIf


Func buttonset($but_int, $but_aan_uit)
Switch $but_int
Case 1
If $but_aan_uit = 'uit' Then
GUICtrlSetImage($b1, "C:\f0.bmp")
Else
GUICtrlSetImage($b1, "C:\f1.bmp")
EndIf
Case 2
If $but_aan_uit = 'uit' Then
GUICtrlSetImage($b2, "C:\s0.bmp")
Else
GUICtrlSetImage($b2, "C:\s1.bmp")
EndIf
Case 3
If $but_aan_uit = 'uit' Then
GUICtrlSetImage($b3, "C:\x0.bmp")
Else
GUICtrlSetImage($b3, "C:\x1.bmp")
EndIf
EndSwitch
EndFunc   ;==>buttonset


;################################################################################################;


Func refrech()
Dim $hWnd = WinGetHandle('[CLASS:Progman]')
_SendMessage($hWnd, $WM_COMMAND, 0x0001A220)


$WinExpListArr = _ExplWinGetList()
If IsArray($WinExpListArr) Then
For $iWin = 1 To $WinExpListArr[0]
$GetWinState = WinGetState($WinExpListArr[$iWin])
$hWnd = WinGetHandle($WinExpListArr[$iWin])
DllCall("user32.dll", "long", "SendMessage", "hwnd", $hWnd, "int", 0x111, "int", 28931, "int", 0)
Next
EndIf


Opt("WinTitleMatchMode", 4)
$hWnd = WinGetHandle("classname=Progman")
DllCall("user32.dll", "long", "SendMessage", "hwnd", $hWnd, "int", 0x111, "int", 28931, "int", 0)
EndFunc   ;==>refrech
Func _ExplWinGetList()
Opt("WinTitleMatchMode", 4)
$WinList = WinList("classname=CabinetWClass")
If IsArray($WinList) Then
Local $WinListArr[$WinList[0][0] + 1]
For $iW = 1 To $WinList[0][0]
$WinListArr[$iW] = $WinList[$iW][0]
Next
$WinListArr[0] = $WinList[0][0]
Return $WinListArr
Else
Return ""
EndIf
EndFunc   ;==>_ExplWinGetList


;################################################################################################;


While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE,$STOP
tik(1)
quit()
Case $MIN
tik(0)
GUISetState(@SW_MINIMIZE)
Case $b1
tik(0)
If $box1 = 'uit' Then
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden", "REG_DWORD", $hidden_reg_show)
buttonset(1, 'aan')
$box1 = 'aan'
Else
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden", "REG_DWORD", $hidden_reg_hide)
buttonset(1, 'uit')
$box1 = 'uit'
EndIf
refrech()
Case $b2
tik(0)
If $box2 = 'uit' Then
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowSuperHidden", "REG_DWORD", $supper_hidden_reg_show)
buttonset(2, 'aan')
$box2 = 'aan'
If $box1 = "uit" Then
$box1 = "aan"
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden", "REG_DWORD", $hidden_reg_show)
buttonset(1, $box1)
EndIf
Else
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowSuperHidden", "REG_DWORD", $supper_hidden_reg_hide)
buttonset(2, 'uit')
$box2 = 'uit'
EndIf
refrech()
Case $b3
tik(0)
If $box3 = 'uit' Then
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt", "REG_DWORD", $ext_reg_show)
buttonset(3, 'aan')
$box3 = 'aan'
Else
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt", "REG_DWORD", $ext_reg_hide)
buttonset(3, 'uit')
$box3 = 'uit'
EndIf
refrech()
Case $TRAY
tik(0)
GUISetState(@SW_HIDE)
TraySetState()
TraySetOnEvent ( -8, "formshow" )
Case $RESET
tik(0)
reset(1)
EndSwitch
WEnd


Func formshow()
tik(0)
TraySetState(2)
GUISetState(@SW_SHOW)
EndFunc


Func reset($byval)
local $refbool = False
if $box1 = 'aan' then
if $byval = 1 then
$box1 = 'uit'
buttonset(1, 'uit')
EndIf
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden", "REG_DWORD", $hidden_reg_hide)
$refbool = True
EndIf
if $box2 = 'aan' then
if $byval = 1 then
$box2 = 'uit'
buttonset(2, 'uit')
EndIf
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowSuperHidden", "REG_DWORD", $supper_hidden_reg_hide)
$refbool = True
EndIf
if $box3 = 'aan' then
if $byval = 1 then
$box3 = 'uit'
buttonset(3, 'uit')
EndIf
RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt", "REG_DWORD", $ext_reg_hide)
$refbool = True
EndIf
if $refbool = True Then refrech()
EndFunc


func quit()
Switch MsgBox(3+512+8192+32, "Close.", "Remember current settings?")
Case 6 ;Yes
GUISetState(@SW_HIDE)
tik(1)
Exit
Case 7 ;No
GUISetState(@SW_HIDE)
tik(1)
reset(0)
Exit
Case 2 ;Cancel
tik(0)
Return
EndSwitch
EndFunc
Link to comment
Share on other sites

Try this

Send( "{F5}" )

It works perfectly for me.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Not related, but look into _Singleton to replace your first block of code

$numberOfAppInstances = ProcessList(_ProcessGetName(@AutoItPID))
$numberOfAppInstances = $numberOfAppInstances[0][0]
If $numberOfAppInstances > 1 Then
    MsgBox(48+4096, "Exiting...", "ShowHide application already running!")
    Exit
EndIf

 

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Not related, but look into _Singleton to replace your first block of code

$numberOfAppInstances = ProcessList(_ProcessGetName(@AutoItPID))

$numberOfAppInstances = $numberOfAppInstances[0][0]

If $numberOfAppInstances > 1 Then

    MsgBox(48+4096, "Exiting...", "ShowHide application already running!")

    Exit

EndIf

 

 

why? what's wrong with it please?

Link to comment
Share on other sites

Too lazy to go through your script :), but this works for me on Win8.1. In my experience the OS version is relevant to this kind of stuff...

If RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt") Then
    RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt", "REG_DWORD", 0)
Else
    RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "HideFileExt", "REG_DWORD", 1)
EndIf

Local $bOld = Opt("WinSearchChildren", True)
Local $aWinListSHELLDLL_DefView = WinList("[CLASS:SHELLDLL_DefView]")
For $i = 0 To $aWinListSHELLDLL_DefView[0][0]
    DllCall("user32.dll", "long", "SendMessage", "hwnd", $aWinListSHELLDLL_DefView[$i][1], "int", 0x111, "int", 28931, "int", 0)
Next
Opt("WinSearchChildren", $bOld)
Link to comment
Share on other sites

_Singleton has nothing to do with the name of the script, it creates a Mutex then checks the second time the script is run to see if that mutex exists. At least that's how I remember it being described.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

not here, as i explained in my intro..

but tnx

I read that in your intro, But the code that I suggested is pretty much a fix to the code that you wrote. Your refresh code doesnt work for me either. Thats why I suggested you test my method.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...