How to Use SystemParametersInfo API for Control Panel Settings

만료된 KB 콘텐츠 고지 사항

이 문서는 Microsoft에서 더 이상 지원하지 않는 제품에 대해 작성되었습니다. 따라서 이 문서는 “있는 그대로" 제공되며 더 이상 업데이트되지 않습니다.

Summary

The SystemParametersInfo API call can be used to get and set Windows settings that are normally set from the Desktop by using the Control Panel.

More Information

You can call the SystemParametersInfo API to set and get all the settings controlled by the Windows Control Panel. Normally a user would have to choose the Windows Control Panel to view or change system settings such as granularity, wallpaper, or icon title wrap. Instead of forcing the user to set things manually using the Control Panel you can have your program call the SystemParametersInfo API to set them automatically.


Use the following Visual Basic for Windows Declare for the API. Enter it all as one, single line:

   Declare Function SystemParametersInfo Lib "User" (ByVal uAction
As Integer, ByVal uparam As Integer, lpvParam As Any, ByVal fuWinIni
As Integer) As Integer

Here are the formal arguments to the function:


uAction system parameter to query or set
uParam depends on system parameter
lpvParam depends on system parameter
fuWinIni WIN.INI update flag

The uAction argument can be one of the following constants:


CONST SPI_GETBEEP=1
CONST SPI_SETBEEP=2
CONST SPI_GETMOUSE=3
CONST SPI_SETMOUSE=4
CONST SPI_GETBORDER=5
CONST SPI_SETBORDER=6
CONST SPI_GETKEYBOARDSPEED=10
CONST SPI_SETKEYBOARDSPEED=11
CONST SPI_LANGDRIVER=12
CONST SPI_ICONHORIZONTALSPACING=13
CONST SPI_GETSCREENSAVETIMEOUT=14
CONST SPI_SETSCREENSAVETIMEOUT=15
CONST SPI_GETSCREENSAVEACTIVE=16
CONST SPI_SETSCREENSAVEACTIVE=17
CONST SPI_GETGRIDGRANULARITY=18
CONST SPI_SETGRIDGRANULARITY=19
CONST SPI_SETDESKWALLPAPER=20
CONST SPI_SETDESKPATTERN=21
CONST SPI_GETKEYBOARDDELAY=22
CONST SPI_SETKEYBOARDDELAY=23
CONST SPI_ICONVERTICALSPACING=24
CONST SPI_GETICONTITLEWRAP=25
CONST SPI_SETICONTITLEWRAP=26
CONST SPI_GETMENUDROPALIGNMENT=27
CONST SPI_SETMENUDROPALIGNMENT=28
CONST SPI_SETDOUBLECLKWIDTH=29
CONST SPI_SETDOUBLECLKHEIGHT=30
CONST SPI_GETICONTITLELOGFONT=31
CONST SPI_SETDOUBLECLICKTIME=32
CONST SPI_SETMOUSEBUTTONSWAP=33
CONST SPI_SETICONTITLELOGFONT=34
CONST SPI_GETFASTTASKSWITCH=35
CONST SPI_SETFASTTASKSWITCH=36

The UParam argument should be 0 when used with a GET constant, and it should contain the new value of the setting when used with a SET constant. The exceptions to these rules are documented in the Windows version 3.1 Software Development Kit (SDK) help file.


When used with a GET constant, the lpvParam argument returns the current value of the setting. When used with a SET constant, it is a NULL. The exceptions to these rules are documented in the Windows version 3.1 SDK help file.


The fuWinIni argument updates the WIN.INI file:

   Const SPIF_SENDWININICHANGE = &H2
Const SPIF_UPDATEINIFILE = &H1

Example One

