1. Hide Cursor in Console Window
- Posted by euphoric (admin) Jul 08, 2009
- 1226 views
How can I hide the cursor in a Windows console window (using euiw)?
I tried using cursor(NO_CURSOR) but that doesn't work, and I can't find the docs for cursor() in the online Manual. It didn't cause a crash so it seems to be a built-in without docs.
2. Re: Hide Cursor in Console Window
- Posted by jacques_desch Jul 08, 2009
- 1264 views
use win32 API call SetConsoleCursorInfo()
ref: http://msdn.microsoft.com/en-us/library/ms686019(VS.85).aspx
--code sample euphoria 3.1 include dll.e constant kernel32=open_dll("kernel32.dll") constant iGetStdHandle=define_c_func(kernel32,"GetStdHandle",{C_INT},C_INT) constant STD_INPUT_HANDLE=-10,STD_OUTPUT_HANDLE=-11,STD_ERROR_HANDLE=-12 global function GetStdHandle(integer std_handle_number) return c_func(iGetStdHandle,{std_handle_number}) end function constant iSetConsoleCursorInfo=define_c_func(kernel32,"SetConsoleCursorInfo",{C_POINTER,C_POINTER},C_UINT) constant iGetConsoleCursorInfo=define_c_func(kernel32,"GetConsoleCursorInfo",{C_POINTER,C_POINTER},C_UINT) --ShowConsoleCursor --show or hide console cursor --hScreen is handle of console output buffer returned by GetStdHandle(STD_OUTPUT_HANDLE) --visible is boolean if TRUE show cursor if FALSE hide it. global procedure ShowConsoleCursor(atom hScreen,integer visible) atom fnVal, pCursorInfo pCursorInfo=allocate(8) fnVal=c_func(iGetConsoleCursorInfo,{hScreen,pCursorInfo}) poke4(pCursorInfo+4,visible) fnVal=c_func(iSetConsoleCursorInfo,{hScreen,pCursorInfo}) free(pCursorInfo) end procedure
not tested, I'm writing this on a linux box, but should work
jacques
How can I hide the cursor in a Windows console window (using euiw)?
I tried using cursor(NO_CURSOR) but that doesn't work, and I can't find the docs for cursor() in the online Manual. It didn't cause a crash so it seems to be a built-in without docs.
3. Re: Hide Cursor in Console Window
- Posted by euphoric (admin) Jul 09, 2009
- 1241 views
use win32 API call SetConsoleCursorInfo()
ref: http://msdn.microsoft.com/en-us/library/ms686019(VS.85).aspx
This doesn't work for me:
ShowConsoleCursor( GetStdHandle( STD_OUTPUT_HANDLE ), 0 )
Is that the right thing to do?
4. Re: Hide Cursor in Console Window
- Posted by jacques_desch Jul 09, 2009
- 1296 views
use win32 API call SetConsoleCursorInfo()
ref: http://msdn.microsoft.com/en-us/library/ms686019(VS.85).aspx
This doesn't work for me:
ShowConsoleCursor( GetStdHandle( STD_OUTPUT_HANDLE ), 0 )
Is that the right thing to do?
the following code works for me on windows xp pro sp3 in a cmd.exe console
as indicated I'm using euphoria 3.1
--code sample euphoria 3.1 include dll.e include machine.e constant kernel32=open_dll("kernel32.dll") constant iGetStdHandle=define_c_func(kernel32,"GetStdHandle",{C_INT},C_INT) constant STD_INPUT_HANDLE=-10,STD_OUTPUT_HANDLE=-11,STD_ERROR_HANDLE=-12 global function GetStdHandle(integer std_handle_number) return c_func(iGetStdHandle,{std_handle_number}) end function constant iSetConsoleCursorInfo=define_c_func(kernel32,"SetConsoleCursorInfo",{C_POINTER,C_POINTER},C_UINT) constant iGetConsoleCursorInfo=define_c_func(kernel32,"GetConsoleCursorInfo",{C_POINTER,C_POINTER},C_UINT) --ShowConsoleCursor --show or hide console cursor --hScreen is handle of console output buffer returned by GetStdHandle(STD_OUTPUT_HANDLE) --visible is boolean if TRUE show cursor if FALSE hide it. global procedure ShowConsoleCursor(atom hScreen,integer visible) atom fnVal, pCursorInfo pCursorInfo=allocate(8) fnVal=c_func(iGetConsoleCursorInfo,{hScreen,pCursorInfo}) poke4(pCursorInfo+4,visible) fnVal=c_func(iSetConsoleCursorInfo,{hScreen,pCursorInfo}) free(pCursorInfo) end procedure ShowConsoleCursor(GetStdHandle(STD_OUTPUT_HANDLE),1) puts(1,"cursor visible now") while get_key()=-1 do end while puts(1,"\ncursor hidden now") ShowConsoleCursor(GetStdHandle(STD_OUTPUT_HANDLE),0) while get_key()=-1 do end while
Jacques
5. Re: Hide Cursor in Console Window
- Posted by euphoric (admin) Jul 09, 2009
- 1195 views
the following code works for me...
It works for me as well. However, removing the extraneous puts() and whiles and wait_keys() causes it not to work.
For instance, this works (code goes right after and replaces all subsequent code after the procedure definition in your code):
puts(1,"a") -- a write to the screen is apparently required in order to set the cursor mode ShowConsoleCursor(GetStdHandle(STD_OUTPUT_HANDLE),0) while get_key()=-1 do end while
But without the prior puts(), it does not work on subsequent writes to the screen. For example, this shows the cursor:
-- no write to the screen prior to the following call means ShowConsoleCursor(GetStdHandle(STD_OUTPUT_HANDLE),0) puts(1,"a") -- the cursor continues to flash hereafter while get_key()=-1 do end while
6. Re: Hide Cursor in Console Window
- Posted by mattlewis (admin) Jul 09, 2009
- 1182 views
the following code works for me...
It works for me as well. However, removing the extraneous puts() and whiles and wait_keys() causes it not to work.
Have you tried a black marker? Dry erase is probably superior to permanent.
Matt
7. Re: Hide Cursor in Console Window
- Posted by euphoric (admin) Jul 09, 2009
- 1140 views
Using
clear_screen() ShowConsoleCursor(GetStdHandle(STD_OUTPUT_HANDLE),0)
seems to make it work as well, so long as something is done to the screen prior to calling the cursor function.
8. Re: Hide Cursor in Console Window
- Posted by euphoric (admin) Jul 09, 2009
- 1148 views
the following code works for me...
It works for me as well. However, removing the extraneous puts() and whiles and wait_keys() causes it not to work.
Have you tried a black marker? Dry erase is probably superior to permanent.
Thanks Matt. I'll give that a try.
9. Re: Hide Cursor in Console Window
- Posted by euphoric (admin) Jul 09, 2009
- 1168 views
Oh yeah...
Thanks for the code, Jacques
10. Re: Hide Cursor in Console Window
- Posted by jacques_desch Jul 09, 2009
- 1161 views
Using
clear_screen() ShowConsoleCursor(GetStdHandle(STD_OUTPUT_HANDLE),0)
seems to make it work as well, so long as something is done to the screen prior to calling the cursor function.
It is because you are using euiw, which is for windows applications, no console is create until you write something to the console.
I'm using exwc which create a console at startup.
Jacques