Page 1 of 1

Enable - Disable Drop Shadow for DeskTop Icons [Windows]

Posted: Tue Sep 04, 2012 5:40 am
by RASHAD
Tested with PB 4.61 x86 Win XP SP2 - Win 7 x64

Code: Select all

Global Process

sRemMachName.s = ""
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
sValueName.s = "ListviewShadow"

Procedure.l QueryValueEx(lhkey.l, szValueName.s) 
    Shared vValue.s 
    cch = 255 
    sValue.s = Space(255)
    lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch) 
        
    Select lType 
        Case #REG_DWORD 
            lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @lValue, @cch) 
            If lrc = 0
              vValue = Str(lValue) 
            EndIf 
        Default 
            lrc = -1 
    EndSelect 
    ProcedureReturn lrc 
EndProcedure

Procedure SetValue(lTopLevelKey.l, sKeyName.s, sValueName.s, vValue.s, lType.l, sRemMachName.s) 
 
  If sRemMachName.s = "" 
    GetHandle = RegOpenKeyEx_(lTopLevelKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, lTopLevelKey, @lhRemoteRegistry) 
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  EndIf 

   If GetHandle = #ERROR_SUCCESS     
    Select lType 
      Case #REG_SZ 
        GetHandle = RegSetValueEx_(hkey, sValueName, 0, #REG_SZ, @vValue, Len(vValue) + 1) 
      Case #REG_DWORD 
        lValue = Val(vValue) 
        GetHandle = RegSetValueEx_(hKey, sValueName, 0, #REG_DWORD, @lValue, 4) 
    EndSelect 
      
    RegCloseKey_(hkey) 
    SetValue = 1 
   Else 
    RegCloseKey_(hKey)
    SetValue = 0 
  EndIf
  ProcedureReturn SetValue
EndProcedure 
 

lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey.l, @lHKeyhandle) 
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey) 
lRetVal = QueryValueEx(lhkey, sValueName) 
RegCloseKey_(lhkey) 

