Code:
Option Explicit
Private Declare Function UpdateLayeredWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal hdcDst As Long, ByRef pptDst As Any, ByRef psize As Any, ByVal hdcSrc As Long, ByRef pptSrc As Any, ByVal crKey As Long, ByRef pblend As Long, ByVal dwFlags As Long) As Long
Private Type Size
cx As Long
cy As Long
End Type
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_EXSTYLE As Long = -20
Private Const WS_EX_LAYERED As Long = &H80000
Private Const WS_EX_TRANSPARENT As Long = &H20&
Private Const WS_EX_TOPMOST As Long = &H8&
Private Const SW_SHOWNA As Long = 8
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Private Declare Function GdiplusStartup Lib "gdiplus" (Token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As Long
Private Declare Sub GdiplusShutdown Lib "gdiplus" (ByVal Token As Long)
Private Declare Function ClientToScreen Lib "user32.dll" (ByVal hwnd As Long, ByRef lpPoint As Any) As Long
Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long, hGraphics As Long) As Long
Private Declare Function GdipDeleteGraphics Lib "gdiPlus.dll" (ByVal mGraphics As Long) As Long
Private Declare Function GdipLoadImageFromFile Lib "gdiplus" (ByVal FileName As Long, hImage As Long) As Long
Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As Long
Private Declare Function GdipDrawImageRectI Lib "gdiPlus.dll" (ByVal mGraphics As Long, ByVal mImage As Long, ByVal mX As Long, ByVal mY As Long, ByVal mWidth As Long, ByVal mHeight As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Declare Sub FillMemory Lib "kernel32.dll" Alias "RtlFillMemory" (ByRef Destination As Any, ByVal Length As Long, ByVal Fill As Byte)
Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hDC As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32.dll" (ByVal hDC As Long, ByRef pBitmapInfo As Any, ByVal un As Long, ByRef lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
Private Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hDC As Long) As Long
Private Const LWA_ALPHA As Long = &H2
Private Const ULW_ALPHA As Long = &H2
Private Const AC_SRC_ALPHA As Long = &H1
Private m_DC As Long
Private m_DCbmp As Long
Private m_DIBptr As Long
Private m_SizeImage As Size
Private m_SizeSlide As Size
Private Sub Command1_Click()
Dim gdiSI As GdiplusStartupInput, gToken As Long
Dim X As Long, Y As Long, tSize As Size
Dim hDib As Long, bmpi As BITMAPINFOHEADER
Dim gImage As Long, gGraphics As Long
gdiSI.GdiplusVersion = 1
GdiplusStartup gToken, gdiSI
m_DC = CreateCompatibleDC(Me.hDC)
If m_DC = 0& Then
GdiplusShutdown gToken
Stop ' error
Exit Sub
End If
Load frmSlide
SetWindowLong frmSlide.hwnd, GWL_EXSTYLE, GetWindowLong(frmSlide.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED Or WS_EX_TOPMOST Or WS_EX_TRANSPARENT
m_SizeImage.cx = Shape1.Width \ Screen.TwipsPerPixelX
m_SizeImage.cy = Shape1.Height \ Screen.TwipsPerPixelY
m_SizeSlide.cx = m_SizeImage.cx
m_SizeSlide.cy = m_SizeImage.cy + Shape1.Top \ Screen.TwipsPerPixelY
tSize.cx = Shape1.Left \ Screen.TwipsPerPixelX
ClientToScreen Me.hwnd, tSize
frmSlide.Move tSize.cx * Screen.TwipsPerPixelX, tSize.cy * Screen.TwipsPerPixelY, Shape1.Width, Shape1.Top + Shape1.Height
With bmpi
.biBitCount = 32
.biHeight = m_SizeSlide.cy
.biWidth = m_SizeSlide.cx
.biPlanes = 1
.biSize = 40
End With
hDib = CreateDIBSection(Me.hDC, bmpi, 0&, m_DIBptr, 0&, 0&)
If hDib = 0& Then
DeleteDC m_DC
m_DC = 0&
GdiplusShutdown gToken
Stop ' error
Exit Sub
End If
m_DCbmp = SelectObject(m_DC, hDib)
GdipLoadImageFromFile StrPtr(App.Path & "\Spider.png"), gImage
GdipCreateFromHDC m_DC, gGraphics
GdipDrawImageRectI gGraphics, gImage, 0, m_SizeSlide.cy - m_SizeImage.cy, m_SizeImage.cx, m_SizeImage.cy
GdipDeleteGraphics gGraphics
GdipDisposeImage gImage
GdiplusShutdown gToken
X = 255& * &H10000 Or (AC_SRC_ALPHA * &H1000000)
tSize.cx = 0: tSize.cy = 0
UpdateLayeredWindow frmSlide.hwnd, 0&, ByVal 0&, m_SizeSlide, m_DC, tSize, 0&, X, ULW_ALPHA
ShowWindow frmSlide.hwnd, SW_SHOWNA ' shows window without setting focus to it
Timer1.Interval = 10
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Me.Width = 7665: Me.Height = 5295
Shape1.Move 2865, 2235, 2520, 2430
Command1.Caption = "Slide Up"
If Len(Dir(App.Path & "\Spider.Png")) = 0 Then
MsgBox "Sample project needs the spider.png file in the app.path"
Unload Me
End If
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Dim lStep As Long, lBF As Long, nrBytes As Long, lOffset As Long
Dim hBmp As Long, tSize As Size
Const nrLinesPerScroll As Long = 5
lStep = Val(Timer1.Tag) + nrLinesPerScroll
If lStep >= m_SizeSlide.cy - nrLinesPerScroll Then
Unload frmSlide
DeleteObject SelectObject(m_DC, m_DCbmp)
DeleteDC m_DC
m_DC = 0
Timer1.Tag = ""
Exit Sub
End If
nrBytes = m_SizeImage.cx * 4& * (m_SizeSlide.cy - nrLinesPerScroll)
lOffset = m_SizeImage.cx * 4& * nrLinesPerScroll
' dangerous code: manipulating DIB via pointers. Testing only
hBmp = SelectObject(m_DC, m_DCbmp)
CopyMemory ByVal m_DIBptr + lOffset, ByVal m_DIBptr, nrBytes
FillMemory ByVal m_DIBptr, lOffset, 0
SelectObject m_DC, hBmp
lBF = 255& * &H10000 Or (AC_SRC_ALPHA * &H1000000)
UpdateLayeredWindow frmSlide.hwnd, 0&, ByVal 0&, m_SizeSlide, m_DC, tSize, 0&, lBF, ULW_ALPHA
Timer1.Tag = lStep
Timer1.Enabled = True
End Sub