By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,016 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

SystemParametersInfo Failing in VB.net "Slide Open Combo Boxes"

P: 1
Could not figure out on how to reply to the last article with the same name. When I logged out it asked me to login and when I logged in there was no "post your reply" option, perhaps there is functional bug on this website, anyhow.

I had a similar problem where getting the value was okay but saving the value did not work, so I hope my solution helps, if someone else has a similar issue of understanding how to declare and use api functions.

[FYI: I was designing a user drawn combobox and the "Slide Open Combo Boxes" windows setting was effecting the display of the drop down portion of combo box. I got no text in the header portion and if my DataSource was only a few rows it showed no data at all and the height of the combo was only a few pixels !!?? My workaround was to toggle this windows setting value off then on again in the DropDown and DropDownClosed events respectively:
Expand|Select|Wrap|Line Numbers
  1. <DllImport("user32.dll", EntryPoint:="SystemParametersInfoA", SetLastError:=True, _
  2.                CharSet:=CharSet.Ansi, ExactSpelling:=True, _
  3.                CallingConvention:=CallingConvention.StdCall)> _
  4.     Private Function SystemParametersInfoGet(ByVal uiAction As SPI_INDEX, ByVal uiParam As UInteger, _
  5.                                           ByRef lpenabled As Boolean, ByVal fWinIni As UInteger) As Boolean
  6.     End Function
  7.     <DllImport("user32.dll", EntryPoint:="SystemParametersInfoA", SetLastError:=True, _
  8.                CharSet:=CharSet.Ansi, ExactSpelling:=True, _
  9.                CallingConvention:=CallingConvention.StdCall)> _
  10.     Private Function SystemParametersInfoSet(ByVal uiAction As SPI_INDEX, ByVal uiParam As UInteger, _
  11.                                           ByVal lpenabled As Boolean, ByVal fWinIni As UInteger) As Boolean
  12.     End Function
  13.  
  14.     Public Function SlideOpenComboBoxes(ByVal TurnOn As Boolean) As Boolean
  15.         Dim fResult As Boolean
  16.         Dim spValue As UInteger
  17.         Dim originalMaskOn As Boolean
  18.  
  19.         fResult = SystemParametersInfoGet(SPI_INDEX.SPI_GETCOMBOBOXANIMATION, 0, originalMaskOn, SPFIPersistance_INDEX.SPFI_NONE)
  20.         Dim oWin32Ex As New Win32Exception()
  21.         If fResult Then
  22.             If TurnOn <> originalMaskOn Then
  23.                 fResult = SystemParametersInfoSet(SPI_INDEX.SPI_SETCOMBOBOXANIMATION, 0, TurnOn, SPFIPersistance_INDEX.SPFI_NONE)
  24.                 oWin32Ex = New Win32Exception()
  25.             End If
  26.         End If
  27.         If Not fResult Then
  28.             Throw oWin32Ex
  29.         End If
  30.         Return originalMaskOn
  31.     End Function
  32. End Module
I noticed 2 difference in the code snippets provided from the previous article compared to my solution above:
  1. The first was the order of calling the parameters. I passed the variable I want to get or set into the call to the api as the third parameter. The previous article had Return = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, lActiveFlag, 0, 0), so maybe the order is incorrect if I am not mistaken.
  2. The other difference is I have two references to the api declaration, one for getting and the other for setting. The difference is use of ByVal (for setting) versus ByRef (for Getting) for the third parameter.
My solution was purely a trial an error effort I came to after googling and reading enough articles. I wish there was some documentation of the do's and dont's of API calling.

Without giving you my entire code base, if anyone else has experience owner drawing issues where this setting effected your code I would like to hear about your short comings and thus your work arounds and solutions to your issues.
Jul 27 '11 #1
Share this Article
Share on Google+