Page 1 of 1

Transparent white color in alpha window [Windows]

Posted: Mon Dec 29, 2025 4:41 pm
by Michael Vogel
Since I have very time for programming I tend to get lost quickly - could ask the great AI but I believe in the cleverness of real experts. So my problem here is that the white circles around the mouse cursor are shown opaque but not transparent.

Code: Select all

; Define

	EnableExplicit

	Enumeration
		#WinMain
		#WinCursor
		#ImgCursor
	EndEnumeration

	Structure CursorType
		Updating.i
		Size.i
		Timer.i
	EndStructure

	Global Cursor.CursorType

	With Cursor
		\Size=150
	EndWith

; EndDefine

Procedure InitCursorWindow()

	CreateImage(#ImgCursor,Cursor\Size,Cursor\Size,32)

	OpenWindow(#WinCursor,0,0,Cursor\Size,Cursor\Size,"",#PB_Window_BorderLess|#PB_Window_Invisible)
	SetWindowColor(#WinCursor,#Red)
	SetWindowLongPtr_(WindowID(#WinCursor),#GWL_EXSTYLE,#WS_EX_LAYERED|#WS_EX_TOOLWINDOW|#WS_EX_TOPMOST)

	StickyWindow(#WinCursor,1)
	HideWindow(#WinCursor,0)

EndProcedure
Procedure DrawCursor(uID,uMsg,du,d1,d2)

	Protected hdc
	Protected ContextOffset.POINT
	Protected BlendMode.BLENDFUNCTION
	Protected size.Size
	Protected mouse.Point

	If Cursor\Updating=#Null
		Cursor\Updating=#True
		hdc=StartDrawing(ImageOutput(#ImgCursor))
		DrawingMode(#PB_2DDrawing_AllChannels)
		Box(0,0,150,150,RGBA(0,0,0,0))
		Circle(75,75,74,$40ffffff)
		;Circle(75,75,74,RGBA($FF,$FF,$FF,$01))
		Circle(75,75,54,$10000000)
		Circle(75,75,34,$40000000)
		Circle(75,75,14,$10ffffff)

		size\cx=Cursor\Size
		size\cy=Cursor\Size

		BlendMode\SourceConstantAlpha = 255
		BlendMode\AlphaFormat = 1


		With BlendMode
			\AlphaFormat=	#AC_SRC_ALPHA
			;\SourceConstantAlpha=10
			\BlendOp=		0
			\BlendFlags=	0
		EndWith

		UpdateLayeredWindow_(WindowID(#WinCursor),0,0,@size,hdc,@ContextOffset,0,@BlendMode,2)
		StopDrawing()

		GetCursorPos_(mouse)
		ResizeWindow(#WinCursor,mouse\x-75,mouse\y-75,150,150)
	EndIf

	Cursor\Updating=#Null

EndProcedure
Procedure Main()

	InitCursorWindow()
	Cursor\Timer=timeSetEvent_(10,1,@DrawCursor(),#WinCursor,#TIME_PERIODIC)

	Repeat
		WaitWindowEvent(10)
	Until GetAsyncKeyState_(#VK_LBUTTON) & 32768

	While Cursor\Updating
		Debug "*wait*"
		Delay(1)
	Wend
	timeKillEvent_(Cursor\Timer)

EndProcedure

Main()

Re: Transparent white color in alpha window [Windows]

Posted: Mon Dec 29, 2025 6:18 pm
by infratec
If you use AC_SRC_ALPHA read the meaning field.

https://learn.microsoft.com/en-us/windo ... ndfunction

40FFFFFF is not valid/possible

Code: Select all

		Circle(75,75,74,$40404040)
		Circle(75,75,54,$10000000)
		Circle(75,75,34,$40000000)
		Circle(75,75,14,$10101010)

Re: Transparent white color in alpha window [Windows]

Posted: Mon Dec 29, 2025 7:39 pm
by JHPJHP
Post removed; answer was incorrect and misleading.

Re: Transparent white color in alpha window [Windows]

Posted: Mon Dec 29, 2025 8:10 pm
by Michael Vogel
Thanks for your help, thought it would match to Dst.Red = Src.Red + (1 - Src.Alpha) * Dst.Red and so on...

Did some first steps now to enable/disable the cursor effect - I'm happy with the actual state - thank you infratec and all others in the forum for being so helpful all the time.

Code: Select all

; Define

	EnableExplicit

	Enumeration
		#WinMain
		#WinCursor
		#BtnCursor
		#BtnQuit
		#ImgCursor
		#ImgInfo
	EndEnumeration

	Structure CursorType
		Mode.i
		Updating.i
		AllDone.i
		Size.i
		Midpoint.i
		Timer.i
		Phase.i
		Index.i
		Ticks.i
	EndStructure

	Global Cursor.CursorType

	With Cursor
		\Size=		150
		\Midpoint=	\Size/2
	EndWith

	DataSection
		CursorCircles:
		Data.i $18181818,$30303030,$18181818,$0,$10000000,$20000000,$10000000,0
	EndDataSection

; EndDefine

Procedure InitCursorWindow()

	CreateImage(#ImgCursor,Cursor\Size,Cursor\Size,32)

	OpenWindow(#WinCursor,0,0,Cursor\Size,Cursor\Size,"",#PB_Window_BorderLess|#PB_Window_Invisible)
	SetWindowLongPtr_(WindowID(#WinCursor),#GWL_EXSTYLE,#WS_EX_LAYERED|#WS_EX_TOOLWINDOW);|#WS_EX_TOPMOST)

	; SetWindowColor(#WinCursor,#Red)
	; StickyWindow(#WinCursor,1)
	; HideWindow(#WinCursor,1)

EndProcedure
Procedure DrawCursor(id,msg,du,d1,d2)

	Protected hdc,n,z
	Protected ContextOffset.POINT
	Protected BlendMode.BLENDFUNCTION
	Protected size.Size
	Protected mouse.Point

	: With Cursor

	If ElapsedMilliseconds()>\Ticks
		\Ticks=ElapsedMilliseconds()+15
		\Phase+1
		If \Phase=4
			\Phase=0
			\Index=(\Index+1)&7
		EndIf
	EndIf

	If \Updating=#Null And \AllDone=#Null
		\Updating=#True
		hdc=StartDrawing(ImageOutput(#ImgCursor))
		DrawingMode(#PB_2DDrawing_AllChannels)
		Box(0,0,150,150,RGBA(0,0,0,0))
		n=74-\Phase
		z=\Index
		While n>10
			Circle(\Midpoint,\Midpoint,n,PeekI(?CursorCircles+z*SizeOf(Integer)))
			n-4
			z=(z+7)&7
		Wend
		Circle(\Midpoint,\Midpoint,2,0)
		
		size\cx=Cursor\Size
		size\cy=Cursor\Size

		: EndWith :

		BlendMode\SourceConstantAlpha = 255
		BlendMode\AlphaFormat = 1

		With BlendMode
			\AlphaFormat=	#AC_SRC_ALPHA
			\SourceConstantAlpha=255
			\BlendOp=		#AC_SRC_OVER
			\BlendFlags=	#Null
		EndWith

		UpdateLayeredWindow_(WindowID(#WinCursor),0,0,@size,hdc,@ContextOffset,0,@BlendMode,2)
		StopDrawing()

		GetCursorPos_(mouse)
		; ResizeWindow(#WinCursor,mouse\x-75,mouse\y-75,150,150)
		; MoveWindow_(WindowID(#WinCursor),mouse\x-75,mouse\y-75,Cursor\Size,Cursor\Size,#Null)
		SetWindowPos_(WindowID(#WinCursor),#HWND_TOPMOST,mouse\x-75,mouse\y-75,Cursor\Size,Cursor\Size,#SWP_NOACTIVATE|#SWP_NOSIZE|#SWP_NOREDRAW|#SWP_NOSENDCHANGING|#SWP_NOCOPYBITS)

	EndIf

	Cursor\Updating=#Null

EndProcedure
Procedure CursorOn(mode)

	Cursor\Timer=timeSetEvent_(10,1,@DrawCursor(),#WinCursor,#TIME_PERIODIC)
	Debug Cursor\Timer
	Cursor\Mode=mode
	HideWindow(#WinCursor,0,#PB_Window_NoActivate)

EndProcedure
Procedure CursorOff()

	With Cursor

		If \Timer
			HideWindow(#WinCursor,1)
			While \Updating
				\AllDone=#True
				DrawCursor(#Null,#Null,#Null,#Null,#Null)
				Delay(1)
			Wend

			timeKillEvent_(\Timer)
			\Timer=#Null
			\Mode=#Null
			\AllDone=#Null
		EndIf

	EndWith

EndProcedure
Procedure Main()

	Protected event
	Protected quit

	InitCursorWindow()

	OpenWindow(#WinMain,10,10,300,100,"Cursor Finder")
	ButtonGadget(#BtnCursor,20,20,120,50,"Cursor On")
	ButtonGadget(#BtnQuit,160,20,120,50,"Quit")

	Repeat

		event=WaitWindowEvent(10)
		Select event

		Case #PB_Event_Gadget,#PB_Event_Menu
			Select EventGadget()
			Case #BtnCursor
				If Cursor\Mode
					CursorOff()
					SetGadgetText(#BtnCursor,"Cursor On")
				Else
					CursorOn(1)
					SetGadgetText(#BtnCursor,"Cursor Off")
				EndIf
			Case #BtnQuit
				quit=#True
			EndSelect

		Case #PB_Event_CloseWindow
			quit=#True

		EndSelect

		;If GetAsyncKeyState_(#VK_LBUTTON) & 32768
		;	CursorOff()
		;EndIf

	Until quit

	CursorOff()

EndProcedure

Main()