Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Set wallpaper

Posted on 2002-03-14
6
Medium Priority
?
266 Views
Last Modified: 2010-05-02
Hi,
I am currently using the SystemParametersInfo API to set my wallpaper. How can I use an alternative that will  work on all operating system but I can specify how the wallpaper is changed.

For exmaple, centered, stretched, tiled.

Thanks
0
Comment
Question by:adam8
  • 2
  • 2
  • 2
6 Comments
 
LVL 12

Expert Comment

by:pjknibbs
ID: 6864401
There is no alternative that will work on all operating systems because all operating systems have different APIs--therefore you could not use the same code to set the wallpaper on a Mac as you would on a Windows PC.
0
 
LVL 1

Author Comment

by:adam8
ID: 6867365
but the SystemParametersInfo API changes the wallpaper on all MS operating systems
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 6867499
You didn't specify all MS operating systems, just all operating systems.

Anyway, the only way to set whether wallpaper is tiled or not (without using certain COM interfaces which were only included in Internet Explorer 4.0 and later, and which therefore wouldn't work on all MS operating systems) is to edit the Registry. The key HKEY_CURRENT_USER\Control Panel\Desktop\TileWallpaper should be set to 1 to tile the wallpaper or 0 to centre it--not sure what you'd need to do to stretch it, though.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:adam8
ID: 6867852
obviously you wouldn't be running visual basic apps on Linux or OS/2    :-)

I thought there might be a simple way to set it
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 6868057
To stretch the wallpaper:

HKEY_CURRENT_USER\Control Panel\Desktop\WallpaperStyle should be set at 2.

If the above does not exist just create a new string value under HKEY_CURRENT_USER\Control Panel\Desktop and call it WallpaperStyle. Then set the value to 2.

0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 200 total points
ID: 6868137
I think all you need is to set the WallpaperStyle string in the registry.It appears to overide the TileWallpaper string.Just keep in mind you will have to use the SystemParamtersInfo API AFTER using the code below to change your settings other wise they will not be reflected.


Option Explicit
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Const HKEY_CURRENT_USER = &H80000001
Private Const ERROR_SUCCESS = 0&
Private Const REG_SZ = 1
Private X As Long
Private Sub SaveString(Hkey As Long, strpath As String, strValue As String, strdata As String)
    Dim keyhand As Long
    Dim r As Long
    X = RegCreateKey(Hkey, strpath, keyhand)
    X = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
    X = RegCloseKey(keyhand)
End Sub

Private Sub Command1_Click()
' this will center the wallpaper
Call SaveString(HKEY_CURRENT_USER, "Control Panel\Desktop", "WallpaperStyle", "0")
End Sub

Private Sub Command2_Click()
' this will tile the wallpaper
Call SaveString(HKEY_CURRENT_USER, "Control Panel\Desktop", "WallpaperStyle", "1")
End Sub

Private Sub Command3_Click()
' this will stretch the wallpaper
Call SaveString(HKEY_CURRENT_USER, "Control Panel\Desktop", "WallpaperStyle", "2")
End Sub


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

926 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