您的位置:首页 > 编程语言 > VB

VB简单实现窗口全透明

2008-10-29 14:01 405 查看
VB简单实现窗口全透明

实现窗口全透明,不管用什么编程语言,其实原理都是一样的,为了进一步展现各语言实现整个窗口全透明,前几天已将C#和C++MFC源码发布,现将用VB实现的源码送上,供大家参考。

效果图:



程序源码如下:

Private Declare Function DwmIsCompositionEnabled Lib "dwmapi.dll" (ByRef enabledptr As Long) As Long
Private Declare Function DwmExtendFrameIntoClientArea Lib "dwmapi.dll" (ByVal hwnd As Long, margin As MARGINS) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type MARGINS
m_Left As Long
m_Right As Long
m_Top As Long
m_Button As Long
End Type

Private Sub Form_Load()
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
End Sub
Private Sub Form_Paint()
Dim hBrush As Long, m_Rect As RECT, hBrushOld As Long
hBrush = CreateSolidBrush(RGB(0, 0, 0))
hBrushOld = SelectObject(Me.hdc, hBrush)
GetClientRect Me.hwnd, m_Rect
FillRect Me.hdc, m_Rect, hBrush
SelectObject Me.hdc, hBrushOld
DeleteObject hBrush
End Sub


工程源码下载: http://download.csdn.net/source/731299

发布:薛雪 E_mail:SnowEmail3074@163.com

备注:实现方法虽然很简单,转载时敬请注明出处,谢谢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: