Re: moving console window

new topic     » goto parent     » topic index » view thread      » older message » newer message

You can move it manually. I've had a lot of fun manipulating the console from Euphoria without using Win32Lib, etc. Here's some sample code...

 
include dll.e 
include get.e 
include machine.e 
 
-- shared libraries 
constant kernel32       = open_dll( "kernel32.dll" ) 
constant user32         = open_dll( "user32.dll" ) 
 
-- console routines 
constant xGetConsoleWindow      = define_c_func( kernel32, "GetConsoleWindow", {}, C_LONG ) 
constant xGetWindowRect         = define_c_func( user32, "GetWindowRect", {C_LONG,C_POINTER}, C_ULONG ) 
constant xMoveWindow            = define_c_func( user32, "MoveWindow", {C_LONG,C_INT,C_INT,C_INT,C_INT,C_ULONG}, C_ULONG ) 
 
-- structures 
constant RECT_left    =  0 
constant RECT_top     =  4 
constant RECT_right   =  8 
constant RECT_bottom  = 12 
constant SIZEOF_RECT  = 16 
 
procedure MoveConsole( integer x, integer y, integer refresh ) 
 
    atom hWnd, pRect 
    integer cx, cy, junk 
     
    -- get the console handle 
    hWnd = c_func( xGetConsoleWindow, {} ) 
     
    -- allocate the structure 
    pRect = allocate( SIZEOF_RECT ) 
     
    -- get the window rect 
    if c_func( xGetWindowRect, {hWnd, pRect} ) = 0 then 
        free( pRect ) 
        return 
    end if 
     
    -- calculate the window size 
    cx = peek4s( pRect + RECT_right ) - peek4s( pRect + RECT_left )  
    cy = peek4s( pRect + RECT_bottom ) - peek4s( pRect + RECT_top ) 
     
    -- free the structure 
    free( SIZEOF_RECT ) 
     
    -- move the window 
    junk = c_func( xMoveWindow, {hWnd, x, y, cx, cy, refresh} ) 
     
end procedure 
 
object junk 
 
puts( 1, "Press any key to move the Window...\n" ) 
junk = wait_key() 
 
-- move to top-left corner 
MoveConsole( 0, 0, 1 ) 
 
puts( 1, "The console was moved!" ) 
junk = wait_key() 

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu