| GetWindowRect, GetClientRect, CombineRgn, CreateRectRgn, ScreenToClient |
| |
| |
| Prozedur im Modul | |
| 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 | |
| GetWindowRect frm.hWnd, rctFrame | Grab client area and frame area. |
| GetClientRect frm.hWnd, rctClient | |
| Dim lpTL As POINTAPI, lpBR As POINTAPI | Convert client coordinates to screen coordinates. |
| lpTL.X = rctFrame.Left | |
| lpTL.Y = rctFrame.Top | |
| lpBR.X = rctFrame.Right | |
| lpBR.Y = rctFrame.Bottom | |
| ScreenToClient frm.hWnd, lpTL | |
| ScreenToClient frm.hWnd, lpBR | |
| rctFrame.Left = lpTL.X | |
| rctFrame.Top = lpTL.Y | |
| rctFrame.Right = lpBR.X | |
| rctFrame.Bottom = lpBR.Y | |
| rctClient.Left = Abs(rctFrame.Left) | |
| rctClient.Top = Abs(rctFrame.Top) | |
| rctClient.Right = rctClient.Right + Abs(rctFrame.Left) | |
| rctClient.Bottom = rctClient.Bottom + Abs(rctFrame.Top) | |
| rctFrame.Right = rctFrame.Right + Abs(rctFrame.Left) | |
| rctFrame.Bottom = rctFrame.Bottom + Abs(rctFrame.Top) | |
| rctFrame.Top = 0 | |
| rctFrame.Left = 0 | 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) |
| CombineRgn hFrame, hClient, hFrame, RGN_XOR | Create the new "Transparent" region. |
| SetWindowRgn frm.hWnd, hFrame, True | Now lock the window's area to this created region. |
| End Sub | Parameter "False" zeigt andere Wirkung. |
| |
| |
| Prozedur im Formular | |
| Private Sub cmdTransparentesFormular_Click() | CommandButton platzieren. |
| MakeTransparent Me | |
| End Sub | |
| |