Working with API and TextOut
BlitzMax Forums/BlitzMax Programming/Working with API and TextOut
| ||
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 |
| ||
| Hehe. This is great fun :) |
| ||
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 |
| ||
| Getting rid of that memory leak sure comes in use ;) |