Как сделать форму прозрачной - VB
Формулировка задачи:
Кто знает, можно ли на VB5.0 сделать цвет формы прозрачным?
Заранее благодарен !!!
Решение задачи: «Как сделать форму прозрачной»
textual
Листинг программы
Option Explicit Declare Function GetWindowRect Lib 'user32' (ByVal hwnd As Long, lpRect As RECT) As Long Declare Function GetClientRect Lib 'user32' (ByVal hwnd As Long, lpRect As RECT) As Long Declare Function CombineRgn Lib 'gdi32' (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long Declare Function CreateRectRgn Lib 'gdi32' _ (ByVal X1 As Long, ByVal Y1 As Long, _ ByVal X2 As Long, ByVal Y2 As Long) As Long Declare Function ScreenToClient Lib 'user32' _ (ByVal hwnd As Long, lpPoint As POINTAPI) As Long Declare Function SetWindowRgn Lib 'user32' _ (ByVal hwnd As Long, ByVal hRgn As Long, _ ByVal bRedraw As Boolean) As Long Public Const RGN_AND = 1 Public Const RGN_COPY = 5 Public Const RGN_DIFF = 4 Public Const RGN_OR = 2 Public Const RGN_XOR = 3 Type POINTAPI X As Long Y As Long End Type Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Public Sub MakeTransparent(frm As Form) Dim rctClient As RECT, rctFrame As RECT Dim hClient As Long, hFrame As Long '// Grab client area and frame area GetWindowRect frm.hwnd, rctFrame GetClientRect frm.hwnd, rctClient '// Convert client coordinates to screen coordinates Dim lpTL As POINTAPI, lpBR As POINTAPI lpTL.X = rctFrame.Left lpTL.Y = rctFrame.Top lpBR.X = rctFrame.Right lpBR.Y = rctFrame.Bottom ScreenToClient frm.hwnd, lpTL ScreenToClient frm.hwnd, lpBR With rctFrame .Left = lpTL.X .Top = lpTL.Y .Right = lpBR.X .Bottom = lpBR.Y End With With rctClient .Left = Abs(rctFrame.Left) .Top = Abs(rctFrame.Top) .Right = rctClient.Right + Abs(rctFrame.Left) .Bottom = rctClient.Bottom + Abs(rctFrame.Top) End With With rctFrame .Right = rctFrame.Right + Abs(rctFrame.Left) .Bottom = rctFrame.Bottom + Abs(rctFrame.Top) .Top = 0 .Left = 0 End With '// Convert RECT structures to region handles hClient = CreateRectRgn(rctClient.Left, rctClient.Top, rctClient.Right, rctClient.Bottom) hFrame = CreateRectRgn(rctFrame.Left, rctFrame.Top, rctFrame.Right, rctFrame.Bottom) '// Create the new 'Transparent' region CombineRgn hFrame, hClient, hFrame, RGN_XOR '// Combine the regions of the controls '// on the form with the 'transparent' region. Dim C As Control, rctControl As RECT, hControl As Long For Each C In frm On Error Resume Next '// Get the control's area GetWindowRect C.hwnd, rctControl '// Convert to client coordinates lpTL.X = rctControl.Left lpTL.Y = rctControl.Top lpBR.X = rctControl.Right lpBR.Y = rctControl.Bottom ScreenToClient frm.hwnd, lpTL ScreenToClient frm.hwnd, lpBR With rctControl .Left = lpTL.X + rctClient.Left .Top = lpTL.Y + rctClient.Top .Right = lpBR.X + rctClient.Left .Bottom = lpBR.Y + rctClient.Top End With hControl = CreateRectRgn(rctControl.Left, rctControl.Top, rctControl.Right, rctControl.Bottom) CombineRgn hFrame, hControl, hFrame, RGN_OR Next C '// Now lock the window's area to this created region SetWindowRgn frm.hwnd, hFrame,
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д