从Delphi调用SHGetSetSettings [英] Calling SHGetSetSettings from Delphi

查看:186
本文介绍了从Delphi调用SHGetSetSettings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚才读<一个href=\"http://stackoverflow.com/questions/3482227/old-delphi-hide-show-desktop-icons-method-not-working-under-windows-7-64-bit\">this问题和<一个href=\"http://stackoverflow.com/questions/3326062/how-do-i-make-the-show-hide-desktop-icons-setting-take-effect\">this问题,从那以后,我一直在试图调用的 SHGetSetSettings 在Delphi中。这是 SHELL32.DLL A的功能,但不是在 ShlObj.pas 中定义的,所以我们需要写我们自己的定义。

I just read this question and this question, and since then I have been trying to call SHGetSetSettings in Delphi. This is a function of shell32.dll, but is not defined in ShlObj.pas, so we need to write our own definition.

首先,我们需要翻译的 SHELLSTATE 结构。现在,我必须用C只有有限的经验,但我想,1指的是结构的成员是单个位,也就是说,其中八人在一个字节打包在一起。我也假设 DWORD = UINT = 32位无符号整数和 = INT 是32位有符号整数。但是,我们有一个问题:那么整个结构将占据228位,即28.5字节,这是...相当不可能的,至少在德尔福,其中的sizeof(SomeRecord)必须是一个整数。

First we need to translate the SHELLSTATE structure. Now I have only limited experience in C, but I suppose that ": 1" means that the member of the structure is a single bit, that is, that eight of them can be packed together in a byte. I also suppose that DWORD = UINT = 32-bit unsigned integers and that LONG = int are 32-bit signed integers. But then we have a problem: The entire structure will then occupy 228 bits, or 28.5 bytes, which is ... rather impossible, at least in Delp where sizeof(SomeRecord) has to be an integer.

不过,我试图在年底增加四个虚位来解决它。 232位= 29个字节,这是很好的。

Nevertheless, I tried to solve it by adding four dummy bits at the end. 232 bits = 29 bytes, which is nice.

因此​​,我试过

PShellState = ^TShellState;
TShellState = packed record
  Data1: cardinal;
  Data2: cardinal;
  Data3: cardinal;
  Data4: cardinal;
  Data5: cardinal;
  Data6: cardinal;
  Data7: cardinal;
  Data8: byte; // Actually a nibble would be sufficient
end;

然后我宣布(用于日后方便)

and then I declared (for later convenience)

const
  fShowAllObjects = 1;
  fShowExtensions = 2;
  fNoConfirmRecycle = 4;
  fShowSysFiles = 8;
  fShowCompColor = 16;
  fDoubleClickInWebView = 32;
  fDesktopHTML = 64;
  fWin95Classic = 128;
  fDontPrettyPath = 256;
  fShowAttribCol = 512;
  fMapNetDrvButton = 1024;
  fShowInfoTip = 2048;
  fHideIcons = 4096;
  fWebView = 8192;
  fFilter = 16384;
  fShowSuperHidden = 32768;
  fNoNetCrawling = 65536;

现在我觉得自己已经准备定义

Now I felt ready to define

interface
  procedure SHGetSetSettings(var ShellState: TShellState; Mask: cardinal; DoSet: boolean); stdcall;

implementation
  procedure SHGetSetSettings; external shell32 name 'SHGetSetSettings';

但我试过code之前,我发现了一些很奇怪的。我发现我宣布常数已经在这里宣布: SSF常量。请注意, SSF_HIDEICONS = 0x00004000 = 16384≠fHideIcons = 4096 。如果 SSF _ 常数真的是用 SHELLSTATE 一起使用口罩,那么它是没有意义的定义 SSF_HIDEICONS 2 ^ 14时,它是第13位(及其掩码应为2 ^ 12)中的结构。因此,现在看来,这两个MSDN参考页矛盾海誓山盟。

But before I tried the code, I noticed something very strange. I found that the constants I declared were already declared here: SSF Constants. Notice that SSF_HIDEICONS = 0x00004000 = 16384 ≠ fHideIcons = 4096. If the SSF_ constants really are masks used together with SHELLSTATE, then it makes no sense to define SSF_HIDEICONS as 2^14 when it is the 13th bit (and its mask should be 2^12) in the structure. Hence, it seems, the two MSDN reference pages contradict eachother.

可能有人请带来一些清晰度为这一切?

Could someone please bring some clarity into all this?

推荐答案

我的帮助下阅读这里要说的是检索数据时SSF_常量掩码指定。没有理由他们必须映射到ShellState结构中的位。

My reading of the help here is that the SSF_ constants are specified for the mask when retrieving data. There's no reason they have to map to the bits in the ShellState structure.

如果他们没有fShowSysFiles将映射到8(0×04),我们从帮助,SSF_SHOWSYSFILES为0x20知道。有没有直接的对应关系。

If they did fShowSysFiles would map to 8 (0x04), and we know from the help that SSF_SHOWSYSFILES is 0x20. There's no direct mapping.

这篇关于从Delphi调用SHGetSetSettings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