MaxGUI Requests

BlitzMax Forums/BlitzMax GUI Programming/MaxGUI Requests

That's a good idea. An optional gadget for GadgetX(), Y() commands. Here's how I did mine, though this isn't as user-friendly:

Strict

Import pub.win32
Import maxgui.maxgui

Extern "win32"
	Function ScreenToClient:Int(hwnd,lpPoint:Byte Ptr)="ScreenToClient@8"
	Function ClientToScreen:Int(hwnd,lpPoint:Byte Ptr)="ClientToScreen@8"
	Function SetCursorPos:Int(x,y)="SetCursorPos@8"
	Function GetCursorPos:Int(lpPoint:Byte Ptr)="GetCursorPos@4"
EndExtern

Function coord:TCoord(x,y)
	Local screencoord:TCoord=New TCoord
	screencoord.x=x
	screencoord.y=y
	Return screencoord
EndFunction

Type TCoord
	Field x,y
	
	Method pointer:Byte Ptr()
		Return Varptr x
	EndMethod
	
	Method copy:TCoord()
		Return Coord(x,y)
	EndMethod
	
EndType

Function GetGadgetCoord:TCoord(gadget:TGadget,glob=0)
	If glob
		Return TFormCoord( Coord(GadgetX(gadget),GadgetY(gadget)),GadgetGroup(gadget),Null )
	Else
		Return Coord(GadgetX(gadget),GadgetY(gadget))
	EndIf
EndFunction

Function SetMouseCoord(c:TCoord,gadget:TGadget=Null)
	If gadget c=TFormCoord(c,gadget,Null)
	setcursorpos c.x,c.y
EndFunction

Function TFormCoord:TCoord(c:TCoord,src:TGadget,dst:TGadget)
	c=c.copy()
	If src ClientToScreen QueryGadget(src,QUERY_HWND),c.pointer()
	If dst ScreenToClient QueryGadget(dst,QUERY_HWND),c.pointer()
	Return c
EndFunction