Re: dos window

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

Use GetConsoleWindow to get the current console window for your application. However, according to this StackOverflow thread, you cannot SetFocus to other top-level windows (frankly, it's rude). Indeed I tried but it did not work. But you can use FlashWindow to draw focus from the user without forcing your hand. This example will flash the current console window. It also shows how to detect if you currently have a window, which could be helpful before calling free_console().

http://stackoverflow.com/questions/3223688/set-focus-on-console-in-windows

include std/dll.e 
include std/machine.e 
include std/os.e 
include std/types.e 
 
constant 
    kernel32    = open_dll( "kernel32.dll" ), 
    user32      = open_dll( "user32.dll" ), 
$ 
 
constant 
    xGetConsoleWindow   = define_c_func( kernel32, "GetConsoleWindow", {}, C_HWND ), 
    xFlashWindow        = define_c_func( user32, "FlashWindow", {C_HWND,C_BOOL}, C_HWND ), 
$ 
 
public function GetConsoleWindow() 
    return c_func( xGetConsoleWindow, {} ) 
end function 
 
public function FlashWindow( atom hwnd, boolean invert = TRUE ) 
    return c_func( xFlashWindow, {hwnd,invert} ) 
end function 
 
-- get the console window 
atom hwnd = GetConsoleWindow() 
 
if hwnd = NULL then 
    -- no window exists 
     
    -- force a console window 
    puts( 1, "\n" ) 
     
    -- get the handle again 
    hwnd = GetConsoleWindow() 
     
end if 
 
for i = 1 to 4 do 
     
    -- flash the window 
    FlashWindow( hwnd ) 
     
    -- sleep briefly before flashing again 
    sleep( 0.5 ) 
     
end for 

-Greg

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

Search



Quick Links

User menu

Not signed in.

Misc Menu