vor langer Zeit mal gebraucht und umgebaut (für meine CWL ^_^).
... Bei Windows ist
die transparente Farbe $ffffff.
Code: Alles auswählen
; 05 Okt 2005 20:09 © by Fred; bugfixes by Mischa; changed by PMV - english PB-Forum
;http://forums.purebasic.com/english/viewtopic.php?t=12829&start=0
Procedure CWLDrawTransparentImage(DC, Bitmap, x, y, Width, Height) ;transparent spritecolor is rgb(255,255,255)
;How to use:
;DC = StartDrawing(WindowOutput(0))
; DrawTransparentimage(DC,UseImage(Image),X,Y,32,32)
; ReleaseDC_(WindowID(0),DC)
;StopDrawing()
; First, create some DC's. These are our gateways To associated
; bitmaps in RAM
maskDC = CreateCompatibleDC_(DC)
tempDC = CreateCompatibleDC_(DC)
SourceDC = CreateCompatibleDC_(DC)
DeleteObject_(SelectObject_(SourceDC, Bitmap))
; Then, we need the bitmap. Note that we create a monochrome
; bitmap here!
; This is a trick we use For creating a mask fast enough.
hMaskBmp = CreateBitmap_(Width, Height, 1, 1, 0)
hTempBmp = CreateCompatibleBitmap_(DC, Width, Height)
; Then we can assign the bitmaps to the DCs
DeleteObject_(SelectObject_(maskDC, hMaskBmp))
DeleteObject_(SelectObject_(tempDC, hTempBmp))
; Now we copy the image into the monochrome bitmap.
BitBlt_ (maskDC, 0, 0, Width, Height, SourceDC, 0, 0, #SRCCOPY)
; The first we do with the mask is To MergePaint it into the
; destination.
; This will punch a WHITE hole in the background exactly were
; we want the graphics To be painted in.
;BitBlt_ (DC, X, Y, Width, Height, maskDC, 0, 0, #MERGEPAINT)
BitBlt_ (tempDC, 0, 0, Width, Height, maskDC, 0, 0, #SRCCOPY)
BitBlt_ (DC, X, Y, Width, Height, tempDC, 0, 0, #MERGEPAINT)
; Both target And source are clean. All we have To do is To And
; them together!
BitBlt_ (DC, X, Y, Width, Height, SourceDC, 0, 0, #SRCAND)
; Now all we have To do is To clean up after us And free system
; resources..
DeleteObject_(hMaskBmp)
DeleteObject_(hTempBmp)
DeleteDC_(maskDC)
DeleteDC_(SourceDC)
DeleteDC_(tempDC)
EndProcedure
; -------------------------------------------------------
OpenWindow(0, 0,0, 300, 30, "ProgressBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
hGadget = ProgressBarGadget(0, 0, 0, 300, 30, 0, 1000)
DC = GetDC_(hGadget)
hImage = CreateImage(0, 50, 20)
Timer = ElapsedMilliseconds()
Rect.Rect
Rect\left = 125
Rect\top = 7
Rect\right = 175
Rect\bottom = 25
Repeat
If Timer + 100 <= ElapsedMilliseconds()
Progress + 1
SetGadgetState(0, Progress)
InvalidateRect_(hGadget, @Rect, #True)
Timer = ElapsedMilliseconds()
EndIf
Select WaitWindowEvent(10)
Case #WM_PAINT
DC = GetDC_(hGadget)
StartDrawing(ImageOutput(0))
Box(0, 0, ImageWidth(0), ImageHeight(0), $ffffff)
DrawText(0, 0, StrF(Progress / 10, 1) + "%", 0, $ffffff)
StopDrawing()
CWLDrawTransparentImage(DC, hImage, 125, 5, ImageWidth(0), ImageHeight(0))
ReleaseDC_(hGadget,DC)
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
geschoben, jetzt läufts auf XP und Vista ohne flimmern.