找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 11523|回复: 7

[其它] VB实现全窗体的磨砂玻璃效果

 火.. [复制链接]

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
发表于 2011-4-8 18:31:22 | 显示全部楼层 |阅读模式
很多年前从网上抄来的,但是最近才看到效果(当年的旧电脑没法启动Aero特效)。


把一下代码复制到类模块中:

  1. Option Explicit

  2. Private Type MARGINS
  3.   m_Left As Long
  4.   m_Right As Long
  5.   m_Top As Long
  6.   m_Button As Long
  7. End Type

  8. Private Type RECT
  9.     Left As Long
  10.     Top As Long
  11.     Right As Long
  12.     Bottom As Long
  13. End Type

  14. Private Declare Function DwmIsCompositionEnabled Lib "dwmapi.dll" (ByRef enabledptr As Long) As Long
  15. Private Declare Function DwmExtendFrameIntoClientArea Lib "dwmapi.dll" (ByVal hwnd As Long, margin As MARGINS) As Long
  16. Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
  17. Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
  18. Private Declare Function GetClientRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT) As Long
  19. Private Declare Function FillRect Lib "user32.dll" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
  20. Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
  21. Private Declare Function SetLayeredWindowAttributesByColor Lib "user32" Alias "SetLayeredWindowAttributes" (ByVal hwnd As Long, ByVal crey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
  22. Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  23. Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  24. Private Declare Function ReleaseCapture Lib "user32" () As Long
  25. Private Declare Function SendMessageA Lib "user32" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

  26. Private Const HTCAPTION = 2
  27. Private Const WM_NCLBUTTONDOWN = &HA1
  28. Private Const GWL_EXSTYLE As Long = -20
  29. Private Const WS_EX_LAYERED As Long = &H80000
  30. Private Const LWA_COLORKEY As Long = &H1
  31. Private m_transparencyKey As Long

  32. Public Sub OnFormLoad(ByVal WindowHandle As Long)
  33.     m_transparencyKey = RGB(255, 255, 1)
  34.     SetWindowLong WindowHandle, GWL_EXSTYLE, GetWindowLong(WindowHandle, GWL_EXSTYLE) Or WS_EX_LAYERED
  35.     SetLayeredWindowAttributesByColor WindowHandle, m_transparencyKey, 0, LWA_COLORKEY
  36.     Dim mg As MARGINS, en As Long
  37.     mg.m_Left = -1
  38.     mg.m_Button = -1
  39.     mg.m_Right = -1
  40.     mg.m_Top = -1
  41.     DwmIsCompositionEnabled en
  42.     If en Then
  43.         DwmExtendFrameIntoClientArea WindowHandle, mg
  44.     End If
  45. End Sub

  46. Public Sub OnFormPaint(ByVal whdc As Long, ByVal wndh As Long)
  47.     Dim hBrush As Long, m_Rect As RECT, hBrushOld As Long
  48.     hBrush = CreateSolidBrush(m_transparencyKey)
  49.     hBrushOld = SelectObject(whdc, hBrush)
  50.     GetClientRect wndh, m_Rect
  51.     FillRect whdc, m_Rect, hBrush
  52.     SelectObject whdc, hBrushOld
  53.     DeleteObject hBrush
  54. End Sub

  55. Public Sub OnMouseDown(ByVal wndh As Long)
  56.     ReleaseCapture
  57.     SendMessageA wndh, WM_NCLBUTTONDOWN, HTCAPTION, 0&
  58. End Sub
复制代码
再把以下代码复制到窗体中:

  1. Option Explicit

  2. Dim ggs As New Cls_GroundGlassStyle

  3. Private Sub Form_Load()
  4.     ggs.OnFormLoad Me.hwnd
  5. End Sub

  6. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  7.     ggs.OnMouseDown Me.hwnd
  8. End Sub

  9. Private Sub Form_Paint()
  10.     ggs.OnFormPaint Me.hdc, Me.hwnd
  11. End Sub
复制代码


效果如下:
Untitled.png

8

主题

149

回帖

2

精华

钻石会员

积分
3407
发表于 2011-4-8 22:44:42 | 显示全部楼层
好大的英特尔logo……:L

275

主题

3017

回帖

1

精华

管理员

嗷嗷叫的老马

积分
17064

论坛牛人贡献奖关注奖最佳版主进步奖人气王疯狂作品奖精英奖赞助论坛勋章乐于助人勋章

QQ
发表于 2011-4-18 14:20:17 | 显示全部楼层
哈哈,果然好大....
我就是嗷嗷叫的老马了......

40

主题

324

回帖

0

精华

铂金会员

Eax=0

积分
1575
发表于 2011-4-18 21:22:34 | 显示全部楼层
啊,幸好我老电脑不算太差,让我几年前就体验到了各种aero特效。不过你的方法代码也太多了吧!其中很多代码都可以安全删去,比如

  1.     mg.m_Left = -1
  2.     mg.m_Button = -1
  3.     mg.m_Right = -1
  4.     mg.m_Top = -1
复制代码
只保留一个就行。
Do my best.

1

主题

8

回帖

0

精华

初来乍到

积分
10
发表于 2011-5-1 16:31:53 | 显示全部楼层
回复 Tesla.Angela 的帖子

迫不及待测试了~

1

主题

8

回帖

0

精华

初来乍到

积分
10
发表于 2011-5-1 16:34:15 | 显示全部楼层
回复 Tesla.Angela 的帖子

貌似缺少DLL哦~?

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
 楼主| 发表于 2011-5-1 19:08:20 | 显示全部楼层
回复 opboy45 的帖子

仅仅支持vista/win7。

0

主题

11

回帖

0

精华

铜牌会员

积分
237
发表于 2012-4-23 11:07:02 | 显示全部楼层
学习学习,gdi?
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表