Posted: Fri Jun 29, 2007 4:37 pm
That's not surprising as no window events are being processed in between SetGadgetState commands.
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
ProcedureDLL.l TicksHQ()
Static maxfreq.q
Protected t.q
If maxfreq=0
QueryPerformanceFrequency_(@maxfreq)
maxfreq=maxfreq/1000
EndIf
QueryPerformanceCounter_(@t)
ProcedureReturn t/maxfreq
EndProcedure
Structure REGIONDATA
rdh.RGNDATAHEADER
buffer.l[100000]
EndStructure
; ===========================================================================================
ProcedureDLL GrabRegion(ImageID, transcolor) ; HBITMAP ImageID, COLORREF transcolor
;=======================================================
; =
; Very fast bitmap -> region creator =
; =
; By netmaestro =
; =
; Contributors: eesau, nico, flype =
; =
; June 26, 2007 =
; =
;=======================================================
Structure RGBTRIPLEC
rgbtBlue.b
rgbtGreen.b
rgbtRed.b
EndStructure
GetObject_(ImageID, SizeOf(BITMAP), @bmp.BITMAP)
Protected width = bmp\bmWidth
Protected height = bmp\bmHeight
Protected hVisibleRgn = CreateRectRgn_(0, 0, width, height)
Protected tred = Red(transcolor)
Protected tgreen = Green(transcolor)
Protected tblue = Blue(transcolor)
BmiInfo.BITMAPINFOHEADER
With BmiInfo
\biSize = SizeOf(BITMAPINFOHEADER)
\biWidth = width
\biHeight = -height
\biPlanes = 1
\biBitCount = 24
\biCompression = #BI_RGB
EndWith
bytesperrow = 4*((3*width+3)/4)
*ColorBits = AllocateMemory(bytesperrow*height)
hDC = GetWindowDC_(#Null)
iRes = GetDIBits_(hDC, ImageID, 0, height, *ColorBits, @bmiInfo, #DIB_RGB_COLORS)
ReleaseDC_(#Null, hDC)
Structure_Max=(width*height*16)+SizeOf(RGNDATAHEADER)
*Buffer.RGNDATAHEADER=AllocateMemory(Structure_Max)
*rd.LONG=*Buffer+SizeOf(RGNDATAHEADER)
bufferloc = 0 : rectcount = 0
For y=0 To height-1
pxcount=0
For x=0 To bytesperrow-1 Step 3
*px.RGBTRIPLEC = *ColorBits + bytesperrow * y + x
If *px\rgbtRed&$FF=tred And *px\rgbtGreen&$FF=tgreen And *px\rgbtBlue&$FF=tblue
transcount = 1 : firsttrans = pxcount
While *px\rgbtRed&$FF=tred And *px\rgbtGreen&$FF=tgreen And *px\rgbtBlue&$FF=tblue And x<=bytesperrow-4
transcount+1 : pxcount+1 : x+3 : *px = *ColorBits + bytesperrow * y + x
Wend
rectcount+1
*rd\l = firsttrans : *rd+4
*rd\l = y : *rd+4
*rd\l = firsttrans+transcount : *rd+4
*rd\l = y+1 : *rd+4
EndIf
pxcount+1
Next
Next
With *Buffer
\dwSize = SizeOf(RGNDATAHEADER)
\iType = #RDH_RECTANGLES
\nCount = rectcount
\nRgnSize = rectcount * SizeOf(RECT)
\rcBound\left = 0
\rcBound\top = 0
\rcBound\right = width
\rcBound\bottom = height
EndWith
RegionSize=SizeOf(RGNDATAHEADER)+(rectcount * SizeOf(RECT))
hTransparentRgn = ExtCreateRegion_(#Null, RegionSize, *Buffer)
CombineRgn_(hVisibleRgn, hVisibleRgn, hTransparentRgn, #RGN_XOR)
FreeMemory(*Buffer)
FreeMemory(*ColorBits)
DeleteObject_(hTransparentRgn)
ProcedureReturn hVisibleRgn
EndProcedure
Procedure.l counter(ctr)
StartDrawing(WindowOutput(0))
DrawText(130,190,"Girl "+Str(ctr),$00FF00)
StopDrawing()
SetGadgetText(1,Str(ctr))
ProcedureReturn ctr+1
EndProcedure
; ===========================================================================================
LoadImage(0, "girl.bmp")
OpenWindow(0,0,0,ImageWidth(0),ImageHeight(0),"", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
CreateGadgetList(WindowID(0))
ImageGadget(0,0,0,0,0,ImageID(0))
TextGadget(1, 130,210,50,20,"")
region = GrabRegion(ImageID(0), #White)
SetWindowRgn_(WindowID(0), region, #True)
HideWindow(0,0)
tm=ElapsedMilliseconds()
Repeat
WaitWindowEvent(100)
If ElapsedMilliseconds() > tm + 999
ctr=counter(ctr)
tm=ElapsedMilliseconds()
EndIf
Until GetAsyncKeyState_(#VK_SPACE) & 32768
Code: Select all
;===========================================================================================
ProcedureDLL GrabRegion(ImageID, transcolor) ; HBITMAP ImageID, COLORREF transcolor
;=======================================================
; =
; Very fast bitmap -> region creator =
; =
; By netmaestro =
; =
; Contributors: eesau, nico, flype =
; =
; June 26, 2007 =
; =
;=======================================================
GetObject_(ImageID, SizeOf(BITMAP), @bmp.BITMAP)
Protected width = bmp\bmWidth
Protected height = bmp\bmHeight
Protected hVisibleRgn = CreateRectRgn_(0, 0, width, height)
Protected tred = Red(transcolor)
Protected tgreen = Green(transcolor)
Protected tblue = Blue(transcolor)
BmiInfo.BITMAPINFOHEADER
With BmiInfo
\biSize = SizeOf(BITMAPINFOHEADER)
\biWidth = width
\biHeight = -height
\biPlanes = 1
\biBitCount = 24
\biCompression = #BI_RGB
EndWith
bytesperrow = 4*((3*width+3)/4)
*ColorBits = AllocateMemory(bytesperrow*height)
hDC = GetWindowDC_(#Null)
iRes = GetDIBits_(hDC, ImageID, 0, height, *ColorBits, @bmiInfo, #DIB_RGB_COLORS)
ReleaseDC_(#Null, hDC)
Structure_Max=(width*height*16)+SizeOf(RGNDATAHEADER)
*Buffer.RGNDATAHEADER=AllocateMemory(Structure_Max)
*rd.LONG=*Buffer+SizeOf(RGNDATAHEADER)
bufferloc = 0 : rectcount = 0
For y=0 To height-1
pxcount=0
For x=0 To bytesperrow-1 Step 3
*px.RGBTRIPLE = *ColorBits + bytesperrow * y + x
If *px\rgbtRed&$FF=tred And *px\rgbtGreen&$FF=tgreen And *px\rgbtBlue&$FF=tblue
transcount = 1 : firsttrans = pxcount
While *px\rgbtRed&$FF=tred And *px\rgbtGreen&$FF=tgreen And *px\rgbtBlue&$FF=tblue And x<=bytesperrow-4
transcount+1 : pxcount+1 : x+3 : *px = *ColorBits + bytesperrow * y + x
Wend
rectcount+1
*rd\l = firsttrans : *rd+4
*rd\l = y : *rd+4
*rd\l = firsttrans+transcount : *rd+4
*rd\l = y+1 : *rd+4
EndIf
pxcount+1
Next
Next
With *Buffer
\dwSize = SizeOf(RGNDATAHEADER)
\iType = #RDH_RECTANGLES
\nCount = rectcount
\nRgnSize = rectcount * SizeOf(RECT)
\rcBound\left = 0
\rcBound\top = 0
\rcBound\right = width
\rcBound\bottom = height
EndWith
RegionSize=SizeOf(RGNDATAHEADER)+(rectcount * SizeOf(RECT))
hTransparentRgn = ExtCreateRegion_(#Null, RegionSize, *Buffer)
CombineRgn_(hVisibleRgn, hVisibleRgn, hTransparentRgn, #RGN_XOR)
FreeMemory(*Buffer)
FreeMemory(*ColorBits)
DeleteObject_(hTransparentRgn)
ProcedureReturn hVisibleRgn
EndProcedure
Procedure.l counter(ctr)
srcdc = StartDrawing(WindowOutput(0))
DrawImage(ImageID(1),130,190)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(130,190,"Girl "+Str(ctr),$00FF00)
StopDrawing()
ProcedureReturn ctr+1
EndProcedure
; ===========================================================================================
LoadImage(0, "girl.bmp")
OpenWindow(0,0,0,ImageWidth(0),ImageHeight(0),"", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
CreateGadgetList(WindowID(0))
ImageGadget(0,0,0,0,0,ImageID(0))
DisableGadget(0,1)
GrabImage(0,1,130,190,40,20)
region = GrabRegion(ImageID(0), #White)
SetWindowRgn_(WindowID(0), region, #True)
HideWindow(0,0)
tm=ElapsedMilliseconds()
Repeat
WaitWindowEvent(100)
If ElapsedMilliseconds() > tm + 999
ctr=counter(ctr)
tm=ElapsedMilliseconds()
EndIf
Until GetAsyncKeyState_(#VK_SPACE) & 32768
netmaestro wrote:No, sorry to disappoint, but no API required:
Code: Select all
;============================================================================================================================
; Open the drag target window
;============================================================================================================================
Procedure OpenDragBox()
If Window_dragbox()
;SetWindowLong_(WindowID(#Window_dragbox), #GWL_EXSTYLE, GetWindowLong_(WindowID(#Window_dragbox), #GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
program\dragdrop = 1
AddKeyboardShortcut(#Window_dragbox, #PB_Shortcut_Alt | #PB_Shortcut_D, #Shortcut_dragbox_closedragbox)
GrabImage(#Image_dragbox_dropzone, #Image_dragbox_counter, 0, 0, 60, 25) ; Create counter image
region = GrabRegion(ImageID(#Image_dragbox_dropzone), #Black) ; Create the region for the included picture
SetWindowRgn_(WindowID(#Window_dragbox), region, #True) ; Clip the image to the calculated region
hBrush = CreatePatternBrush_(ImageID(#Image_dragbox_dropzone)) ; Set the window background to the image.
SetClassLong_(WindowID(#Window_dragbox), #GCL_HBRBACKGROUND, hBrush) ; Subclass the window to allow dragging around
DrawCounter(50550500) ; Draw the counter with an initial value of 0
HideWindow(#Window_dragbox, 0) ; Show the window now that everything is ready
EnableWindowDrop(#Window_dragbox, #PB_Drop_Files, #PB_Drag_Copy) ; Enable dragging and dropping on this window
StickyWindow(#Window_dragbox, 1) ; Make this window stay on top of all others
EndIf
EndProcedure
Code: Select all
;============================================================================================================================
; Draw the file count on the drop target
;============================================================================================================================
Procedure.l DrawCounter(Counter)
StartDrawing(WindowOutput(#Window_dragbox))
DrawImage(ImageID(#Image_dragbox_counter), 20, 20)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(20, 20, Str(Counter) + " Counter me baby")
StopDrawing()
; ProcedureReturn ctr + 1
EndProcedure