从Delphi调用SHGetSetSettings [英] Calling SHGetSetSettings from Delphi
问题描述
我刚读了这个问题和这个问题,从那以后,我一直在试图调用 SHGetSetSettings
。这是 shell32.dll
的功能,但在 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位无符号整数,而 LONG
=
int
是32位有符号整数。但是我们有一个问题:整个结构将占用228位或28.5字节,这是...相当不可能,至少在Delphi中,其中 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;
现在我已经准备好定义
interface
procedure SHGetSetSettings(var ShellState: TShellState; Mask: cardinal; DoSet: boolean); stdcall;
implementation
procedure SHGetSetSettings; external shell32 name 'SHGetSetSettings';
但是,在我尝试代码之前,我注意到一些非常奇怪的东西。我发现我声明的常数已经在这里被声明: 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(0x04),并且从帮助中我们知道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屋!