VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 2745 ClientLeft = 60 ClientTop = 345 ClientWidth = 2175 LinkTopic = "Form1" ScaleHeight = 2745 ScaleWidth = 2175 StartUpPosition = 3 'Windows Default Begin VB.CommandButton Command4 Caption = "Command4" Height = 375 Left = 240 TabIndex = 3 Top = 2040 Width = 1575 End Begin VB.CommandButton Command3 Caption = "Command3" Height = 375 Left = 240 TabIndex = 2 Top = 1440 Width = 1575 End Begin VB.CommandButton Command2 Caption = "Command2" Height = 375 Left = 240 TabIndex = 1 Top = 840 Width = 1575 End Begin VB.CommandButton Command1 Caption = "Command1" Height = 375 Left = 240 TabIndex = 0 Top = 240 Width = 1575 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option ExplicitConst LVM_FIRST = &H1000 Const LVM_SETBKIMAGEA = LVM_FIRST + 68 Const LVM_GETITEMCOUNT = LVM_FIRST + 4 Const LVM_SETTEXTCOLOR = LVM_FIRST + 36 Const LVM_REDRAWITEMS = LVM_FIRST + 21 Const LVM_SETTEXTBKCOLOR = LVM_FIRST + 38 Const LVM_SETITEMPOSITION = LVM_FIRST + 15Const SW_SHOW = 5 Const SW_HIDE = 0Private Type POINTAPI x As Long y As Long End TypePrivate Declare Function ShowWindow Lib "user32" _ (ByVal hwnd As Long, _ ByVal nCmdShow As Long) As LongPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ (ByVal hWnd1 As Long, _ ByVal hWnd2 As Long, _ ByVal lpsz1 As String, _ ByVal lpsz2 As String) As Long Private Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long Private Declare Function SendMessageP Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As LongPrivate Declare Function GetSysColor Lib "user32" _ (ByVal nIndex As Long) As Long Private Declare Function SetSysColors Lib "user32" _ (ByVal nChanges As Long, _ lpSysColor As Long, _ lpColorValues As Long) As LongConst COLOR_DESKTOP = 1 Dim bHide As Boolean'RestoreColor函数回复默认的图标文字颜色和背景 Sub RestoreColor() Dim lColor As Long
lColor = GetSysColor(COLOR_DESKTOP) SetSysColors 1, COLOR_DESKTOP, lColor End Sub Sub SetIconText(clFore, clBack As Long, bTrans As Boolean) Dim hWindow As Long Dim lItemCount As Long
'重新绘制所有的图标 lItemCount = SendMessage(hWindow, LVM_GETITEMCOUNT, 0, 0) SendMessage hWindow, LVM_REDRAWITEMS, 0, lItemCount - 1 '更新窗口 UpdateWindow hWindow End SubSub ArrangeDesktopIcon(iWidth As Integer, iHeight As Integer) Dim hWindow As Long Dim i1, i2, i, iCount As Integer Dim po As POINTAPI
i1 = 20: i2 = 20 iCount = SendMessage(hWindow, LVM_GETITEMCOUNT, 0, 0) For i = 0 To iCount - 1 po.x = i1: po.y = i2 '发送LVM_SETITEMPOSITION消息排列图标 Call SendMessage(hWindow, LVM_SETITEMPOSITION, i, i2 * 65536 + i1) i1 = i1 + iWidth If i1 > ((Screen.Width / 15) - 32) Then '达到屏幕边缘,进行换行 i1 = 20 i2 = i2 + iHeight End If Next i '图标排列完毕,重新绘制图标项 SendMessage hWindow, LVM_REDRAWITEMS, 0, iCount - 1 '更新窗口 UpdateWindow hWindow End SubPrivate Sub Command1_Click() '设置图标文字的颜色为蓝色,背景色为黑色,背景为透明 SetIconText vbBlue, vbBlack, True End SubPrivate Sub Command2_Click() RestoreColor End SubPrivate Sub Command3_Click() '以100x100像素为单位排列图标 ArrangeDesktopIcon 100, 100 End SubPrivate Sub Command4_Click() Dim hWindow As Long
http://expert.csdn.net/Expert/topic/1984/1984981.xml?temp=.5877802
3、怎样实现桌面文字背景透明?========================================================================利用全局Hook对桌面窗口进行SubClass,再对其进行自绘
具体代码可以参考 陈宽达的《C++ Builder深度历险》
http://www.dapha.net/down/list.asp?id=1863
XP下拉菜单(影子效果,酷!!!)
http://www.dapha.net/down/list.asp?id=426
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2745
ClientLeft = 60
ClientTop = 345
ClientWidth = 2175
LinkTopic = "Form1"
ScaleHeight = 2745
ScaleWidth = 2175
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command4
Caption = "Command4"
Height = 375
Left = 240
TabIndex = 3
Top = 2040
Width = 1575
End
Begin VB.CommandButton Command3
Caption = "Command3"
Height = 375
Left = 240
TabIndex = 2
Top = 1440
Width = 1575
End
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 375
Left = 240
TabIndex = 1
Top = 840
Width = 1575
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 375
Left = 240
TabIndex = 0
Top = 240
Width = 1575
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitConst LVM_FIRST = &H1000
Const LVM_SETBKIMAGEA = LVM_FIRST + 68
Const LVM_GETITEMCOUNT = LVM_FIRST + 4
Const LVM_SETTEXTCOLOR = LVM_FIRST + 36
Const LVM_REDRAWITEMS = LVM_FIRST + 21
Const LVM_SETTEXTBKCOLOR = LVM_FIRST + 38
Const LVM_SETITEMPOSITION = LVM_FIRST + 15Const SW_SHOW = 5
Const SW_HIDE = 0Private Type POINTAPI
x As Long
y As Long
End TypePrivate Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, _
ByVal nCmdShow As Long) As LongPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function SendMessageP Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As LongPrivate Declare Function GetSysColor Lib "user32" _
(ByVal nIndex As Long) As Long
Private Declare Function SetSysColors Lib "user32" _
(ByVal nChanges As Long, _
lpSysColor As Long, _
lpColorValues As Long) As LongConst COLOR_DESKTOP = 1
Dim bHide As Boolean'RestoreColor函数回复默认的图标文字颜色和背景
Sub RestoreColor()
Dim lColor As Long
lColor = GetSysColor(COLOR_DESKTOP)
SetSysColors 1, COLOR_DESKTOP, lColor
End Sub
Sub SetIconText(clFore, clBack As Long, bTrans As Boolean)
Dim hWindow As Long
Dim lItemCount As Long
'通过三步查找到放置桌面图表的窗口
hWindow = FindWindow("Progman", "Program Manager")
hWindow = FindWindowEx(hWindow, 0, "SHELLDLL_DefView", "")
hWindow = FindWindowEx(hWindow, 0, "SysListView32", "")
If bTrans Then '透明背景
SendMessage hWindow, LVM_SETTEXTBKCOLOR, 0, &HFFFFFFFF
Else '非透明背景
SendMessage hWindow, LVM_SETTEXTBKCOLOR, 0, clBack
End If
'设置图标文字的颜色
SendMessage hWindow, LVM_SETTEXTCOLOR, 0, clFore
'重新绘制所有的图标
lItemCount = SendMessage(hWindow, LVM_GETITEMCOUNT, 0, 0)
SendMessage hWindow, LVM_REDRAWITEMS, 0, lItemCount - 1
'更新窗口
UpdateWindow hWindow
End SubSub ArrangeDesktopIcon(iWidth As Integer, iHeight As Integer)
Dim hWindow As Long
Dim i1, i2, i, iCount As Integer
Dim po As POINTAPI
'通过三步查找到放置桌面图表的窗口
hWindow = FindWindow("Progman", "Program Manager")
hWindow = FindWindowEx(hWindow, 0, "SHELLDLL_DefView", "")
hWindow = FindWindowEx(hWindow, 0, "SysListView32", "")
i1 = 20: i2 = 20
iCount = SendMessage(hWindow, LVM_GETITEMCOUNT, 0, 0)
For i = 0 To iCount - 1
po.x = i1: po.y = i2
'发送LVM_SETITEMPOSITION消息排列图标
Call SendMessage(hWindow, LVM_SETITEMPOSITION, i, i2 * 65536 + i1)
i1 = i1 + iWidth
If i1 > ((Screen.Width / 15) - 32) Then '达到屏幕边缘,进行换行
i1 = 20
i2 = i2 + iHeight
End If
Next i
'图标排列完毕,重新绘制图标项
SendMessage hWindow, LVM_REDRAWITEMS, 0, iCount - 1
'更新窗口
UpdateWindow hWindow
End SubPrivate Sub Command1_Click()
'设置图标文字的颜色为蓝色,背景色为黑色,背景为透明
SetIconText vbBlue, vbBlack, True
End SubPrivate Sub Command2_Click()
RestoreColor
End SubPrivate Sub Command3_Click()
'以100x100像素为单位排列图标
ArrangeDesktopIcon 100, 100
End SubPrivate Sub Command4_Click()
Dim hWindow As Long
'通过三步查找到放置桌面图表的窗口
hWindow = FindWindow("Progman", "Program Manager")
hWindow = FindWindowEx(hWindow, 0, "SHELLDLL_DefView", "")
hWindow = FindWindowEx(hWindow, 0, "SysListView32", "")
If bHide Then
ShowWindow hWindow, SW_SHOW
bHide = False
Command4.Caption = "隐藏桌面图标"
Else
ShowWindow hWindow, SW_HIDE
bHide = True
Command4.Caption = "显示桌面图标"
End If
End SubPrivate Sub Form_Load()
Command1.Caption = "设置文字背景"
Command2.Caption = "恢复文字背景"
Command3.Caption = "排列桌面图标"
Command4.Caption = "隐藏桌面图标"
End Sub