Ryan Farber's WebLog

High Contrast Mode

We are working on a simple helper tool for testing accessibility in IE pages.  One of the few tests that is pretty hard to automate since it has to be reviewed first, although once reviewed screen shot comparisons of regressions could be useful assuming the pages are reasonably static.  Either way this tool is a simple set of options for IE.  Turn on/off IE settings for Images, Colors, and CSS; resize IE window for resolution testing (ok not the same thing but reasonably the same effect), Alt text expand, and font size.  The tool sets the IE registry settings then opens IE on the test url.  After you are done it resets all the registry setting.  Nice, simple, and easy to hand to a dev for unit tests.  The only feature we wanted to add the was somewhat difficult was setting Windows into High Contrast Mode.  After long searching for how to change high contrast mode in .NET I came up with the following. 

Public Structure tagHIGHCONTRAST
   
Dim cbSize As Integer
   
Dim dwFlags As Integer
   
Dim lpszDefaultScheme As Integer
End Structure

Public Const HCF_HIGHCONTRASTON As Integer = &H1
Public Const SPI_GETHIGHCONTRAST As Integer = 66
Public Const SPI_SETHIGHCONTRAST As Integer = 67
Public Const SPIF_UPDATEINIFILE As Integer = &H1
Public Const SPIF_SENDWININICHANGE As Integer = &H2
Public Const SPIF_SENDCHANGE As Integer = SPIF_SENDWININICHANGE

Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" ( _
      
ByVal uAction As Integer, _
      
ByVal uParam As Integer, _
      
ByRef lpvParam As tagHIGHCONTRAST, _
   
   ByVal fuWinIni As Integer) As Integer

Private Sub SetHighContrast(ByVal TurnOn As Boolean)
   
Dim udtHighContrast As tagHIGHCONTRAST
   
Dim lngWin32apiResultCode As Long

   
udtHighContrast.cbSize = Len(udtHighContrast)
   
lngWin32apiResultCode = SystemParametersInfo(SPI_GETHIGHCONTRAST, Len(udtHighContrast), udtHighContrast, 0)

   If
TurnOn Then
      
udtHighContrast.dwFlags = udtHighContrast.dwFlags Or HCF_HIGHCONTRASTON
   Else
      
udtHighContrast.dwFlags = udtHighContrast.dwFlags Xor HCF_HIGHCONTRASTON
   
End If

   
lngWin32apiResultCode = SystemParametersInfo(SPI_SETHIGHCONTRAST, Len(udtHighContrast), udtHighContrast, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE)
End Sub

Published Friday, October 21, 2005 2:32 PM by rfarber

Comments

No Comments
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker