Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tiling Desktop Wall Paper 1

Status
Not open for further replies.

ShaneBrennan

Programmer
May 19, 1999
198
GB
Does anyone know how to make VB switch between tile and center the desktop wall paper.

I can set wallpaper image no problem - but I need to switch between centre and tile, depending on the type, size and user preferences.

Thanks for any help

Shane.
Shane Brennan
Shane.Brennan@tcat.ac.uk

 
I was researching this the other day. There are no "tile" or "stretch" attributes in the Windows desktop background API calls. I think you actually have to build a desktop-sized bitmap file and fill it with the tiled (or stretched) images yourself, then use that to set your wallpaper.

Or, it might be that it's there in the API, and I'm just not finding it. Rick Sprague
 
Hi RickSpr.

I've found a way to do it! well one of the bits anyways.

The centre/tile facility is set in the registery.

I got the following code from another website - can't remember which one - but it was there :)

--------------------------------------
Create a module and place the following code in it:

' -------------------
' Registery Constants
' -------------------
'
Private Const SPIF_UPDATEINIFILE = &H1
Private Const SPIF_SENDWININICHANGE = &H2
Global Const REG_SZ = 1

Public Enum REG_TOPLEVEL_KEYS
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_CONFIG = &H80000005
HKEY_CURRENT_USER = &H80000001
HKEY_DYN_DATA = &H80000006
HKEY_LOCAL_MACHINE = &H80000002
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_USERS = &H80000003
End Enum

' Registery Manipulation Functions
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 RegCloseKey Lib "advapi32.dll" (ByVal Hkey 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

' ---------------------------------------------------------
' The private procedure to change/create registery settings
' ---------------------------------------------------------
'
Private Function WriteStringToRegistry(Hkey As REG_TOPLEVEL_KEYS, strPath As String, _
strValue As String, strdata As String) As Boolean

Dim bAns As Boolean

On Error GoTo ErrorHandler
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
If r = 0 Then
r = RegSetValueEx(keyhand, strValue, 0, _
REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand)
End If

WriteStringToRegistry = (r = 0)

Exit Function

ErrorHandler:
WriteStringToRegistry = False
Exit Function

End Function

' ------------------------------------------------------
' The 2 public functions to Tile & Centre the wallpaper.
' ------------------------------------------------------
'
Public Function TileBackground()
WriteStringToRegistry HKEY_CURRENT_USER, "Control Panel\desktop", "TileWallpaper", "1"
End Function

Public Function CentreBackground()
WriteStringToRegistry HKEY_CURRENT_USER, "Control Panel\desktop", "TileWallpaper", "0"
End Function

'----------------------------------------------------------

To use tile or centre the background simply use:

CentreBackground or TileBackground in your code.

Shane






Shane Brennan
Shane.Brennan@tcat.ac.uk

 
Doh! I thought there was a way to do it--that's why I was researching it. I just totally forgot about the registry. (It used to be in Win.INI--I remember seeing it there in Windows 3.1.) Good work, Shane! Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top