VB关于桌面的一些操作

*提取桌面背景图片到FORM窗体:
Private Declare Function PaintDesktop Lib “user32” (ByVal hdc As Long) As Long

Private Sub Form_Paint()
PaintDesktop Me.hdc
End Sub


*鼠标穿透FORM窗体
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
Const WS_EX_TRANSPARENT As Long = &H20&
Private Declare Function GetWindowLong Lib “user32” Alias “GetWindowLongA” (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA” (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Sub Fme(S As Boolean)
If S = True Then
SetWindowLong Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED Or WS_EX_TRANSPARENT '鼠标穿透窗体
Else
SetWindowLong Me.hwnd, GWL_EXSTYLE, 0 '取消鼠标穿透窗体
End If
End Sub


*刷新桌面
Private Declare Function PostMessage Lib “user32” Alias “PostMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) 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
Const WM_KEYDOWN = &H100

Private Sub RefreshDesktop()
Dim DesWin As Long
DesWin = FindWindowEx(0&, 0&, “Progman”, vbNullString)
'DesWin = FindWindowEx(DesWin, 0&, “SHELLDLL_DefView”, vbNullString)
'DesWin = FindWindowEx(DesWin, 0&, “SysListVietw32”, vbNullString)
PostMessage DesWin, WM_KEYDOWN, &H74, &H3F0001
End Sub


*隐藏、显示桌面图标
Private Declare Function FindWindow Lib “user32” Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib “user32” (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_HIDE = 0
Const SW_RESTORE = 9

Private Sub Command1_Click() '隐藏
Dim Hwd As Long
Dim rtn As Long
Hwd = FindWindow(“progman”, vbNullString)
rtn = ShowWindow(Hwd, SW_HIDE)
End Sub

Private Sub Command2_Click() '显示
Dim Hwd As Long
Dim rtn As Long
Hwd = FindWindow(“progman”, vbNullString)
rtn = ShowWindow(Hwd, SW_RESTORE)
End Sub


*显示桌面(把所有的窗口最小化)
Private Sub Command1_Click()
CreateObject(“Shell.Application”).ToggleDesktop
End Sub


'将窗体嵌入桌面
Private Declare Function FindWindow Lib “user32” Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetParent Lib “user32” (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private Sub Command1_Click()
Dim i&
i = FindWindow(“progman”, vbNullString)
SetParent Me.hwnd, i
End Sub
Private Sub Command2_Click()
SetParent Me.hwnd, 0
End Sub

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

键盘上的舞指

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值