Page 1 of 1

See if High Contrast Theme is On -- Help with DllCall("SystemParametersInfo")

Posted: 26 Oct 2017, 09:53
by Verdlin
Using Autohotkey_H. I'm trying to check if a high contrast theme is on (see this link for a C++ example)

DllCall returns 0, but dwFlags is always 0, even when the high contrast theme is off. What am I doing wrong?

Code: Select all

vHighContrast := Struct("UINT cbSize, DWORD dwFlags, LPTSTR lpszDefaultScheme", {cbSize:sizeof("UINT cbSize, DWORD dwFlags, LPTSTR lpszDefaultScheme")})
Msgbox % DllCall("SystemParametersInfo", "Uint", SPI_GETHIGHCONTRAST:=66, "Uint", 0, "ptr", &vHighContrast, "Uint", 0)
MsgBox % vHighContrast.dwFlags

Re: See if High Contrast Theme is On -- Help with DllCall("SystemParametersInfo")  Topic is solved

Posted: 26 Oct 2017, 20:10
by jeeswg
I believe you need to pass oHighContrast[""] rather than &oHighContrast.

Code: Select all

q::
;SPI_GETHIGHCONTRAST := 0x42
oHighContrast := Struct("UINT cbSize, DWORD dwFlags, LPTSTR lpszDefaultScheme", {cbSize:sizeof("UINT cbSize, DWORD dwFlags, LPTSTR lpszDefaultScheme")})
vSize := sizeof(oHighContrast)
DllCall("user32\SystemParametersInfo", UInt,0x42, UInt,vSize, Ptr,oHighContrast[""], UInt,0)
vFlags := oHighContrast.dwFlags
MsgBox, % Format("0x{:X}", vFlags)

vSize := A_PtrSize=8?16:12
VarSetCapacity(HIGHCONTRAST, vSize, 0)
NumPut(vSize, &HIGHCONTRAST, 0, "UInt") ;cbSize
DllCall("user32\SystemParametersInfo", UInt,0x42, UInt,vSize, Ptr,&HIGHCONTRAST, UInt,0)
vFlags := NumGet(&HIGHCONTRAST, 4, "UInt") ;dwFlags
MsgBox, % Format("0x{:X}", vFlags)

;HCF_HIGHCONTRASTON := 0x1 ;constant from WinUser.h
MsgBox, % "high contrast: " ((vFlags & 0x1) ? "on" : "off")
return

;[note: setting uiParam as 0 rather than sizeof(HIGHCONTRAST) also seemed to work]
;SystemParametersInfo function (Windows)
;https://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx
;Set the cbSize member of this structure and the uiParam parameter to sizeof(HIGHCONTRAST).

Re: See if High Contrast Theme is On -- Help with DllCall("SystemParametersInfo")

Posted: 27 Oct 2017, 09:55
by Verdlin
That was spot on! Thanks!