Suggested change to MSGBOX.E
- Posted by Jonas Temple <jtemple at yhti.net> Apr 22, 2004
- 549 views
Could I humbly suggest an additional routine to add to msgbox.e: global function message_box_ex(atom handle, sequence text, sequence title, object style) integer or_style atom text_ptr, title_ptr, ret 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 ret = c_func(msgbox_id, {handle, text_ptr, title_ptr, or_style}) free(text_ptr) free(title_ptr) return ret end function The current message_box routine issues a call to GetActiveWindow to retrieve the window handle to pass to MessageBox. This works fine as long as the program calling messaeg_box is the current foreground window. If the program is not the current foreground window then a call to message_box creates a separate task on the task bar and the program that called message_box can receieve Windows events such as clicking buttons, etc. This is not good especially if you're expecting the user to respond to the message box before any other event can take place. You can try this by writing a Windows program that uses a timer and pops up a message box after a short delay. After starting the program, switch to another application. You'll see the message box as a seperate task. The above routine corrects this by allowing the program to supply the window handle to associate the message box with. I call this as: void = message_box_ex(getHandle(Main), "Connection to system " & conn_systems[i] & " was lost", "Connection Lost!", or_all({MB_SETFOREGROUND,MB_ICONEXCLAMATION,MB_OK})) In this example I want the user to know when a connection is lost. By using MB_SETFOREGROUND the program's button on the task bar flashes letting the user know a response is needed. Jonas