Help with SetConsoleCursorPosition

BlitzMax Forums/BlitzMax Beginners Area/Help with SetConsoleCursorPosition

Hezkore(Posted 2009) [#1]
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?


plash(Posted 2009) [#2]
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)



Hezkore(Posted 2009) [#3]
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.


plash(Posted 2009) [#4]
Hmm, arrays aren't working either.


Hezkore(Posted 2009) [#5]
Yeah tried that too, heh...
Feels like I've tried everything. x_X


grable(Posted 2009) [#6]
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!"



Hezkore(Posted 2009) [#7]
Cheers mate, you've saved me heh.


plash(Posted 2009) [#8]
Doesn't work for me.

EDIT: Doh! 'Strict' is evil. Works a treat!


EOF(Posted 2009) [#9]
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



Hezkore(Posted 2009) [#10]
Hey thanks Jim Brown (and everyone else) I might use this if I'm allowed. :3


EOF(Posted 2009) [#11]
Sure


GW(Posted 2009) [#12]
This is pretty nice Jim!
looking over the code, where are you getting the hwnd of the console window?


EOF(Posted 2009) [#13]
Thanks
The console window is 'handle' based. The following line retains the handle after opening the console window:
Console.hnd=AllocConsole()



em22(Posted 2009) [#14]
Awesome :)


Chroma(Posted 2010) [#15]
...