Instructions
Windows7 ™, VS11™ Beta, VB11™ Beta. This is for Windows7 ™ only. This program will be obsolete in Windows 8™
as users will be able to do this without this program. So for now this program is for Windows7 ™ users ONLY. This needs to be RunAs ADMIN
because of the Registry entries. If you are not an ADMIN or you do not have ADMIN RIGHTS, then this app will display a message
to you to apply RunAs admin rights, and then the app will exit gracefully or in other words Shutdown.
Intro
This is a visual style paper hanger (changer) that can change the Logon User Interface background and it can change your Desktop wallpaper.
I added a file compression panel so you can compress some JPEGs to a suitable size (<= 256
KB) as Windows7 ™
does not use a pic that is greater than 256 KB for the LogonUI background. You can select a background pic for the LogonUI by clicking on a thumbnail
in the DataGridView
control at the top of the form. Then click Apply. The first thumbnail in the DatagridView
is the Default Background that Windows7 ™ uses. The second thumbnail is the currently used pic.
These two will always be the first and second (respectively) in the DatagridView
and the rest of the pics that are less than or equal to 256
KB (DESIRED_SIZE
).
DESIRED_SIZE
is a constant that is equal to 262144 (256 KB). This is used to check all images that are loaded in the grid. If larger, then they are skipped.
Background
The background for this idea came from
Mr. Wolfy version: Best VB.NET article January 2010
and Julien Manici's WPF Version which
are awesome. My version imitates Julien's except I used WinForms and the
VS IDE Toolbox Standard Components. I have been using my app for better than a year now and decided to post it. This app however was created in VS11 beta, VB11 beta.
I will be posting downloads for VB9.0 and VB10. They are all pretty much the same except for the designs.
Julien's app has some nice effects (MotionCircles animation) and (On-The-Fly) file compression (for
JPEGs only) which I thought was excellent. Mine has file compression,
but we do it manually. It has the look and feel of PS CS3's file compression. Before we can compress our files, we need to give the file a name to save as.
I just add the letter "a" to the selected pic's name. This works fairly well for me.
Code for the file compression...
Private Sub DoImageCompression()
If txtSaveAsJpeg.Text = "" Then
MessageBox.Show("Please fill in the 'Save As *.jpg' Text box " & _
"with '.jpg' at the end.", "Textbox err", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Dim bmpToJpeg As New Bitmap(lstImages.SelectedItem.ToString())
Dim file_size As Long
Dim compression_level As Long = CType(tbSize.Value, Long)
Dim memory_stream As MemoryStream = _
SaveJpegIntoStream(bmpToJpeg, _
compression_level)
file_size = memory_stream.Length
lblFileSize.Text = "File Size : " & _
Math.Round((file_size / 1024), 2).ToString & " kb"
txtTBValue.Text = tbSize.Value.ToString()
If isSaveAsButtonClicked = False Then
bmpToJpeg.Dispose()
memory_stream.Dispose()
Exit Sub
End If
If file_size <= DESIRED_SIZE Then
My.Computer.FileSystem.WriteAllBytes(mySaveLocation & txtSaveAsJpeg.Text, _
memory_stream.ToArray(), False)
picAfter.ImageLocation = mySaveLocation & txtSaveAsJpeg.Text
MessageBox.Show("File saved!...")
bmpToJpeg.Dispose()
memory_stream.Dispose()
btnSaveAs.Enabled = False
isSaveAsButtonClicked = False
End If
End Sub
When we are dragging the trackbar, on the MouseUp
event, the suggested size shows in the text box below the trackbar.
You need to do this a few times until you are close to 256 KB as possible without going over the DESIRED_SIZE
. Once you get what you want,
your pic is displayed next to the original on the left side, compressed file on the right.
I decided to add the Standard Wallpaper changer as this is a paper hanger.
Using the code
To set our standard wallpaper, we need to add some pics to our listbox. *.bmps used to be the standard with MS but this changed when Windows Vista came out.
Now we can select from a vast array of wallpaper pics, *.bmp,*.jpg,*.png, and so on.
Setting and saving our wallpaper...
Private Sub SetWallpaper(ByVal img As Image)
imageLocation = My.Computer.FileSystem.CombinePath(_
My.Computer.FileSystem.SpecialDirectories.MyPictures, WallpaperPath)
picStandardWP.ImageLocation = imageLocation
If imageLocation.EndsWith(".bmp") Then
img.Save(imageLocation, System.Drawing.Imaging.ImageFormat.Bmp)
ElseIf imageLocation.EndsWith(".jpg") Then
img.Save(imageLocation, System.Drawing.Imaging.ImageFormat.Jpeg)
ElseIf imageLocation.EndsWith(".png") Then
img.Save(imageLocation, System.Drawing.Imaging.ImageFormat.Png)
End If
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, imageLocation, _
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
End Sub
First Time Run and Loading
When first running the The Paper Hanger, if it does not have Admin rights, then
it will display a message stating this fact and let you know that it will shutdown
after which you can do the right_click thing and add "RunAs admin" under the
Security tab. Here is the code that does this....
Private Sub frmPaperHanger_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim myPrincipal As WindowsPrincipal = _
CType(System.Threading.Thread.CurrentPrincipal, WindowsPrincipal)
If (myPrincipal.IsInRole(WindowsBuiltInRole.Administrator) = True) Then
pnlLogonUI.Location = New Point(96, 179)
pnlLogonUI.Show()
pnlStandardWallpaper.Location = ptStandardWP
pnlStandardWallpaper.Hide()
pnlOptions.Location = ptOptions
pnlOptions.Hide()
pnlCompressFiles.Location = ptCompressionFiles
pnlCompressFiles.Hide()
pnlAbout.Location = ptAbout
pnlAbout.Hide()
LoadAndInitialize()
End If
Catch ex As Exception
MessageBox.Show("The Program does not currently have (runas admin) " & _
"permission. Please set this.", "UAC Permission Needed", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Application.Exit()
End Try
Points of Interest
History
- Uploaded The Paper Hanger: 04·20·2012.