[PB4] Timed MessageRequester

Share your advanced PureBasic knowledge/code with the community.
User avatar
kenmo
Addict
Addict
Posts: 2047
Joined: Tue Dec 23, 2003 3:54 am

Re: [PB4] Timed MessageRequester

Post by kenmo »

skywalk wrote:Thanks kenmo.
kenmo wrote:There are a handful of similar solutions here:

http://www.purebasic.fr/english/viewtop ... erequester
BTW, your "safe" method doesn't work. :?
The single procedure with the label is OK, except for a warning:

[12:12:57] Waiting for executable to start...
[12:12:57] Executable type: Windows - x86 (32bit)
[12:12:57] Executable started.
[12:12:57] [WARNING] Line: 11
[12:12:57] [WARNING] The specified '@ProcedureName()' is not a Procedure pointer.
[12:13:02] The Program execution has finished.
Hmmmm...... to be fair, I posted this 4 years ago and I linked you to it without testing!

If you want to be totally safe (as in, no memory leaks by killed threads, etc.) and you want customizable (timeout, delay before clicking, custom text), it is really worth the small bit of extra time to write your own custom messagebox system. It doesn't take much effort to make it seamlessly work with most programs. You can even set the messagebox to be Always-on-top, and disable any main windows you want.

The ONLY drawback I can think of right now is that MessageRequester makes icon use simple... of course that's only true in Windows (correct me if I'm wrong).
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: [PB4] Timed MessageRequester

Post by yrreti »

I've been using the one netmaestro coded
http://www.purebasic.fr/english/viewtop ... MessageBox
since he posted it, and it has been very useful. - especially where I may need to change the timed
message on different parts of the code. Try it, you'll really like it too, as it's very useful.

If you just want a messagebox simular to the standard one, but with a time out that you can set for each one.
I always use this code.-again from netmaestro.

Code: Select all

; $C0  ;this gives you the silent ok box when using MessageRequester
#MessageBox_Timeout = -1
Global g_hwndTimedOwner
Global g_bTimedout

Procedure MessageBoxTimer(hwnd, uiMsg, idEvent, dwTime)
  g_bTimedout = #True
  If g_hwndTimedOwner
    EnableWindow_(g_hwndTimedOwner, #True)
  EndIf
  PostQuitMessage_(0)
EndProcedure

Procedure TimedMessageBox(hwndOwner, pszMessage.s, pszTitle.s, flags, dwTimeout)
  Protected idTimer.l, iResult.l
  g_hwndTimedOwner = #Null
  g_bTimedout = #False
  If hwndOwner And IsWindowEnabled_(hwndOwner)
    g_hwndTimedOwner = hwndOwner
  EndIf
  idTimer.l = SetTimer_(#Null, 0, dwTimeout, @MessageBoxTimer())
  iResult.l = MessageBox_(hwndOwner, pszMessage, pszTitle, flags)
  KillTimer_(#Null, idTimer)
  If g_bTimedout
    PeekMessage_(@msg.MSG, #Null, #WM_QUIT, #WM_QUIT, #PM_REMOVE)
    iResult = #MessageBox_Timeout
  EndIf
  ProcedureReturn iResult
EndProcedure

;two examples of use
OpenWindow(0, 100, 100, 200, 200, "Test Program", #PB_Window_SystemMenu)
TimedMessageBox(#Null, "Check Task Bar.  Program is already running.", "PTM",$C0, 1500);1.5 seconds
TimedMessageBox(#Null, "Bad Date entered.  Please use MMDDYY format.", "Map Date",$C0, 2500) ;5 seconds
Post Reply