Solved

Set wallpaper

Posted on 2002-03-14
6
211 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now