One exception to the rules given above occurs with a call to set or get the icon spacing setting. The following example gives the correct arguments to use to set and get the horizontal spacing:

  1. Create a Visual Basic project, and add the following controls to a form:

    Control Name Caption
    ----------------------
    Command1 Read
    Command2 Set
    Text1
    Label1 Icon Horizontal Spacing

  2. Add the following code to the general declarations section of the form:
       Const SPIF_SENDWININICHANGE = &H2
    Const SPIF_UPDATEINIFILE = &H1
    Const SPI_ICONHORIZONTALSPACING = 13
    Dim uAction As Integer
    Dim uparam As Integer
    ' Enter the following Declare as one, single line:
    Declare Function SystemParametersInfo Lib "User" (ByVal uAction As
    Integer, ByVal uparam As Integer, lpvParam As Any, ByVal fuWinIni As
    Integer) As Integer

  3. Add the following code to the Command1_Click event:

    uAction = 0
    uparam = 0
    ret% = SystemParametersInfo(SPI_ICONHORIZONTALSPACING, uAction,
    uparam, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
    text1.Text = uparam

  4. Add the following code to the Command2_Click event:
       uAction = Val(text1.Text)
    uparam = 0
    ' Enter the following as one, single line:
    x% = SystemParametersInfo(SPI_ICONHORIZONTALSPACING, uAction,
    ByVal 0&, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)

  5. Run the program, and click the Read button. The current setting of the icon horizontal spacing will be displayed in the Text1 box. Enter a new number(32 is the lowest setting accepted) in the Text1 box, and click the Read button. The spacing will be reset. To see the new setting, bring up the Windows Task list, and choose Arrange Icons.

Example Two

The example follows the general parameter rules. It demonstrates how to turn icon title wrapping on and off by using SETICONTITLEWRAP.

  1. Create a Visual Basic project and add the following controls to a form:

    Control Name Caption
    -----------------------------
    Command1 Wrapping True
    Command2 Wrapping False

  2. Add the following code to the general declarations section of the form:
       ' Enter the following Declare as one, single line:
    Declare Function SystemParametersInfo Lib "User" (ByVal uAction As
    Integer, ByVal uparam As Integer, lpvParam As Any, ByVal fuWinIni As
    Integer) As Integer
    Const SPI_SETICONTITLEWRAP = 26
    Const SPIF_SENDWININICHANGE = &H2
    Const SPIF_UPDATEINIFILE = &H1

  3. Add the following code to the Command1 Click event:
       ' Enter the following as one, single line:
    x% = SystemParametersInfo(SPI_SETICONTITLEWRAP, True, 0&,
    SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)

  4. Add the following code to the Command2 Click event:
       ' Enter the following as one, single line:
    x% = SystemParametersInfo(SPI_SETICONTITLEWRAP, False, 0&,
    SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)

  5. Run the program and watch the icon titles as you click the two buttons.

Example Three

This example follows the general parameter rules. It demonstrates how to change your desktop's wallpaper with the SPI_SETDESKWALLPAPER.

  1. Create a Visual Basic project and add the following controls to a form:

    Control Name Caption
    -----------------------------
    Command1 Change Wallpaper to Rivets

  2. Add the following code to the general declarations section of the form:
       Const SPIF_UPDATEINIFILE = &H1
    Const SPI_SETDESKWALLPAPER = 20
    Const SPIF_SENDWININICHANGE = &H2

    ' Enter the following Declare as one, single line:

    Declare Function SystemParametersInfo Lib "User" (ByVal uAction As
    Integer, ByVal uparam As Integer, ByVal lpvParam As String, ByVal
    fuWinIni As Integer) As Integer

  3. Add the following code to the Command1 Click event:
       Sub Command1_Click ()
    filenm$ = "C:\Windows\rivets.bmp"

    ' Enter the following two lines as one, single line:
    x% = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&,
    filenm$, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
    End Sub

  4. Run the program and watch the wallpaper change to RIVETS.BMP.
속성

문서 ID: 97142 - 마지막 검토: 2007. 10. 26. - 수정: 1

피드백