gpt4 book ai didi

windows - SPI_SETDISABLEOVERLAPPEDCONTENT

转载 作者:可可西里 更新时间:2023-11-01 10:59:05 26 4
gpt4 key购买 nike

我有功能

function bgSetDisableOverlappedContent(CAA: BOOL; var ErrorCode: DWORD; ErrorText: string): Boolean;  
begin
errorCode := ERROR_SUCCESS;
ErrorText := '';
if not GetOSVersion >= 60 then
Exit;
Result := SystemParametersInfo(SPI_SETDISABLEOVERLAPPEDCONTENT, 0, @CAA, 0);
if not Result then
begin
ErrorCode := GetLastError;
ErrorText := GetErrorText(ErrorCode);
end;
end;

并准确地调用它

procedure TForm1.Button3Click(Sender: TObject);
var
CAA: BOOL;
OS: TUsableInOS;
ErrorCode: DWORD;
ErrorText: string;
begin
CAA := False;
if bgSetDisableOverlappedContent(CAA, ErrorCode, ErrorText) then
ShowMessage('Success');
end;

但是,当我再次检查下一个代码时

function bgGetDisableOverlappedContent(var CAA: BOOL; OS: TUsableInOS; ErrorCode: DWORD; ErrorText: string): Boolean;
begin
errorCode := ERROR_SUCCESS;
ErrorText := '';
os := tosVistaUp;
if not GetOSVersion >= 60 then
Exit;
Result := SystemParametersInfo(SPI_GETDISABLEOVERLAPPEDCONTENT, 0, @CAA, 0);
if not Result then
begin
ErrorCode := GetLastError;
ErrorText := GetErrorText(ErrorCode);
end;
end;
function GetOSVersion: Integer;
var
OSVersionInfo : TOSVersionInfo;
begin
Result:= 0;
FillChar(OsVersionInfo, Sizeof(OsVersionInfo), 0);
OSVersionInfo.dwOSVersionInfoSize := SizeOf(OSVersionInfo);
if GetVersionEx(OSVersionInfo) then
begin
if OSVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then
begin
if (OsVersionInfo.dwMajorVersion = 5) and ((OsVersionInfo.dwMinorVersion = 0)) then
Result:= 50; //2000
if (OsVersionInfo.dwMajorVersion = 5) and ((OsVersionInfo.dwMinorVersion = 1)) then
Result:= 51; //XP
if (OsVersionInfo.dwMajorVersion = 5) and ((OsVersionInfo.dwMinorVersion = 2)) then
Result:= 52; //2003, 2003 R2
if (OsVersionInfo.dwMajorVersion = 6) and ((OsVersionInfo.dwMinorVersion = 0)) then
Result:= 60; //Vista, Windows Server 2008
if (OsVersionInfo.dwMajorVersion = 6) and ((OsVersionInfo.dwMinorVersion = 1)) then
Result:= 61; //Server 2008 R2, 7
end;
end;
end;

CAA 的结果再次为真,即使我完全设置了 CAA := False;我正在使用 Win 7。Result of Result := SystemParametersInfo(SPI_SETDISABLEOVERLAPPEDCONTENT, 0, @CAA, 0);是 True,但 SPI_GETDISABLEOVERLAPPEDCONTENT 为 CAA 返回 True,即使在它被设置为 False 之前的步骤中也是如此。

procedure TForm1.Button3Click(Sender: TObject);
var
CAA: BOOL;
OS: TUsableInOS;
ErrorCode: DWORD;
ErrorText: string;
Res: Bool;
begin
CAA := False;
{ if bgSetDisableOverlappedContent(CAA, ErrorCode, ErrorText) then
ShowMessage('Success'); }
Res := SystemParametersInfo(SPI_SETDISABLEOVERLAPPEDCONTENT,
0,
@CAA,
0);

Res := SystemParametersInfo(SPI_GETDISABLEOVERLAPPEDCONTENT,
0,
@CAA,
0);
if Caa then
ShowMessage('True')
else
ShowMessage('False');
end;

CAA 是正确的。

你有什么想法吗?

提前致谢博扬

最佳答案

主要问题是,当传递 SPI_SETDISABLEOVERLAPPEDCONTENT 时,您打算传递一个 BOOL 变量,但您传递的是一个指向 BOOL 的指针. documentation说:

The pvParam parameter is a BOOL variable. Set pvParam to TRUE to disable overlapped content, or FALSE to enable overlapped content.

这意味着您设置属性的代码需要像这样:

SystemParametersInfo(SPI_SETDISABLEOVERLAPPEDCONTENT, 0, Pointer(CAA), 0)

您的 GetOSVersion 是一场灾难。抱歉听起来很刺耳!对于 Windows 8 及更高版本,它返回 0。而且您的代码在运算符优先级方面存在问题。你写:

if not GetOSVersion >= 60 then

and operator precedence means that is interpreted as

if (not GetOSVersion) >= 60 then

由于 GetOSVersion 返回一个带符号的值,(not GetOSVersion) >= 60 的计算结果为 False,与 Windows 版本无关。那是因为 not GetOSVersion 总是 <= 0

您需要逻辑否定而不是按位否定。所以你应该写

if not (GetOSVersion >= 60) then

或等效

if GetOSVersion < 60 then

实际上有一个内置函数可以做到这一点。它称为 CheckWin32Version。像这样调用它:

if not CheckWin32Version(6, 0) then
exit;

你的函数的其余部分有点乱。您按值传递 ErrorText,然后分配给它。大概您打算调用者接收该值。除非您通过 var,否则不会发生这种情况。

我个人会像这样编写您的程序:

procedure bgSetDisableOverlappedContent(CAA: BOOL);
begin
if CheckWin32Version(6, 0) then
if not SystemParametersInfo(SPI_SETDISABLEOVERLAPPEDCONTENT, 0, Pointer(CAA), 0) then
RaiseLastOSError;
end;

我认为最好将 SystemParametersInfo 中的错误转换为异常,因为这是一种特殊情况。我反对你实际生成对 SystemParametersInfo 的调用失败。在这种情况下,没有必要为根本不会发生的事情构建错误代码返回机制。检查错误并转换为运行时异常。这使得调用代码变得非常简单。

您的按钮点击处理程序可以更简单:

procedure TForm1.Button3Click(Sender: TObject);
begin
bgSetDisableOverlappedContent(False);
end;

而且 getter 函数也比必要的复杂得多。我会这样:

function bgGetDisableOverlappedContent: Boolean;
var
CAA: BOOL;
begin
if not CheckWin32Version(6, 0) then
begin
Result := False;//or True, I don't know, you decide
exit;
end;
if not SystemParametersInfo(SPI_GETDISABLEOVERLAPPEDCONTENT, 0, @CAA, 0) then
RaiseLastOSError;
Result := CAA;
end;

关于windows - SPI_SETDISABLEOVERLAPPEDCONTENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14085508/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com