吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 5981|回复: 22
收起左侧

[其他转载] Visual Basic 实现窗口磨砂玻璃样式

  [复制链接]
〆红瞳朱雀丶痛 发表于 2014-8-8 17:56
因之前的图片无法显示,重新发帖。

用VB制作磨砂玻璃效果,在Win7和Vista系统下经常会看到这种效果,现在我就用VB来实现。

首先要在 Visual Basic 6.0  中新建一个工程,一个标准程序和一个标准模块。

模块代码如下:

Public Type MARGINS
    m_Left As Long
    m_Right As Long
    m_Top As Long
    m_Button As Long
End Type
Public Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Public Const LWA_COLORKEY = &H1
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_LAYERED = &H80000
    Dim Inied As Boolean
Public Declare Function DwmExtendFrameIntoClientArea Lib "dwmapi.dll" (ByVal hwnd As Long, margin As MARGINS) As Long
'[DllImport("dwmapi.dll", PreserveSig=false)]
Public Declare Function DwmIsCompositionEnabled Lib "dwmapi.dll" (ByRef enabledptr As Long) As Long
Public Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Public Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public 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
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Form窗体代码如下:

Dim m_transparencyKey As Long
Private Sub Form_Load()
    m_transparencyKey = RGB(255, 255, 1)
    SetWindowLong Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED
    SetLayeredWindowAttributesByColor Me.hwnd, m_transparencyKey, 0, LWA_COLORKEY
     Dim mg As MARGINS, en As Long
    mg.m_Left = -1
    mg.m_Button = -1
    mg.m_Right = -1
    mg.m_Top = -1
    DwmIsCompositionEnabled en
    If en Then
        DwmExtendFrameIntoClientArea Me.hwnd, mg
    End If
    Exit Sub
End Sub
Private Sub Form_Paint()
Dim hBrush As Long, m_Rect As RECT, hBrushOld As Long
    hBrush = CreateSolidBrush(m_transparencyKey)
    hBrushOld = SelectObject(Me.hdc, hBrush)
    GetClientRect Me.hwnd, m_Rect
    FillRect Me.hdc, m_Rect, hBrush
    SelectObject Me.hdc, hBrushOld
    DeleteObject hBrush
End Sub

效果图:
psb.png
psb3.png
psb2.png
psb1.png

By:HackAny


免费评分

参与人数 1热心值 +1 收起 理由
pdprf + 1 很漂亮。

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 〆红瞳朱雀丶痛 发表于 2014-8-8 19:10
wzj005 发表于 2014-8-8 18:47
已经点赞了,希望楼主多发点VB的教程

VB的话我会比较多发表吧,因为不会其他编程语言了。
 楼主| 〆红瞳朱雀丶痛 发表于 2015-5-2 14:23
opelwang 发表于 2015-4-21 08:25
我在win7下,怎么没有效果?

Win7下没有效果,你看看电脑有没有打开Aero或有没有支持Aero
丶阡陌丨殇 发表于 2014-8-8 18:03
 楼主| 〆红瞳朱雀丶痛 发表于 2014-8-8 18:07
丶阡陌丨殇 发表于 2014-8-8 18:03
支持!!!!沙发!

多谢支持哈。
ytw6176 发表于 2014-8-8 18:10
非常喜欢~~  感谢分享  收藏了
Mr丶晓东 发表于 2014-8-8 18:18
路过帮顶下~~~~~~~~~~~·
ww1113330 发表于 2014-8-8 18:38
感谢分享,收藏了,以后方便使用
myqqq 发表于 2014-8-8 18:45
我有透明的源码
wzj005 发表于 2014-8-8 18:47
已经点赞了,希望楼主多发点VB的教程
 楼主| 〆红瞳朱雀丶痛 发表于 2014-8-8 19:09
myqqq 发表于 2014-8-8 18:45
我有透明的源码

透明代码比较少。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-15 15:29

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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