Reputation: 20464
I'm trying to use SystemParametersInfo
function to set a Boolean parameter, this is just an example of one of the Booleans parameters that I will set:
' I try to set a boolean parameter, but no matter if I use False or True,
' the parameter on the SO is always activated.
SystemParametersInfo(SPI.SPI_SETCURSORSHADOW, 0UI, False, SPIF.None)
' I check the modified parameter but always is positive.
Dim MyBoolean As Boolean = False
SystemParametersInfo(SPI.SPI_GETCURSORSHADOW, 0UI, MyBoolean, SPIF.None)
MsgBox(MyBoolean) ' Always is 'True',
' and in the Advanced properties of the SO;
' the 'Show shadow under mouse' option is always checked.
And this is other example:
' Enable Accelerator Keys Visibility ( The underlined keys of the ContextMenu )
NativeMethods.SystemParametersInfo(SPI.SPI_SETKEYBOARDCUES, 0UI, True, SPIF.None)
The documentation for both in MSDN says to use a False boolean to disable the parameter:
''' <summary>
''' Enables or disables a shadow around the cursor.
''' The pvParam parameter is a BOOL variable.
''' Set pvParam to TRUE to enable the shadow or FALSE to disable the shadow.
''' This effect appears only if the system has a color depth of more than 256 colors.
''' Windows NT, Windows Me/98/95: This value is not supported.
''' </summary>
But the truth is that I can't find the way to Disable them once they are enabled, I've tried to use directly a boolean value, also with a boolean variable, and with combinations of the SPIF parameter, no way, if I activate a parameter I can't turn it off, I supose that I'm doing something wrong but ...what is?.
PS: I'm using Windows 8 x64
And this is the SystemParametersInfo
part:
<DllImport("user32.dll", SetLastError:=True)>
Friend Shared Function SystemParametersInfo(
ByVal uiAction As SPI,
ByVal uiParam As UInteger,
ByRef pvParam As Boolean,
ByVal fWinIni As SPIF
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<Description("SPI System-wide parameter - Used in SystemParametersInfo function")>
Public Enum SPI As UInteger
SPI_SETKEYBOARDCUES = &H100B
SPI_GETCURSORSHADOW = &H101A
SPI_SETCURSORSHADOW = &H101B
End Enum
<Description("SPIF System-wide parameter - Used in SystemParametersInfo function")>
<Flags>
Enum SPIF
''' <summary>
''' None
''' </summary>
None = &H0
''' <summary>
''' Writes the new system-wide parameter setting to the user profile.
''' </summary>
SPIF_UPDATEINIFILE = &H1
''' <summary>
''' Broadcasts the WM_SETTINGCHANGE message after updating the user profile.
''' </summary>
SPIF_SENDCHANGE = &H2
''' <summary>
''' Same as SPIF_SENDCHANGE.
''' </summary>
SPIF_SENDWININICHANGE = &H2
End Enum
Upvotes: 1
Views: 507
Reputation: 38875
All the Win32 API stuff tends to be geared for C/C++ where True is 1 (or actually just not zero IIRC). You need to change MyBoolean to Integer
and use 0 or 1. You'll also have to change the API signature:
<DllImport("user32.dll")> _
Private Shared Sub SystemParametersInfo(uiAction As UInteger,
uiParam As UInteger, ByRef pvParam As Integer, fWinIni As UInteger)
End Sub
This is also why you saw 0 and 1 and the return for many, many of those WndProc messages you were messing with. Its the T/F return whether the message was handled in many cases.
Upvotes: 1