🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.nativeapi
Article #21

Using SHGetSetSettings to emulate XPs Show Desktop Icons switch

#21
From: Damitr
Date: Tue, 15 Nov 2005 00:31
133 lines
4377 bytes
In Win XP you can right click on the desktop, select "Arrange Icons by"
then check or uncheck "Show Desktop Icons".  I need to emulate this
function programatically.  An old thread gave me a clue about using
SHGetSetSettings - but I've gotten stuck.  The code below (attached to
a form with a button called btnToggleIcons) gives a "Types of actual
and formal var parameters must be identical" error.  But I've tried
every variation I can think of and all I can succeed in doing is
varying the error messages <S>

Can anyone fix my code for me?


************************************
unit uIcons;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls, shlobj;

type
 TShellRecord = packed record
     fShowAllObjects: bool;
     fShowExtensions: bool;
     fNoConfirmRecycle: bool;
     fShowSysFiles: bool;
     fShowCompColor: bool;
     fDoubleClickInWebView: bool;
     fDesktopHTML: bool;
     fWin95Classic: bool;
     fDontPrettyPath: bool;
     fShowAttribCol: bool;
     fMapNetDrvBtn: bool;
     fShowInfoTip: bool;
     fHideIcons: bool;
     fWebView: bool;
     fFilter: bool;
     fShowSuperHidden: bool;
     fNoNetCrawling: bool;
     dwWin95Unused: DWORD;
     uWin95Unused: UINT;
     lParamSort: longint;
     iSortDirection: integer;
     version: UINT;
     uNotUsed: UINT;
     fSepProcess: bool;
     fStartPanelOn: bool;
     fShowStartPage: bool;
     fSpareFlags: UINT;
   end;

   PShellRecord = ^TShellRecord;

  TForm1 = class(TForm)
    btnToggleIcons: TButton;
    procedure btnToggleIconsClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
{TShellFlagState is already defined in shlobj.pas}
procedure SHGetSetSettings(var lpss: TShellFlagState; dwMask: DWORD;
bSet:
BOOL); stdcall;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure SHGetSetSettings; external 'shell32.dll' name
'SHGetSetSettings'

procedure TForm1.btnToggleIconsClick(Sender: TObject);
var
  psr: PShellRecord;
  msk: cardinal;
  bset: longbool;
begin
   bset:=false;
   SHGetSetSettings(psr,  msk,  bset);
   psr^.fHideIcons:= not psr^.fHideIcons;
   bset:=true;
   SHGetSetSettings(psr,msk,bset);
end;

end.

>From Microsoft:
SHELLSTATE Structure

Contains settings for the Shell's state. This structure is used with
the SHGetSetSettings function.

Syntax

typedef struct {
    BOOL fShowAllObjects:1;
    BOOL fShowExtensions:1;
    BOOL fNoConfirmRecycle:1;
    BOOL fShowSysFiles:1;
    BOOL fShowCompColor:1;
    BOOL fDoubleClickInWebView:1;
    BOOL fDesktopHTML:1;
    BOOL fWin95Classic:1;
    BOOL fDontPrettyPath:1;
    BOOL fShowAttribCol:1;
    BOOL fMapNetDrvBtn:1;
    BOOL fShowInfoTip:1;
    BOOL fHideIcons:1;
    BOOL fWebView:1;
    BOOL fFilter:1;
    BOOL fShowSuperHidden:1;
    BOOL fNoNetCrawling:1;
    DWORD dwWin95Unused;
    UINT uWin95Unused;
    LONG lParamSort;
    int iSortDirection;
    UINT version;
    UINT uNotUsed;
    BOOL fSepProcess:1;
    BOOL fStartPanelOn:1;
    BOOL fShowStartPage:1;
    UINT fSpareFlags:13;
} SHELLSTATE, *LPSHSHELLSTATE;

Structure Information
Header	shlobj.h
Technical Details
Message-ID: <1132014685.213780.47250@g43g2000cwa.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g43g2000cwa.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f94dd,879351ec023f90ae,start
X-Google-Attributes: gidf94dd,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g43g2000cwa.googlegroups.com!not-for-mail
From: "Damitr" <dmtrump@qivx.com>
Newsgroups: borland.public.delphi.nativeapi
Subject: Using SHGetSetSettings to emulate XPs Show Desktop Icons switch
Date: 14 Nov 2005 16:31:25 -0800
Organization: http://groups.google.com
Lines: 134
Message-ID: <1132014685.213780.47250@g43g2000cwa.googlegroups.com>
NNTP-Posting-Host: 71.211.174.169
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1132014690 17079 127.0.0.1 (15 Nov 2005 00:31:30 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 15 Nov 2005 00:31:30 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: g43g2000cwa.googlegroups.com; posting-host=71.211.174.169;
   posting-account=QQUu3gwAAAB-ka88hv599V1M3w82pAc3