I have function
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;
and call it exactly
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;
But, when I inspect again with next code
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;
result for CAA is again True, even I exactly set CAA := False;
I am working on Win 7. and Result of Result := SystemParametersInfo(SPI_SETDISABLEOVERLAPPEDCONTENT, 0, @CAA, 0); is True, but SPI_GETDISABLEOVERLAPPEDCONTENT returns True for CAA, even in step before it exactly was set as 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 is True.
Do you have any idea?
Thanks in advance
Bojan
The main problem is that when passing
SPI_SETDISABLEOVERLAPPEDCONTENTyou are meant to pass aBOOLvariable, but you are passing a pointer to aBOOL. The documentation says:Which means that your code to set the property needs to be like this:
Your
GetOSVersionis a disaster. Sorry to sound harsh! It returns0for Windows 8 and later. And your code has problems with operator precedence. You write:and operator precedence means that is interpreted as
Since
GetOSVersionreturns a signed value,(not GetOSVersion) >= 60evaluates toFalseirrespective of windows version. That’s becausenot GetOSVersionis always <=0.You want logical negation rather than bitwise negation. So you should write
or equivalently
In reality there is a built in function to do this. It’s called
CheckWin32Version. Call it like this:The rest of your function is a bit of a mess though. You pass
ErrorTextby value and then assign to it. Presumably you are intending the caller to receive that value. Which won’t happen unless you passed byvar.Personally I’d write your procedure like this:
I think it’s better to convert an error in
SystemParametersInfoto an exception since it’s an exceptional circumstance. I defy you to actually generate a failure of that call toSystemParametersInfo. In which case there’s no point building an error code returning mechanism for something that simply will not happen. Check for errors and convert to a runtime exception. This makes the calling code so much simpler.Your button click handler can be much simpler:
And the getter function is also much more complex than necessary. I’d have it like this: