Solved

Set wallpaper

Posted on 2002-03-14
6
200 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
Comment Utility
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
Comment Utility
but the SystemParametersInfo API changes the wallpaper on all MS operating systems
0
 
LVL 12

Expert Comment

by:pjknibbs
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:adam8
Comment Utility
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
Comment Utility
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
Comment Utility
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now