|
-
September 15th, 2008, 12:49 AM
#1
Background Switcher
So i currently have this background switcher that works. Thing is, what's supposed to center it in the screen actually tiles it and i don't know why. Ultimately, i'd like to be able to have a separate picture for each monitor, but that's not really necessary. So my question is two fold: One, why doesn't the line indicated below center the background and what should I do instead and two, how do i go about even starting to have two separate pictures, one for each monitor, at the same time with each centered based on the monitor their on. This is important because I have two monitors that are different sizes and something centered in a 1440x900 resolution won't be centered correctly in a 1024x768 resolution.
Code:
Public Class settings
Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
Dim Pics As New List(Of String)
Private Sub settings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TimeUnit.SelectedIndex = 1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TFPath As String
FolderBrowserDialog1.ShowDialog()
TFPath = FolderBrowserDialog1.SelectedPath
Try
Dim DInfo As System.IO.DirectoryInfo = System.IO.Directory.GetParent(TFPath)
Dim ER As String = DInfo.Name
Change_Wallpaper(ER)
Catch ex As Exception
If System.IO.Directory.Exists(TFPath) = True Then
Change_Wallpaper(TFPath)
Else
MsgBox("Error: Directory " & TFPath & " doesn't exist!", MsgBoxStyle.Critical, "Error")
End If
End Try
End Sub
Private Sub Change_Wallpaper(ByVal Path As String)
Dim TStor As String()
TStor = System.IO.Directory.GetFiles(Path, "*.*")
For Each hold As String In TStor
Pics.Add(hold)
Next
Pics.Sort()
Microsoft.Win32.Registry.SetValue("HKEY_CURRENT_USER\Control_ Panel\Desktop", "WallpaperStyle", 3, Microsoft.Win32.RegistryValueKind.String)
My.Settings.WeAreOn = 1
SystemParametersInfo(20, 3, Pics(0), &H1)
End Sub
Private Sub Next_wallpaper()
If My.Settings.WeAreOn >= Pics.Count Then
My.Settings.WeAreOn = 0
SystemParametersInfo(20, 0, Pics(My.Settings.WeAreOn), &H1)
Else
SystemParametersInfo(20, 0, Pics(My.Settings.WeAreOn), &H1)
End If
My.Settings.WeAreOn += 1
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Pics.Count <> 0 Then
Next_wallpaper()
End If
End Sub
Private Sub TimeUnit_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimeUnit.SelectedIndexChanged
Dim FinalTime As Integer = 0
If TimeUnit.SelectedItem = "Minutes" Then
FinalTime = (60 * TimeInt.Text) * 1000
Timer1.Stop()
Timer1.Interval = FinalTime
Timer1.Start()
ElseIf TimeUnit.SelectedItem = "Seconds" Then
FinalTime = TimeInt.Text * 1000
Timer1.Stop()
Timer1.Interval = FinalTime
Timer1.Start()
ElseIf TimeUnit.SelectedItem = "Hours" Then
FinalTime = ((60 * 60) * TimeInt.Text) * 1000
Timer1.Stop()
Timer1.Interval = FinalTime
Timer1.Start()
End If
End Sub
Private Sub TimeInt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimeInt.TextChanged
Dim FinalTime As Integer = 0
If TimeUnit.SelectedItem = "Minutes" Then
FinalTime = (60 * TimeInt.Text) * 1000
Timer1.Stop()
Timer1.Interval = FinalTime
Timer1.Start()
ElseIf TimeUnit.SelectedItem = "Seconds" Then
FinalTime = TimeInt.Text * 1000
Timer1.Stop()
Timer1.Interval = FinalTime
Timer1.Start()
ElseIf TimeUnit.SelectedItem = "Hours" Then
FinalTime = ((60 * 60) * TimeInt.Text) * 1000
Timer1.Stop()
Timer1.Interval = FinalTime
Timer1.Start()
End If
End Sub
End Class
This line was what I hacked together for center:
Code:
Microsoft.Win32.Registry.SetValue("HKEY_CURRENT_USER\Control_ Panel\Desktop", "WallpaperStyle", 3, Microsoft.Win32.RegistryValueKind.String)
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1
-
September 16th, 2008, 02:21 AM
#2
Re: Background Switcher
You can use the FileWatcher() class, which fires when a folder changes.
Also, one screen is added to the other, so try adding the width's
-
September 16th, 2008, 10:18 AM
#3
Re: Background Switcher
Okay, so how do i get the width's of the two screens?
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1
-
September 16th, 2008, 07:01 PM
#4
-
September 17th, 2008, 11:19 AM
#5
Re: Background Switcher
So will this allow me to center the pictures based on both screen's resolution? I've seen things that do it. Also, how do I even go about centering the desktop background in code? I've tried the registry but that didn't work at all.
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1
-
September 17th, 2008, 01:55 PM
#6
Re: Background Switcher
Strange problem. so i found some code and actually got it to work good, but now I have another small problem. It works in so much as it will set the registry value, but the desktop won't update itself to reflect that new value unless i go to background settings. When I do that, it automatically adjusts itself to be whatever value I put in, such as 2 for fit to screen. how can i update the desktop to reflect the new value through vb.net?
Code:
Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Public Class Form1
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function SystemParametersInfo(ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SystemParametersInfo(20, 0, "C:\users\cooper\pictures\backgrounds\3.jpg", 1 Or 2)
Dim rkWallPaper As RegistryKey = Registry.CurrentUser.OpenSubKey("Control Panel\Desktop", True)
rkWallPaper.SetValue("WallpaperStyle", 2, RegistryValueKind.String)
rkWallPaper.SetValue("TileWallpaper", 0, RegistryValueKind.String)
rkWallPaper.Close()
End Sub
End Class
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1
-
September 18th, 2008, 12:52 AM
#7
Re: Background Switcher
The problem is that you call SystemparametersInfo before editing the registry, rather have it that SystemparametersInfo is called after the modifications to the registry. I'm actually surprised that you did get a picture, because as I recall, systemparametersInfo only works with bmp images.
Will the paper always be centered ¿ As you have finally realised, you need 2 settings ( WallpaperStyle and TileWallpaper ) - to allow for the other settings, you can do :
Code:
Select Case WPStyle 'What Style Was Chosen ¿
Case 1 'Tile
WallStyleReg.SetValue("TileWallpaper", "1")
WallStyleReg.SetValue("WallpaperStyle", "0")
Case 2 'Center
WallStyleReg.SetValue("TileWallpaper", "0")
WallStyleReg.SetValue("WallpaperStyle", "0")
Case 3 'Stretch
WallStyleReg.SetValue("TileWallpaper", "0")
WallStyleReg.SetValue("WallpaperStyle", "2")
End Select
I've also sometimes encountered a problem where the wallpaper didn't apply immediately, so you may need to call SystemParametersInfo twice.
How to do all these, is explained in this article :
http://www.codeguru.com/vb/gen/vb_mi...le.php/c14139/
It is in VB.NET 2003 though, but still compatibel with the newer versions 
For dual monitors, have a look here :
http://www.codeguru.com/forum/showth...t=dual+monitor
and
http://blogs.msdn.com/coding4fun/arc...2/5246528.aspx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|