昨天看到How To Geek裡的一篇文章, 裡面有個小程序做得覺得挺有意思, 那個程序可以改變Windows 7的縮略圖大小, 縮略圖與縮略圖之間的距離, 以及上下左右的邊距, 甚至還可以設置鼠標放到任務欄上多久顯示出縮略圖, 系統默認的是400ms, 感覺有點慢, 我把它調成了1, 鼠標一放上去就冒出縮略圖, 感覺非常的爽. 當然這些都是靠更改注冊表完成的.
我把那個程序下載下來, 用Reflector看一下那個程序, 終於知道是什麼原理, 又花了好幾個小時實現了一遍, 當然我寫的代碼肯定沒人家好, 人家是美國的MVP, 我只是個菜鳥:)在這裡把實現過程跟大家分享一下, 有哪些寫的不好的地方, 歡迎指教.
改變縮略圖後的大小(可以在這裡面看電影了, 呵呵):
查看原圖(大圖)
更改縮略圖的X-Spacing和Y-Spacing後(可以看到效果還是很明顯的):
查看原圖(大圖)
程序的核心步驟:
在注冊表目錄HKEY_CURRENT
在注冊表目錄HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced下新建一個鍵: ExtendedUIHoverTime
它用於控制縮略圖顯示的延遲時間(單位是ms)
每次更改完注冊表的信息後, 要看到效果不需要重新開機, 只需要關閉explore.exe, 再重新打開即可.
Private Sub btnApplySettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApplySettings.Click
My.Computer.Registry.SetValue(path, "MaxThumbSizePx", Convert.ToInt32(maxSizeTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "MinThumbSizePx", Convert.ToInt32(miniSizeTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "ThumbSpacingXPx", Convert.ToInt32(xsTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "ThumbSpacingYPx", Convert.ToInt32(ysTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "TopMarginPx", Convert.ToInt32(tmTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "BottomMarginPx", Convert.ToInt32(bmTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "LeftMarginPx", Convert.ToInt32(lmTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "RightMarginPx", Convert.ToInt32(rmTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ExtendedUIHoverTime", Convert.ToInt32(dtTrackBar.Value), RegistryValueKind.DWord)
'修改注冊表後,重啟explore.exe
Dim Explorers() As Process = Process.GetProcessesByName("explorer")
For Each Explorer As Process In Explorers
Explorer.Kill()
Next
Process.Start("explorer.exe")
Explorers = Nothing
End Sub
不用擔心的是, 如果你設置這個設置那個, 搞的很亂, 你可以恢復系統默認值:
Private Sub btnRestoreDefaults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestoreDefaults.Click
My.Computer.Registry.SetValue(path, "MaxThumbSizePx", 200, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "MinThumbSizePx", 200, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "ThumbSpacingXPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "ThumbSpacingYPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "TopMarginPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "BottomMarginPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "LeftMarginPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "RightMarginPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ExtendedUIHoverTime", 400, RegistryValueKind.DWord)
maxSizeTextBox.Text = "200"
miniSizeTextBox.Text = "200"
xsTextBox.Text = "16"
ysTextBox.Text = "16"
tmTextBox.Text = "16"
bmTextBox.Text = "16"
lmTextBox.Text = "16"
rmTextBox.Text = "16"
dtTextBox.Text = "400"
'修改注冊表後,重啟explore.exe
Dim Explorers() As Process = Process.GetProcessesByName("explorer")
For Each Explorer As Process In Explorers
Explorer.Kill()
Next
Process.Start("explorer.exe")
Explorers = Nothing
End Sub
主要的代碼就是這樣, 下面是程序中所有的代碼:
Imports Microsoft.Win32
Public Class mainForm
Dim path As String = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband"
Private Sub textBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
'這個函數的功能是判斷按下的鍵是否為數字或者Backspace鍵
If (e.KeyChar < "0" Or e.KeyChar > "9") Then
e.Handled = True
If Convert.ToInt32(e.KeyChar).Equals(8) Then
e.Handled = False
End If
Else
e.Handled = False
End If
End Sub 'KeyPress函數
Private Sub txtBox_TextChanged(ByVal txtBox As TextBox, ByVal trackBar As TrackBar)
'TextBox裡的值發生變化後
'如果值不為空
If txtBox.Text <> "" Then
'滑動條的值等於文本框內的數值
Try
trackBar.Value = txtBox.Text
If trackBar.Value > 512 Then '如果滑動條的值超過512則拋出一個異常
Throw New Exception
End If
Catch ex As Exception
trackBar.Value = 512
txtBox.Text = "512"
End Try
End If
'如果值為空
If txtBox.Text = "" Then
'滑動條的值置為0,文本框的值置為空
trackBar.Value = 0
txtBox.Text = ""
End If
End Sub 'TextChanged函數
Private Sub trackBar_ValueChanged(ByVal txtBox As TextBox, ByVal tracBar As TrackBar)
'當滑動條數值變化時,文本框裡的數值始終和滑動條值相等
txtBox.Text = tracBar.Value
End Sub 'TrackBarValueChanged函數
Private Sub btnApplySettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApplySettings.Click
My.Computer.Registry.SetValue(path, "MaxThumbSizePx", Convert.ToInt32(maxSizeTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "MinThumbSizePx", Convert.ToInt32(miniSizeTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "ThumbSpacingXPx", Convert.ToInt32(xsTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "ThumbSpacingYPx", Convert.ToInt32(ysTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "TopMarginPx", Convert.ToInt32(tmTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "BottomMarginPx", Convert.ToInt32(bmTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "LeftMarginPx", Convert.ToInt32(lmTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "RightMarginPx", Convert.ToInt32(rmTrackBar.Value), RegistryValueKind.DWord)
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ExtendedUIHoverTime", Convert.ToInt32(dtTrackBar.Value), RegistryValueKind.DWord)
'修改注冊表後,重啟explore.exe
Dim Explorers() As Process = Process.GetProcessesByName("explorer")
For Each Explorer As Process In Explorers
Explorer.Kill()
Next
Process.Start("explorer.exe")
Explorers = Nothing
End Sub
#Region "KeyPress_Events"
Private Sub maxSizeTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles maxSizeTextBox.KeyPress
textBox_KeyPress(maxSizeTextBox, e)
End Sub
Private Sub miniSizeTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles miniSizeTextBox.KeyPress
textBox_KeyPress(miniSizeTextBox, e)
End Sub
Private Sub xsTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles xsTextBox.KeyPress
textBox_KeyPress(xsTextBox, e)
End Sub
Private Sub ysTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ysTextBox.KeyPress
textBox_KeyPress(ysTextBox, e)
End Sub
Private Sub tmTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tmTextBox.KeyPress
textBox_KeyPress(tmTextBox, e)
End Sub
Private Sub bmTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles bmTextBox.KeyPress
textBox_KeyPress(bmTextBox, e)
End Sub
Private Sub lmTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles lmTextBox.KeyPress
textBox_KeyPress(lmTextBox, e)
End Sub
Private Sub rmTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles rmTextBox.KeyPress
textBox_KeyPress(rmTextBox, e)
End Sub
Private Sub dtTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles dtTextBox.KeyPress
textBox_KeyPress(dtTextBox, e)
End Sub
#End Region
#Region "TextBox_Changed"
Private Sub miniSizeTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miniSizeTextBox.TextChanged
txtBox_TextChanged(miniSizeTextBox, miniSizeTrackBar)
End Sub
Private Sub maxSizeTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles maxSizeTextBox.TextChanged
txtBox_TextChanged(maxSizeTextBox, maxSizeTrackBar)
End Sub
Private Sub xsTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xsTextBox.TextChanged
txtBox_TextChanged(xsTextBox, xsTrackBar)
End Sub
Private Sub ysTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ysTextBox.TextChanged
txtBox_TextChanged(ysTextBox, ysTrackBar)
End Sub
Private Sub tmTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmTextBox.TextChanged
txtBox_TextChanged(tmTextBox, tmTrackBar)
End Sub
Private Sub bmTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bmTextBox.TextChanged
txtBox_TextChanged(bmTextBox, bmTrackBar)
End Sub
Private Sub lmTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lmTextBox.TextChanged
txtBox_TextChanged(lmTextBox, lmTrackBar)
End Sub
Private Sub rmTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rmTextBox.TextChanged
txtBox_TextChanged(rmTextBox, rmTrackBar)
End Sub
Private Sub dtTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtTextBox.TextChanged
If dtTextBox.Text <> "" Then
'Delay Time最大值是9999
Try
dtTrackBar.Value = dtTextBox.Text
If dtTrackBar.Value > 9999 Then
Throw New Exception
End If
Catch ex As Exception
dtTrackBar.Value = 512
dtTextBox.Text = "512"
End Try
End If
'如果值為空
If dtTextBox.Text = "" Then
dtTrackBar.Value = 0
dtTextBox.Text = ""
End If
End Sub
#End Region
#Region "TrackBar_Changed"
Private Sub maxSizeTrackBar_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles maxSizeTrackBar.ValueChanged
trackBar_ValueChanged(maxSizeTextBox, maxSizeTrackBar)
End Sub
Private Sub miniSizeTrackBar_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miniSizeTrackBar.ValueChanged
trackBar_ValueChanged(miniSizeTextBox, miniSizeTrackBar)
End Sub
Private Sub xsTrackBar_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xsTrackBar.ValueChanged
trackBar_ValueChanged(xsTextBox, xsTrackBar)
End Sub
Private Sub ysTrackBar_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ysTrackBar.ValueChanged
trackBar_ValueChanged(ysTextBox, ysTrackBar)
End Sub
Private Sub tmTrackBar_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmTrackBar.ValueChanged
trackBar_ValueChanged(tmTextBox, tmTrackBar)
End Sub
Private Sub bmTrackBar_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bmTrackBar.ValueChanged
trackBar_ValueChanged(bmTextBox, bmTrackBar)
End Sub
Private Sub lmTrackBar_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lmTrackBar.ValueChanged
trackBar_ValueChanged(lmTextBox, lmTrackBar)
End Sub
Private Sub rmTrackBar_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rmTrackBar.ValueChanged
trackBar_ValueChanged(rmTextBox, rmTrackBar)
End Sub
Private Sub dtTrackBar_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtTrackBar.ValueChanged
trackBar_ValueChanged(dtTextBox, dtTrackBar)
End Sub
#End Region
Private Sub btnRestoreDefaults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestoreDefaults.Click
My.Computer.Registry.SetValue(path, "MaxThumbSizePx", 200, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "MinThumbSizePx", 200, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "ThumbSpacingXPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "ThumbSpacingYPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "TopMarginPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "BottomMarginPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "LeftMarginPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue(path, "RightMarginPx", 16, RegistryValueKind.DWord)
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ExtendedUIHoverTime", 400, RegistryValueKind.DWord)
maxSizeTextBox.Text = "200"
miniSizeTextBox.Text = "200"
xsTextBox.Text = "16"
ysTextBox.Text = "16"
tmTextBox.Text = "16"
bmTextBox.Text = "16"
lmTextBox.Text = "16"
rmTextBox.Text = "16"
dtTextBox.Text = "400"
'修改注冊表後,重啟explore.exe
Dim Explorers() As Process = Process.GetProcessesByName("explorer")
For Each Explorer As Process In Explorers
Explorer.Kill()
Next
Process.Start("explorer.exe")
Explorers = Nothing
End Sub
Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
maxSizeTextBox.Text = "200"
miniSizeTextBox.Text = "200"
xsTextBox.Text = "16"
ysTextBox.Text = "16"
tmTextBox.Text = "16"
bmTextBox.Text = "16"
lmTextBox.Text = "16"
rmTextBox.Text = "16"
dtTextBox.Text = "400"
On Error Resume Next
maxSizeTextBox.Text = My.Computer.Registry.GetValue(path, "MaxThumbSizePx", Nothing).ToString
miniSizeTextBox.Text = My.Computer.Registry.GetValue(path, "MinThumbSizePx", Nothing).ToString()
xsTextBox.Text = My.Computer.Registry.GetValue(path, "ThumbSpacingXPx", Nothing).ToString()
ysTextBox.Text = My.Computer.Registry.GetValue(path, "ThumbSpacingYPx", Nothing).ToString()
tmTextBox.Text = My.Computer.Registry.GetValue(path, "TopMarginPx", Nothing).ToString()
bmTextBox.Text = My.Computer.Registry.GetValue(path, "BottomMarginPx", Nothing).ToString()
lmTextBox.Text = My.Computer.Registry.GetValue(path, "LeftMarginPx", Nothing).ToString()
rmTextBox.Text = My.Computer.Registry.GetValue(path, "RightMarginPx", Nothing).ToString()
dtTextBox.Text = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ExtendedUIHoverTime", Nothing).ToString
End Sub
End Class
程序界面: