Ich hab's auch mal probiert, der Einfachheit halber ohne double buffering. Die gesamte client area wird für die Darstellung genutzt.
- Alpha.png (148.71 KiB) 8599 mal betrachtet
Flutscht wie eine Eins. Painten auch ohne Probleme. Nachfolgend der komplette code des Programms.
--- snip ---
#include "CockpitGuiLibs.ch"
#include "CrackAndDispatch.ch"
#include "Windows.ch"
FUNCTION Main
UserTask(AlphaBlendWindow())
Application():Run()
RETURN NIL
CLASS AlphaBlendWindow FROM UserTaskWindow,CrackAndDispatch
EXPORTED:
VAR trackBar
VAR image
VAR cxSource
VAR cySource
VAR cx,cy
METHOD OnCreate
METHOD OnSize
METHOD OnPaint
METHOD OnNotify
ENDCLASS
METHOD AlphaBlendWindow:OnCreate
LOCAL bitmap
* Create the trackbar
::trackBar := TrackBarControl():Create(,(TBS_BOTTOM|TBS_AUTOTICKS|TBS_TOOLTIPS|WS_CHILD|WS_VISIBLE),10,10,100,100,self)
* Set its range
::trackBar:SetRange(.F.,0,255)
* Set ticks in increments of 10
::trackBar:TicFreq := 10
* Load the image
IF (::image := LoadImage(,"JellyFish.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE)) == NIL
SysError("Cannot load bitmap.")
ENDIF
* Get its size and take it down
bitmap := BITMAPSTRUCT():New()
::image:GetObject(,@bitmap)
::cxSource = bitmap:bmWidth
::cySource = bitmap:bmHeight
RETURN 0
METHOD AlphaBlendWindow:OnSize(_,cx,cy)
* Reposition the trackbar
::trackBar:Move(100,cy-50,cx-200,30,TRUE)
* take down the client area size
::cx := cx
::cy := cy
RETURN 0
METHOD AlphaBlendWindow:OnPaint
LOCAL ps,dc,dcMem,bf
* Begin painting
dc := ::BeginPaint(@ps)
* Create a device context for the bitmap
dcMem := dc:CreateCompatibleDC()
* Put it in
dcMem:SelectObject(::image)
* Prepare the blending parameters
bf := BLENDFUNCTION():New()
bf:BlendOp := AC_SRC_OVER
bf:SourceConstantAlpha := ::trackBar:sliderPos && The blending level is taken from the track bar
* Go blending
dc:AlphaBlend( 0, 0, ::cx, ::cy, dcMem, 0, 0, ::cxSource, ::cySource, bf)
* Discard the memory device context
dcMem:Delete()
* We're done painting
::EndPaint(ps)
RETURN 0
METHOD AlphaBlendWindow:OnNotify
::InvalidateRect(,.T.)
RETURN 0
--- snap ---