If Val(vValue) = 0
    SetValue(lTopLevelKey, sKeyName, sValueName.s, "01", #REG_DWORD, "")
Else
    SetValue(lTopLevelKey, sKeyName, sValueName.s, "00", #REG_DWORD, "")
EndIf

Procedure.b CheckRunningExe() 
  Protected snap.i , Proc32.PROCESSENTRY32 , dll_kernel32.i 
  dll_kernel32 = OpenLibrary(#PB_Any, "kernel32.dll") 
  If dll_kernel32 
    snap = CallFunction(dll_kernel32, "CreateToolhelp32Snapshot",$2, 0) 
    If snap 
      Proc32\dwSize = SizeOf(PROCESSENTRY32) 
      If CallFunction(dll_kernel32, "Process32First", snap, @Proc32) 
        While CallFunction(dll_kernel32, "Process32Next", snap, @Proc32)
          If PeekS(@Proc32\szExeFile) = "explorer.exe"
              Process = OpenProcess_(#PROCESS_ALL_ACCESS, 0, Proc32\th32ProcessID)
              Break
          EndIf
        Wend 
      EndIf    
      CloseHandle_(snap) 
    EndIf 
    CloseLibrary(dll_kernel32) 
  EndIf 
  ProcedureReturn #False 
EndProcedure


CheckRunningExe()
TerminateProcess_(Process, 0)
If OSVersion() > #PB_OS_Windows_Server_2003
   Delay(500)
Else
   Delay(2500)
EndIf

Re: Enable - Disable Drop Shadow for DeskTop Icons [Windows]

Posted: Tue Sep 04, 2012 3:23 pm
by IdeasVacuum
Hi Rashad

This one is proving to be a headache, I never imagined it would be so tricky.

Strangely, your code does not work on my PC (WinXP 32bit). However, I don't think I can use a Registry query anyway since many Users do not have Admin rights.

I had a glimmer of hope, running sysdm.cpl thus: RunProgram("control.exe","sysdm.cpl,,3",""). This pops-up the System Properties form, where tab 3 is the advanced tab. I was hoping that it would be possible to add further arguments to the command to select/deselect drop shadow, but to date have found nothing - probably a wild goose chase :?

Re: Enable - Disable Drop Shadow for DeskTop Icons [Windows]

Posted: Tue Sep 04, 2012 7:00 pm
by RASHAD
Sorry mate
The registry is the only way (If you use the MS panel to change the state of drop shadow ,Windows will save the new state to the registry)

About it did not work with you (if you mean changing the color),so it is a matter of timing

Code: Select all

Global Process

sRemMachName.s = ""
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
sValueName.s = "ListviewShadow"

Procedure.l QueryValueEx(lhkey.l, szValueName.s) 
    Shared vValue.s 
    cch = 255 
    sValue.s = Space(255)
    lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch) 
        
    Select lType 
        Case #REG_DWORD 
            lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @lValue, @cch) 
            If lrc = 0
              vValue = Str(lValue) 
            EndIf 
        Default 
            lrc = -1 
    EndSelect 
    ProcedureReturn lrc 
EndProcedure

Procedure SetValue(lTopLevelKey.l, sKeyName.s, sValueName.s, vValue.s, lType.l, sRemMachName.s) 
 
  If sRemMachName.s = "" 
    GetHandle = RegOpenKeyEx_(lTopLevelKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, lTopLevelKey, @lhRemoteRegistry) 
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  EndIf 

   If GetHandle = #ERROR_SUCCESS     
    Select lType 
      Case #REG_SZ 
        GetHandle = RegSetValueEx_(hkey, sValueName, 0, #REG_SZ, @vValue, Len(vValue) + 1) 
      Case #REG_DWORD 
        lValue = Val(vValue) 
        GetHandle = RegSetValueEx_(hKey, sValueName, 0, #REG_DWORD, @lValue, 4) 
    EndSelect 
      
    RegCloseKey_(hkey) 
    SetValue = 1 
   Else 
    RegCloseKey_(hKey)
    SetValue = 0 
  EndIf
  ProcedureReturn SetValue
EndProcedure 
 

lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey.l, @lHKeyhandle) 
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey) 
lRetVal = QueryValueEx(lhkey, sValueName) 
RegCloseKey_(lhkey) 

If Val(vValue) = 1
    ;SetValue(lTopLevelKey, sKeyName, sValueName.s, "01", #REG_DWORD, "")
;Else
    SetValue(lTopLevelKey, sKeyName, sValueName.s, "00", #REG_DWORD, "")
EndIf

Procedure DesktopHandle()
;------------------------
;Same for XP and Win7
         Static hwndDesktop.i
         If Not hwndDesktop               ;Class    ;Window Title
                hwndDesktop = FindWindow_("ProgMan","Program Manager")
                hwndDesktop =  GetWindow_(hwndDesktop,#GW_CHILD) ;SHELLDLL_DefView
                hwndDesktop =  GetWindow_(hwndDesktop,#GW_CHILD) ;SysListView32
         EndIf

         ProcedureReturn hwndDesktop

EndProcedure

Procedure SetListViewTextFrontColour()
;-------------------------------------

Protected sClass.s = Space(128)
Protected   hwnd.i = DesktopHandle()

           GetClassName_(hwnd, @sClass, 127)

           If (sClass = "SysListView32")

                     SendMessage_(hwnd,#LVM_SETTEXTCOLOR,#Null,$1820FE)
                  InvalidateRect_(hwnd,#Null,#True)
                    RedrawWindow_(hwnd,0,0,#RDW_UPDATENOW)
           EndIf

EndProcedure

Procedure.b CheckRunningExe() 
  Protected snap.i , Proc32.PROCESSENTRY32 , dll_kernel32.i 
  dll_kernel32 = OpenLibrary(#PB_Any, "kernel32.dll") 
  If dll_kernel32 
    snap = CallFunction(dll_kernel32, "CreateToolhelp32Snapshot",$2, 0) 
    If snap 
      Proc32\dwSize = SizeOf(PROCESSENTRY32) 
      If CallFunction(dll_kernel32, "Process32First", snap, @Proc32) 
        While CallFunction(dll_kernel32, "Process32Next", snap, @Proc32)
          If PeekS(@Proc32\szExeFile) = "explorer.exe"
              Process = OpenProcess_(#PROCESS_ALL_ACCESS, 0, Proc32\th32ProcessID)
              Break
          EndIf
        Wend 
      EndIf    
      CloseHandle_(snap) 
    EndIf 
    CloseLibrary(dll_kernel32) 
  EndIf 
  ProcedureReturn #False 
EndProcedure

; example
CheckRunningExe()
TerminateProcess_(Process, 0)
If OSVersion() > #PB_OS_Windows_Server_2003
   Delay(500)
Else
   Delay(2500)
EndIf
SetListViewTextFrontColour()


Re: Enable - Disable Drop Shadow for DeskTop Icons [Windows]

Posted: Tue Sep 04, 2012 9:19 pm
by IdeasVacuum
Hi Rashad

Ah, I meant that the drop shadow is still displayed on the desktop.

When I run your code, I can confirm the registry value is changed (with regedit) and also the option is shown deselected in the System Properties Panel, but the icon text drop shadow is still there. I thought perhaps "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects\ListviewShadow" had something to do with it but that in fact never changes. If I change the reg value by hand, same result, but via the System Properties Panel it always works fine. Given that a registry edit will not work if the User is not Admin, it's moot anyway, I need it to work every time.

Re: Enable - Disable Drop Shadow for DeskTop Icons [Windows]

Posted: Fri Sep 07, 2012 2:24 pm
by Kwai chang caine
You surely laugh, i have never see there was a shadow behind icons :oops:
Now i know :mrgreen:

The first code works fine on vista
The second change again the color of the text icon in the same color i have changed with your other code before :shock:

Thanks again RASHAD 8)