
Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
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
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Sub Form_Load()
Dim Ret As Long
Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
SetLayeredWindowAttributes Me.hWnd, 0, 128, LWA_ALPHA
End Sub
xolod писал(а):За эту неделю подобный вопрос возникает раз 5-ый =)
Ну сколько можно??
- Код: Выделить всё
Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
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
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Sub Form_Load()
Dim Ret As Long
Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
SetLayeredWindowAttributes Me.hWnd, 0, 128, LWA_ALPHA
End Sub
И, RTFM!
Чтобы контролы были непрозрачны, а сама форма была полупрозрачна, что-то страшное надо сделать ...
А вот контролы чтобы были непрозрачны и формы совсем не видно было - это можно, поищи по форуму, совсем не давно подобную тему рассматривали...
Option Explicit
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As _
Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal _
nCombineMode As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As _
Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Public Sub TransparentForm(frm As Form)
frm.ScaleMode = vbPixels
Const RGN_DIFF = 4
Const RGN_OR = 2
Dim outer_rgn As Long
Dim inner_rgn As Long
Dim wid As Single
Dim hgt As Single
Dim border_width As Single
Dim title_height As Single
Dim ctl_left As Single
Dim ctl_top As Single
Dim ctl_right As Single
Dim ctl_bottom As Single
Dim control_rgn As Long
Dim combined_rgn As Long
Dim ctl As Control
If frm.WindowState = vbMinimized Then Exit Sub
wid = frm.ScaleX(frm.Width, vbTwips, vbPixels)
hgt = frm.ScaleY(frm.Height, vbTwips, vbPixels)
outer_rgn = CreateRectRgn(0, 0, wid, hgt)
border_width = (wid - frm.ScaleWidth) / 2
title_height = hgt - border_width - frm.ScaleHeight
inner_rgn = CreateRectRgn(border_width, title_height, wid - border_width, _
hgt - border_width)
combined_rgn = CreateRectRgn(0, 0, 0, 0)
CombineRgn combined_rgn, outer_rgn, inner_rgn, RGN_DIFF
For Each ctl In frm.Controls
If ctl.Container Is frm Then
ctl_left = frm.ScaleX(ctl.Left, frm.ScaleMode, vbPixels) _
+ border_width
ctl_top = frm.ScaleX(ctl.Top, frm.ScaleMode, vbPixels) + title_height
ctl_right = frm.ScaleX(ctl.Width, frm.ScaleMode, vbPixels) + ctl_left
ctl_bottom = frm.ScaleX(ctl.Height, frm.ScaleMode, vbPixels) + ctl_top
control_rgn = CreateRectRgn(ctl_left, ctl_top, ctl_right, ctl_bottom)
CombineRgn combined_rgn, combined_rgn, control_rgn, RGN_OR
End If
Next ctl
SetWindowRgn frm.hWnd, combined_rgn, True
End Sub
Private Sub Form_Resize()
TransparentForm Me
End Sub
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 19