Re: Potential issue with message_box() function

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

Hallo

petelomax said...

Hmm. Quite amazing something that old, that simple, and that heavily used could be hiding that for quite so long..

I'am really sure nobody ever used this include for a real program...

petelomax said...

First off, clearly it is a serious omission that you cannot supply a better hwnd to message_box() if you know one. I was thinking of a 4th defaulted parameter, and a new set_mb_hwnd() routine to allow an app to make the top-level window (or whatever) the default in all future message_box() calls.

A include in win32 that only exports MessageBox() is completly useless (from my point of view) and needs to be moved to demo or something like this.

petelomax said...

Secondly, I'm a bit shocked and dismayed that Raymond Chen - the Raymond Chen, mind you, (bit of a big-time fan of his) did not mention MB_TASKMODAL, as that seems to be the thing you need when hwnd is NULL, assuming you want it to be modal. According to the docs, it suspends all top-level windows associated with the current thread. I've even gone so far as to (add said 4th param, rip out GetActiveWindow,) and add

if hWnd=NULL then style = or_bits(style,MB_TASKMODAL) end if </eucode> to my copy of msgbox.e - and I guess I'll find out in the next few days if there's anything amiss with that.

Pete

The problem with msgbox.e is:\

ret = c_func(msgbox_id, {c_func(get_active_id, {}),text_ptr, title_ptr, or_style}) 
-- get_active_id() should be NULL or a valid hwnd 
-- grabbing the foregrund window is just bad style 

In a single threaded App there is not much difference if you use MB_TASKMODAL or MB_APPSMODAL (default).
The call to Messagebox() will block your program (no matter if you pass MB_APPSMODAL or MB_TASKMODAL) , even Mr. Petzold used it this way (with NULL as hwnd and MB_APPSMODAL).

You may play with this code. tinEWG passes WinHwnd to MessageBox() as default, so setting it to zero gives you a test situation.

include gui/tin/tinewg.exw 
 
atom handle=Window()  -- Window() returns the handle that is stored in WinHwnd 
atom b1=Control(Button,"Button",0,0,80,20) 
 
WinHwnd=0   -- InfoMsg() uses WinHwnd for the MessageBox handle 
 
InfoMsg("MyText","MyTitle") 
 
WinHwnd=handle  -- restore the handle for WinHwnd 
 
WinMain() 
 

Andreas

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

Search



Quick Links

User menu

Not signed in.

Misc Menu