We're building a brand new version of the site, and we'd love to hear your ideas
Members
Technology Zones
IBM Learning Center
Articles
Hosted By
Info
|
[4202] Making Windows Transparent
-
01-01-1999 12:00 AM
|
|
Advertisement
|
|
-
-
-
-
-
-
-
Joe C


- Joined on 07-30-2004

- Points 10
|
Yes, thanks for the help. The following code is an example of the problem:
Option Explicit
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.dll" (ByVal _
hwnd As Long, ByValcrKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Boolean
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X _
As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal _
hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Const SRCCOPY = &HCC0020
Private Const LWA_ALPHA = 2
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Dim iLeft As Integer
Private Sub Form_Load()
'Change window style to layered
'Comment out the code for smooth scrolling (disables fade effect)
SetWindowLong Form1.hwnd, GWL_EXSTYLE, GetWindowLong(Form1.hwnd, _
GWL_EXSTYLE) Or WS_EX_LAYERED
SetLayeredWindowAttributes Form1.hwnd, 0, 255, LWA_ALPHA
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Can't change the window style here, because it creates flicker
'Cut and paste the Form_Load code here to see
'Fade effect
Timer1.Enabled = False
Dim i As Integer
For i = 255 To 0 Step -5
SetLayeredWindowAttributes Me.hwnd, 0, i, LWA_ALPHA
DoEvents
Next
End Sub
Private Sub Timer1_Timer()
'BitBLT scrolling
iLeft = iLeft + 1
If iLeft = ((Form1.Width + Picture1.Width) / Screen.TwipsPerPixelX) Then _
iLeft = 0
BitBlt Picture1.hDC, 0, 0, Picture1.Width, Picture1.Height, Form1.hDC, _
iLeft, 0, SRCCOPY
End Sub
To use the code, add a small picture box to your form and add a timer (enable it, and set the interval to 1). Then load a large picture into the form (the form1.picture property)
As you will see, if you change the window style in the form load event, then the bitblting becomes very choppy. If you wait and change the window style in the form unload event, just before the fade out effect, then you will see an ugly flicker.
I would like to change the window style to layered, only when i need it at form unload, but would like to avoid the flicker problem.
Thanks for the help,
-Joe
|
|
-
-
-
-
armandolanda


- Joined on 01-21-2008
- Spain

- Points 5
|
As you will see, if you change the window style in the form load event,
then the bitblting becomes very choppy. If you wait and change the
window style in the form unload event, just before the fade out effect,
then you will see an ugly flicker. ==================================================================== The only solution I find is capture the image of the window to the clipboard, and load a wide form with BorderStyle = 0 and put the image of the main form, unload the main form, and do the effect of transparency with this form, the capturewindow image code is how this: Option Explicit
Public Type RECT_Type
left As Long top As Long right As Long bottom As Long
End Type
'The following Public Declare statements are case sensitive.
Public Declare Function GetActiveWindow Lib "User32" () As Long Public Declare Function GetDesktopWindow Lib "User32" () As Long Public Declare Sub GetWindowRect Lib "User32" (ByVal Hwnd As Long, _ lpRect As RECT_Type) Public Declare Function GetDC Lib "User32" (ByVal Hwnd As Long) As Long Public Declare Function CreateCompatibleDC Lib "Gdi32" (ByVal hdc As Long) _ As Long Public Declare Function CreateCompatibleBitmap Lib "Gdi32" (ByVal hdc _ As Long, ByVal nWidth As Long, _ ByVal nHeight As Long) As Long Public Declare Function SelectObject Lib "Gdi32" (ByVal hdc As Long, _ ByVal hObject As Long) As Long Public Declare Function BitBlt Lib "Gdi32" (ByVal hDestDC As Long, _ ByVal X As Long, ByVal Y _ As Long, ByVal nWidth As Long, _ ByVal nHeight As Long, _ ByVal hSrcDC As Long, _ ByVal XSrc As Long, _ ByVal YSrc As Long, _ ByVal dwRop As Long) As Long Public Declare Function OpenClipboard Lib "User32" (ByVal Hwnd As Long) As Long Public Declare Function EmptyClipboard Lib "User32" () As Long Public Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, _ ByVal hMem As Long) As Long Public Declare Function CloseClipboard Lib "User32" () As Long Public Declare Function ReleaseDC Lib "User32" (ByVal Hwnd As Long, _ ByVal hdc As Long) As Long Public Declare Function DeleteDC Lib "Gdi32" (ByVal hdc As Long) As Long
Global Const SRCCOPY = &HCC0020 Global Const CF_BITMAP = 2
Public Function CaptureWindowArea(AccessHwnd As Long) Dim DeskHwnd As Long Dim hdc As Long Dim hdcMem As Long Dim rect As RECT_Type Dim junk As Long Dim fwidth As Long, fheight As Long Dim hBitmap As Long
'DoCmd.Hourglass True
'--------------------------------------------------- ' Get window handle to Windows and Microsoft Access '--------------------------------------------------- DeskHwnd = GetDesktopWindow() AccessHwnd = GetActiveWindow()
'--------------------------------------------------- ' Get screen coordinates of Microsoft Access '--------------------------------------------------- Call GetWindowRect(AccessHwnd, rect) fwidth = rect.right - rect.left fheight = rect.bottom - rect.top
'--------------------------------------------------- ' Get the device context of Desktop and allocate memory '--------------------------------------------------- hdc = GetDC(DeskHwnd) hdcMem = CreateCompatibleDC(hdc) hBitmap = CreateCompatibleBitmap(hdc, fwidth, fheight)
If hBitmap <> 0 Then junk = SelectObject(hdcMem, hBitmap)
'--------------------------------------------- ' Copy the Desktop bitmap to memory location ' based on Microsoft Access coordinates. '--------------------------------------------- junk = BitBlt(hdcMem, 0, 0, fwidth, fheight, hdc, rect.left, _ rect.top, SRCCOPY)
'--------------------------------------------- ' Set up the Clipboard and copy bitmap '--------------------------------------------- junk = OpenClipboard(DeskHwnd) junk = EmptyClipboard() junk = SetClipboardData(CF_BITMAP, hBitmap) junk = CloseClipboard() End If
'--------------------------------------------- ' Clean up handles '--------------------------------------------- junk = DeleteDC(hdcMem) junk = ReleaseDC(DeskHwnd, hdc)
'DoCmd.Hourglass False
End Function
|
|
Page 1 of 1 (10 items)
|
Search
Code Samples
New Members
|