Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / April 2007

Tip: Looking for answers? Try searching our database.

setting wallpaper style in vb.net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick Dugan - 07 Apr 2007 17:35 GMT
The code below is what i have been *trying* to use to set the desktop
wallpaper picture and the Wallpaper style.  The picture gets replaced
with the new image each time, but the style never changes.

Whatever it is set to in the "Display Properties > Desktop" is where is
stays and the code below does not seem to effect it.  The registry
entries ARE getting changed but it does not actually apply the new
style.  I have tried two different registry entries (The other is
currently remmed out) and I have even tried both at the same time.  The
style never gets applied.  The return code is always true and the
registry entries do get changed.

What am i missing?

Private Declare Auto Function SystemParametersInfo Lib "user32.dll"
(ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As
String, ByVal fuWinIni As Integer) As Integer

Private Declare Function GetDesktopWindow Lib "user32" () As Int32

 Friend Sub SetWallpaper(ByVal Filename As String)

        Dim imageLocation As String
        Dim SPI_SETDESKWALLPAPER As Integer = &H14
        Dim SPIF_UPDATEINIFILE As Integer = &H1
        Dim SPIF_SENDWININICHANGE As Integer = &H2

        Dim RegKey2 As RegistryKey

       'RegKey2 =
Registry.CurrentUser.OpenSubKey("Software\Microsoft\Internet
Explorer\Desktop\General", True)

        RegKey2 = Registry.CurrentUser.OpenSubKey("Control
Panel\Desktop", True)
        RegKey2.SetValue("Wallpaper", WallpaperFile)
        Select Case intWindowStyle
             Case 0 ' Centered
                 RegKey2.SetValue("TileWallpaper", 0)
                 RegKey2.SetValue("WallpaperStyle", intWindowStyle)
             Case 1 ' Tiled
                 RegKey2.SetValue("TileWallpaper", 1)
                 RegKey2.SetValue("WallpaperStyle", intWindowStyle)
             Case 2 ' Stretched
                 RegKey2.SetValue("TileWallpaper", 0)
                 RegKey2.SetValue("WallpaperStyle", intWindowStyle)
         End Select

       SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename,
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)

End Sub
Chris Dunaway - 09 Apr 2007 15:34 GMT
> Private Declare Auto Function SystemParametersInfo Lib "user32.dll"
> (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As
[quoted text clipped - 8 lines]
>          Dim SPIF_UPDATEINIFILE As Integer = &H1
>          Dim SPIF_SENDWININICHANGE As Integer = &H2

<snip>

>         SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename,
> SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
>
> End Sub

Hi Patrick!

I'm not sure if this will help, but in the declaration to the
SetParametersInfo method, the parameters are all UINT which, I
believe, is an unsigned 2 byte integer.  In .Net, Integer is 4 bytes.
You might try changing your declaration from Integer to Short and also
on the SPI* declarations too.

Chris
rowe_newsgroups - 09 Apr 2007 15:47 GMT
> The code below is what i have been *trying* to use to set the desktop
> wallpaper picture and the Wallpaper style.  The picture gets replaced
[quoted text clipped - 48 lines]
>
> End Sub

According to pinvoke.net your GetDesktopWindow declaration is wrong.
Try replacing it with "Private Declare Auto Function GetDesktopWindow
Lib "user32.dll" () As IntPtr"

Here's the page:

http://www.pinvoke.net/default.aspx/user32/GetDesktopWindow.html

Thanks,

Seth Rowe

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.