HOW TO: Change the Windows Desktop Bitmap by Using Visual J++ (315615)



The information in this article applies to:

  • Microsoft Visual J++ 6.0

This article was previously published under Q315615

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:
  1. In the Visual J++ development environment, click Other Windows on the View toolbar, and then click J/Direct Call Builder.
  2. Type SystemParametersInfo in the Find field.
  3. Copy the generated code into your Java source file. It should look similar to the following:
    /** @dll.import("USER32",auto) */ 
    public static native boolean SystemParametersInfo(int uiAction,int uiParam,int[] pvParam,int fWinIni);
    					
  4. 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("USER32",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 = "c:\\winnt\\Blue Lace 16.bmp";
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: back to the top

Modification Type:MajorLast Reviewed:10/26/2002
Keywords:kbhowto kbHOWTOmaster kbinfo KB315615 kbAudDeveloper