Solved

Set wallpaper

Posted on 2002-03-14
6
221 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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 50 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 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