views:

182

answers:

5

The code below calls SHGetSetSettings function to hide desktop icons but it just unchecked "Show desktop icons" from the view menu.

I called SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSHNOWAIT, nil, nil); to update the desktop but that doesn't work?

var
lpss: SHELLSTATE;
begin
  lpss.Data := High(cardinal);
  lpss.Data2 := Low(cardinal);
  SHGetSetSettings(lpss,SSF_HIDEICONS,true);
  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSHNOWAIT, nil, nil);
end;
+1  A: 

isa, to refresh the desktop you can send the F5 key to the progman (Program Manager) window

PostMessage(FindWindow('Progman', nil), WM_KEYDOWN, VK_F5, 3);

another alternative to hide the desktop icons is

ShowWindow(FindWindow('Progman', nil),SW_HIDE); //hide the icons desktop and refresh the screen

to show again

ShowWindow(FindWindow('Progman', nil),SW_SHOW); //show the icons of the desktop and refresh
RRUZ
hiding the 'Progman' will disable right-click on the desktop.sending f5 to desktop doesn't work too.
isa
@isa, i've tried sending the F5 key and works ok for me. wich version of windows are you using?
RRUZ
@RRUZ sending the F5 key to refresh the desktop works, i meant it doesn't hide the icons after caling SHGetSetSettings(lpss,SSF_HIDEICONS,true);
isa
A: 

To hide or show the desktop icons:

Procedure DesktopIcons(Const Show : Boolean);
 Var
   h : HWND;
 begin
   h := GetWindow(FindWindow('Progman', 'Program Manager'), GW_CHILD);
   If Show then ShowWindow(h, SW_SHOW)
    else ShowWindow(h, SW_HIDE);
end;
DwrCymru
hiding the 'Progman' will disable right-click on the desktop
isa
A: 

Not quite an answer since I don't know why SHGetSetSettings does not work. However you can do what the shell does to hide the icons; hide the List-View control.

This is the window hiearchy of the desktop;

'Program Manager' - Progman
  '' - SHELLDLL_DefView
    'FolderView' - SysListView32

The 'SysListView32' is the one displaying the icons.


You can test and see if the shell is indeed hiding the list-view; hide the icons with the "show desktop icons" item in the view menu, then run the below,

function GetDesktopListView: HWnd;
begin
  Result := GetWindow(GetWindow(FindWindow('Progman', nil), GW_CHILD), GW_CHILD);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowWindow(GetDesktopListView, SW_SHOW);
end;

and the icons will show again.

Since you're able to check/uncheck the menu item by using 'SHGetSetSettings', the icons' visibility would be -seemingly- in accordance. Also, you don't need to refresh the desktop since the visibility change would take effect immediately.

Sertac Akyuz
good workaround solution
isa
Since this answer is already presented as a workaround to the *correct* approach, which for some reason or another does not work, I'd like to be advised about the reason of the down-vote.
Sertac Akyuz
A: 

Umm, don't you think that SHCNE_ASSOCCHANGED is a wrong choice?

SHCNE_ASSOCCHANGED says "file association was changed". You didn't change any file association. You've changed Shell settings. See the difference?

Try SHCNE_ALLEVENTS instead (I would also try SHCNE_UPDATEDIR and SHCNE_UPDATEITEM with Desktop).

Alexander
A: 

Have you tried broadcasting WM_SETTINGCHANGE message?

Alexander