Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set wallpaper

Posted on 2002-03-14
6
Medium Priority
?
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses

721 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