Microsoft KB Archive/315615

= HOW TO: Change the Windows Desktop Bitmap by Using Visual J++ =

Article ID: 315615

Article Last Modified on 10/26/2002

-

APPLIES TO


 * Microsoft Visual J++ 6.0 Standard Edition

-



This article was previously published under Q315615





IN THIS TASK
SUMMARY
 * Requirements
 * How to Declare SystemParametersInfo
 * How to Use SystemParametersInfo
 * Troubleshooting



SUMMARY
This article explains how to use Visual J++ to change the Windows desktop background to an arbitrary bitmap.

back to the top

Requirements

 * A Microsoft Windows 95, Microsoft Windows 98, Microsoft Windows Millennium Edition (Me), Microsoft Windows NT, Microsoft Windows 2000, or Microsoft Windows XP-based system.


 * Familiarity with the principles of Visual J++ programming in the Windows environment, and with using Microsoft J/Direct Call Builder.

back to the top

How to Declare SystemParametersInfo
The Windows API provides a function called SystemParametersInfo. This function has a number of features, including a way to set the desktop bitmap. Before this API function can be incorporated into a Visual J++ application, you need to define a prototype for it by using J/Direct Call Builder. To do this, follow these steps:  In the Visual J++ development environment, click Other Windows on the View toolbar, and then click J/Direct Call Builder. Type SystemParametersInfo in the Find field.  Copy the generated code into your Java source file. It should look similar to the following: /** @dll.import(&quot;USER32&quot;,auto) */ public static native boolean SystemParametersInfo(int uiAction,int uiParam,int[] pvParam,int fWinIni);   The third parameter in this prototype for SystemParametersInfo, pvParam, is declared as int[]. However, this parameter actually takes different data types, depending on the value of the uiAction parameter. When you change the desktop background, pvParam should be declared as a String to ensure that Visual J++ marshals the data correctly. Edit pvParam to make it of type String: /** @dll.import(&quot;USER32&quot;,auto) */ public static native boolean SystemParametersInfo(int uiAction,int uiParam,String pvParam,int fWinIni); 

back to the top

How to Use SystemParametersInfo
Having created a correct prototype, you can use the SystemParametersInfo function in your Visual J++ application, as in the following sample code: int nAction = com.ms.win32.win.SPI_SETDESKWALLPAPER; String strBMP = &quot;c:\\winnt\\Blue Lace 16.bmp&quot;; int nSaveChange = 0; SystemParametersInfo(nAction,0,strBMP,nSaveChange); NOTE: The SystemParametersInfo API works only for Windows Bitmap (.bmp) files.

back to the top

Troubleshooting
After you use the preceding methods, you will notice that you cannot change the way in which the wallpaper bitmap is displayed on the desktop (centered or tiled). You must edit the registry to switch (toggle) between the centered and tiled wallpaper options.

Navigate to the following registry key:

HKEY_CURRENT_USER\Control Panel\Desktop\TileWallpaper

Set the value to 1 to tile the wallpaper, or to 0 to center the wallpaper.

For more information about how to access the Windows registry from within a Visual J++ application, see the WFC registry tutorial at the following Microsoft Web site:

http://msdn.microsoft.com/visualj/technical/tutorial/wfcregistry/default.asp

back to the top

Keywords: kbhowto kbhowtomaster kbinfo KB315615

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.