Help with SetConsoleCursorPosition
BlitzMax Forums/BlitzMax Beginners Area/Help with SetConsoleCursorPosition
| ||
Right, so I'm trying to use SetConsoleCursorPosition to set the cursors position in my console window.Extern "Win32" Function SetConsoleCursorPosition(hbuffOUT%, xyCoord:Byte Ptr) End Extern SetConsoleCursorPosition(stdOUT, Byte Ptr(10)) DOES work but I can only set its X position, how would I set its Y position? |
| ||
Try something like this (data types might need to be changed):Type TCoord Field x:Short Field y:Short Method Set(_x:Short, _y:Short) x = _x y = _y End Method End Type Local coord:TCoord = New TCoord coord.Set(10, 5) SetConsoleCursorPosition(stdOUT, coord) |
| ||
That was what I first tried but it just doesn't work :/
Extern "Win32"
Function GetStdHandle:Int(nStdHandle:Int)
Function SetConsoleCursorPosition(hbuffOUT%, xyCoord:Byte Ptr)
End Extern
Type TCoord
Field x:Short
Field y:Short
Method Set(_x:Short, _y:Short)
x = _x
y = _y
End Method
End Type
Local stdOUT% = GetStdHandle(- 11)
Local coord:TCoord = New TCoord
coord.Set(5, 10)
SetConsoleCursorPosition(stdOUT, coord)
Print("Testing!")
Delay 1000
Setting xyCoord:Byte Ptr to xyCoord:TCoord does not help either. |
| ||
| Hmm, arrays aren't working either. |
| ||
| Yeah tried that too, heh... Feels like I've tried everything. x_X |
| ||
COORD should not be a pointer, it is copied by value in c.. so treat it as an Int in stead.Extern "Win32" Function SetConsoleCursorPosition( hbuffOUT%, coord:Int) EndExtern Function MakeCoord:Int( x:Int, y:Int) Return y Shl 16 | x EndFunction SetConsoleCursorPosition( stdout, MakeCoord(70,20)) WriteStdOut "it works!" |
| ||
| Cheers mate, you've saved me heh. |
| ||
| Doesn't work for me. EDIT: Doh! 'Strict' is evil. Works a treat! |
| ||
| I have a (almost) complete Console Control library here if you are interested It has functionality to clear the screen, change fore/back colours, write text anywhere in the screen, and accept user input ![]() DEMO #1 DEMO #2 CONSOLECONTROL.bmx |
| ||
| Hey thanks Jim Brown (and everyone else) I might use this if I'm allowed. :3 |
| ||
| Sure |
| ||
| This is pretty nice Jim! looking over the code, where are you getting the hwnd of the console window? |
| ||
| Thanks The console window is 'handle' based. The following line retains the handle after opening the console window: Console.hnd=AllocConsole() |
| ||
| Awesome :) |
| ||
| ... |
