1. Hide Cursor in Console Window

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.

new topic     » topic index » view message » categorize

2. Re: Hide Cursor in Console Window

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

euphoric said...

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.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Hide Cursor in Console Window

This doesn't work for me:

ShowConsoleCursor( GetStdHandle( STD_OUTPUT_HANDLE ), 0 ) 

Is that the right thing to do? smile

new topic     » goto parent     » topic index » view message » categorize

4. Re: Hide Cursor in Console Window

euphoric said...

This doesn't work for me:

ShowConsoleCursor( GetStdHandle( STD_OUTPUT_HANDLE ), 0 ) 

Is that the right thing to do? smile

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

new topic     » goto parent     » topic index » view message » categorize

5. Re: Hide Cursor in Console Window

jacques_desch said...

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 
new topic     » goto parent     » topic index » view message » categorize

6. Re: Hide Cursor in Console Window

euphoric said...
jacques_desch said...

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

new topic     » goto parent     » topic index » view message » categorize

7. Re: Hide Cursor in Console Window

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.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Hide Cursor in Console Window

mattlewis said...
euphoric said...
jacques_desch said...

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.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Hide Cursor in Console Window

Oh yeah...

Thanks for the code, Jacques

new topic     » goto parent     » topic index » view message » categorize

10. Re: Hide Cursor in Console Window

euphoric said...

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu