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 LWAALPHA = 2
Private Const GWLEXSTYLE = (-20)
Private Const WSEXLAYERED = &H80000
Dim iLeft As Integer
Private Sub FormLoad()
'Change window style to layered
'Comment out the code for smooth scrolling (disables fade effect)
SetWindowLong Form1.hwnd, GWLEXSTYLE, GetWindowLong(Form1.hwnd, _
GWLEXSTYLE) Or WSEXLAYERED
SetLayeredWindowAttributes Form1.hwnd, 0, 255, LWAALPHA
End Sub
Private Sub FormUnload(Cancel As Integer)
'Can't change the window style here, because it creates flicker
'Cut and paste the FormLoad 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
Enter your message below
Sign in or Join us (it's free).