Page 1 of 1

Non-blocking MessageRequester ?

Posted: Fri Jul 31, 2009 4:17 pm
by delta69
Hello,

I have a MessageRequester in a loop, and I'd like to display a warning message in the requester that don't stop the loop when waiting for user validation.

Is there a way to proceed without using a separate thread for the MessageRequester ?

Thanks for your help !

Regards.

Posted: Fri Jul 31, 2009 4:37 pm
by Matt
This works nicely, but does use threads....

Code: Select all

Structure msgstruc
  title$
  message$
EndStructure

Procedure MessageBoxT(*para.msgstruc)
  MessageRequester(*para\title$, *para\message$)
  FreeMemory(*para)
EndProcedure
Procedure MessageBox(title$, message$)
  *tempstruc.msgstruc = AllocateMemory(SizeOf(msgstruc))
  *tempstruc\title$ = title$
  *tempstruc\message$ = message$
  CreateThread(@MessageBoxT(),*tempstruc)
EndProcedure

For a=1 To 3
  MessageBox("test","message!")
Next a

Delay(5000)
And then this works in Windows to allow access to the main window, rather than wait for all the message boxes to be closed:

Code: Select all

Structure msgstruc
  title$
  message$
EndStructure

Procedure MessageBoxT(*para.msgstruc)
  ;MessageRequester(*para\title$, *para\message$)
  MessageBox_(0, *para\title$, *para\message$, 0)
  FreeMemory(*para)
EndProcedure
Procedure MessageBox(title$, message$)
  *tempstruc.msgstruc = AllocateMemory(SizeOf(msgstruc))
  *tempstruc\title$ = title$
  *tempstruc\message$ = message$
  CreateThread(@MessageBoxT(),*tempstruc)
EndProcedure

For a=1 To 3
  MessageBox("test","message!")
Next a

OpenWindow(0, 0, 0, 100,100,"msgbox test")

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

End
Why no threads?

Posted: Fri Jul 31, 2009 4:49 pm
by Kaeru Gaman
MsgBox is definitely designed to block the calling thread,
because you should be able to change something before the processing continues.

dropping messages while processing normally is put into some listing gadget,
like the compiler messages downleft in the IDE.

sure it's more work, but you should program something own that is obviously different from a messagerequester...
else your customers may ask "wutufu? why does the bloody prog not stop while requester?"

Posted: Fri Jul 31, 2009 4:52 pm
by Matt
Yeah, it would be really simple to make a function that creates a window that looks like a message box, customized for your application, to get the job done just as Kaeru Gaman said...

Re: Non-blocking MessageRequester ?

Posted: Fri Jul 31, 2009 10:40 pm
by PB
There's a post here (do a search) for a timed messagebox that times out
after X seconds... maybe that's what you want?

Posted: Sat Aug 01, 2009 7:44 pm
by delta69
First of all, I'd like to thank eveybody for your help...

I was wondering if there was a "hidden" parameter for the MessageRequester allowing to do what I need. I'm #1 at reinventing the wheel coding 100's of buggy lines whereas the needed function already exists !

I had a look at MSDN's website before botehring you, but I didn't found what I was looking for. You're definitely right : This function just works as it should !

Thanks again for your help, I really appreciate. I will use Matt's code to implement my requester !

Regards.

Posted: Sat Aug 01, 2009 8:29 pm
by Matt
First of all, I'd like to thank eveybody for your help...

I was wondering if there was a "hidden" parameter for the MessageRequester allowing to do what I need. I'm #1 at reinventing the wheel coding 100's of buggy lines whereas the needed function already exists !

I had a look at MSDN's website before botehring you, but I didn't found what I was looking for. You're definitely right : This function just works as it should !
Yep, I looked through the documentation as well before writing that code... as I was not able to find anything either :(
delta69 wrote: Thanks again for your help, I really appreciate. I will use Matt's code to implement my requester !
8)