Solved

SystemParametersInfo problem

Posted on 2004-03-22
10
565 Views
Last Modified: 2007-12-19
I am attempting to enable/disable the ClickLock accessibility option using the SystemParametersInfo API function.  The problem I am having is that no matter what I put in uiParam and pvParam, I it enables ClickLock (I test it with SPI_GETMOUSECLICKLOCK and by looking in the Mouse properties in Control Panel).

Here's an example; this is how I thought it should work based on MSDN:

retval = SystemParametersInfo(SPI_SETMOUSECLICKLOCK, False, 0, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)

but that ENABLES it, which makes no sense.  I made a huge function that would try every combination of 1, 0, true, false, boolean vars, integer vars, and every single one enables the feature.  I hope that I'm just doing something wrong, and not that it is impossible to do because of a bug or something.  

I am using Windows XP (the feature is supposed to work in XP and ME).  Here is the MSDN page I have been using as a reference http://msdn.microsoft.com/library/en-us/sysinfo/base/systemparametersinfo.asp

Any help is very appreciated!
0
Comment
Question by:brianbugh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10652042
What are the constants for SPI_SETMOUSECLICKLOCK, SPIF_SENDWININICHANGE and SPIF_UPDATEINIFILE?
0
 

Author Comment

by:brianbugh
ID: 10652114
Ah, sorry.

Private Const SPI_GETMOUSECLICKLOCK = 4126
Private Const SPI_GETMOUSECLICKLOCKTIME = 8200

Private Const SPI_SETMOUSECLICKLOCK = 4127
Private Const SPI_SETMOUSECLICKLOCKTIME = 8201

Private Const SPIF_SENDWININICHANGE = &H2
Private Const SPIF_UPDATEINIFILE = &H1
0
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10652267
:)
Use this:

retVal = SystemParametersInfo(SPI_SETMOUSECLICKLOCK, False, ByVal &H0, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)

Note the "little" change :)
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:brianbugh
ID: 10652338
Well, that disables it, but replacing "False" with "True" doesn't turn it back on.  I need something I can put in a variable (from a checkbox) that will turn on/off.

Getting closer I think..
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10652397
ByVal &H0 is for Enabling/Disabling. Hex 0 = Disable, Hex 1 = Enable (Boolean values). Try &H1 to enable it
0
 
LVL 6

Accepted Solution

by:
___XXX_X_XXX___ earned 125 total points
ID: 10652418
But you must change not False,True parameter. You must change ByVal parameter ! Like this:

Dim retVal As Long
Dim lngOnOff As Long

lngOnOff = CLng(Check1.Value) ' Suppose that you have Check1 check box
retVal = SystemParametersInfo(SPI_SETMOUSECLICKLOCK, False, ByVal lngOnOff, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
0
 

Author Comment

by:brianbugh
ID: 10652431
Correct, however, I said I need something to put in a variable.  I can easily make a switch statement that uses &H0 and &H1 but I don't want to do that, I want to do it right :)

I do have it working like this:

    Select Case mbEnabled
        Case True
            retval = SystemParametersInfo(SPI_SETMOUSECLICKLOCK, 0, True, 0)
        Case False
            retval = SystemParametersInfo(SPI_SETMOUSECLICKLOCK, 0, ByVal 0&, 0)
        Case Else
            MsgBox "error in SetEnabled"
    End Select

but if I put in "False" instead of the ByVal &H0 it will not work.  I'm running into this problem with another API call - how do I send a variable ByVal when it expects ByRef?  "ByVal myVar" doesn't work.
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10652473
You can change the function.. quick example:

Option Explicit

Private Declare Function SystemParametersInfoLong Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Long, ByVal fuWinIni As Long) As Long

Private Const SPI_GETMOUSECLICKLOCK = 4126
Private Const SPI_GETMOUSECLICKLOCKTIME = 8200

Private Const SPI_SETMOUSECLICKLOCK = 4127
Private Const SPI_SETMOUSECLICKLOCKTIME = 8201

Private Const SPIF_SENDWININICHANGE = &H2
Private Const SPIF_UPDATEINIFILE = &H1
Private Sub MouseSetClickLock(ByVal bEnable As Boolean)
    Call SystemParametersInfoLong(SPI_SETMOUSECLICKLOCK, False, ByVal bEnable, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
End Sub
Private Sub Form_Load()
    Call MouseSetClickLock(True)
End Sub
Private Sub Form_Unload(Cancel As Integer)
    Call MouseSetClickLock(False)
End Sub
0
 

Author Comment

by:brianbugh
ID: 10652478
XXX_X_XXX:  OK, I got it now.  For some reason when I did "ByVal variable" it was giving me an error.  I guess that the two times I tried it, I must have left off "As Long" on my test variable.  Always something stupid :)

Thanks a lot for the help, that clears up the current problem and a couple others.
0
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10652481
Hah :)
Just use this:

Instead of Select Case with "Case True","Case False" and "Case Else" ?!?!??! use this:

 ' Suppose that you will pass to this subroutine/function boolean parameter named mbEnabled:


Dim lngOnOff As Long
Dim retVal As Long

lngOnOff=Clng(mbEnabled) AND &H1
retVal = SystemParametersInfo(SPI_SETMOUSECLICKLOCK, False, ByVal lngOnOff, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE




So, no need of these Select case statements.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month5 days, 2 hours left to enroll

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question