博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VB窗体半透明的方法
阅读量:5873 次
发布时间:2019-06-19

本文共 2175 字,大约阅读时间需要 7 分钟。

hot3.png

'-----------------------------'使用说明:'1.新建一个标准exe工程'2.放置1个CommandButton 控件(使用默认名)'3.把下面的代码复制进去就可以了'-----------------------------Option Explicit'Transparancy API'sPrivate Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As LongPrivate Declare Function UpdateLayeredWindow Lib "user32" (ByVal hWnd As Long, ByVal hdcDst As Long, pptDst As Any, psize As Any, ByVal hdcSrc As Long, pptSrc As Any, crKey As Long, ByVal pblend As Long, ByVal dwFlags As Long) As LongPrivate Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Const GWL_EXSTYLE = (-20)Private Const LWA_COLORKEY = &H1Private Const LWA_ALPHA = &H2Private Const ULW_COLORKEY = &H1Private Const ULW_ALPHA = &H2Private Const ULW_OPAQUE = &H4Private Const WS_EX_LAYERED = &H80000Public Function isTransparent(ByVal hWnd As Long) As BooleanOn Error Resume NextDim Msg As LongMsg = GetWindowLong(hWnd, GWL_EXSTYLE)If (Msg And WS_EX_LAYERED) = WS_EX_LAYERED ThenisTransparent = TrueElseisTransparent = FalseEnd IfIf Err ThenisTransparent = FalseEnd IfEnd FunctionPublic Function MakeTransparent(ByVal hWnd As Long, ByVal Perc As Integer) As LongDim Msg As LongOn Error Resume NextPerc = 100If Perc < 0 Or Perc > 255 ThenMakeTransparent = 1ElseMsg = GetWindowLong(hWnd, GWL_EXSTYLE)Msg = Msg Or WS_EX_LAYEREDSetWindowLong hWnd, GWL_EXSTYLE, MsgSetLayeredWindowAttributes hWnd, 0, Perc, LWA_ALPHAMakeTransparent = 0End IfIf Err ThenMakeTransparent = 2End IfEnd FunctionPublic Function MakeOpaque(ByVal hWnd As Long) As LongDim Msg As LongOn Error Resume NextMsg = GetWindowLong(hWnd, GWL_EXSTYLE)Msg = Msg And Not WS_EX_LAYEREDSetWindowLong hWnd, GWL_EXSTYLE, MsgSetLayeredWindowAttributes hWnd, 0, 0, LWA_ALPHAMakeOpaque = 0If Err ThenMakeOpaque = 2End IfEnd Function'透明Private Sub Command1_Click() MakeTransparent Me.hWnd, 120 '这里的120是透明度,在0~255之间取值End Sub

  

转载于:https://my.oschina.net/mengkun/blog/647504

你可能感兴趣的文章
被神话的大数据——从大数据(big data)到深度数据(deep data)思维转变
查看>>
修改校准申请遇到的问题
查看>>
Linux 进程中 Stop, Park, Freeze【转】
查看>>
文件缓存
查看>>
远程协助
查看>>
Scrum实施日记 - 一切从零开始
查看>>
关于存储过程实例
查看>>
配置错误定义了重复的“system.web.extensions/scripting/scriptResourceHandler” 解决办法...
查看>>
AIX 7.1 install python
查看>>
PHP盛宴——经常使用函数集锦
查看>>
重写 Ext.form.field 扩展功能
查看>>
Linux下的搜索查找命令的详解(locate)
查看>>
福利丨所有AI安全的讲座里,这可能是最实用的一场
查看>>
开发完第一版前端性能监控系统后的总结(无代码)
查看>>
Python多版本情况下四种快速进入交互式命令行的操作技巧
查看>>
MySQL查询优化
查看>>
【Redis源码分析】如何在Redis中查找大key
查看>>
关于链接文件的探讨
查看>>
android app启动过程(转)
查看>>
Linux—源码包安装
查看>>