Non-blocking message_box

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

Here is a simple way to get a non-blocking message_box using Daniel Kluss' TDLL.

-- (c) Copyright 2007 Rapid Deployment Software - See License.txt 
-- 
-- Euphoria 3.1 
-- Windows message_box() function 
 
include tdll.e 
include msgbox.e  -- only to retrieve constants 
include machine.e 
include misc.e 
 
without warning 
 
atom lib 
integer msgbox_id, get_active_id 
 
if platform() = WIN32 then 
  lib = open_tdll("user32.dll") 
  msgbox_id = define_t_func(lib, "MessageBoxA", {C_POINTER, C_POINTER, 
                           C_POINTER, C_INT}, C_INT) 
  if msgbox_id = -1 then 
    puts(2, "couldn't find MessageBoxA\n") 
    abort(1) 
  end if 
 
  get_active_id = define_t_func(lib, "GetActiveWindow", {}, C_LONG) 
  if get_active_id = -1 then 
    puts(2, "couldn't find GetActiveWindow\n") 
    abort(1) 
  end if 
end if 
 
global function messageBox(sequence text, sequence title, object style) 
  integer or_style 
  atom text_ptr, title_ptr, ret, active 
     
  text_ptr = allocate_string(text) 
  if not text_ptr then 
    return 0 
  end if 
  title_ptr = allocate_string(title) 
  if not title_ptr then 
    free(text_ptr) 
    return 0 
  end if 
  if atom(style) then 
    or_style = style 
  else 
    or_style = 0 
    for i = 1 to length(style) do 
      or_style = or_bits(or_style, style[i]) 
    end for 
  end if 
  active = t_func(get_active_id, {}) 
  ret = t_func(msgbox_id, {active, text_ptr, title_ptr, or_style}) 
  free(text_ptr) 
  free(title_ptr) 
  return ret 
end function 
 

Just include this library instead of msgbox.e and replace message_box by messageBox in your code.

Jean-Marc

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

Search



Quick Links

User menu

Not signed in.

Misc Menu