Working with API and TextOut

BlitzMax Forums/BlitzMax Programming/Working with API and TextOut

Regular K(Posted 2006) [#1]
SuperStrict

Extern "win32"
	Function GetAsyncKeyState:Int(key:Int)
	Function GetWindowDC(hwnd:Int)
	Function GetForegroundWindow:Int()
	Function TextOutA:Int(dc:Int,x:Int,y:Int,txt:Byte Ptr,l:Int)
End Extern

Global CurrentDC:Int

Repeat
	CurrentDC=GetWindowDC(GetForegroundWindow())
	DrawTextOut("APPLES",10,10)
	Delay 30
Forever

Function DrawTextOut(Txt:String,X:Int,Y:Int)
	If CurrentDC<>0
		Local TxtPtr:Byte Ptr=Txt.ToCString()
		Print TextOutA(CurrentDC,X,Y,TxtPtr,Len(Txt))
	EndIf
End Function


EDIT: Got it to work, the code above can be used to draw text ot the screen using the WinAPI ;) I have to convert the string to a CString, confusing stuff :P


ozak(Posted 2006) [#2]
Hehe. This is great fun :)


Yan(Posted 2006) [#3]
Hehe...BMax can do the string conversion for you (without the memory leak too)...
SuperStrict

Extern "win32"
	Function GetAsyncKeyState:Int(key:Int)
	Function GetWindowDC(hwnd:Int)
	Function GetForegroundWindow:Int()
	Function TextOutA:Int(dc:Int, x:Int, y:Int, txt$z, l:Int)
End Extern

Global CurrentDC:Int

SeedRnd MilliSecs()

Repeat
	CurrentDC=GetWindowDC(GetForegroundWindow())
	DrawTextOut("APPLES", Rand(800), Rand(600))
	Delay 30
Forever

Function DrawTextOut(Txt:String,X:Int,Y:Int)
	If CurrentDC<>0
		Print TextOutA(CurrentDC, X, Y, Txt, Txt.length)
	EndIf
End Function



Regular K(Posted 2006) [#4]
Getting rid of that memory leak sure comes in use ;)