The MessageBox function calls an undocumented API named MessageBoxTimeout. This function takes a parameter setting the timeout value in miliseconds.
Here is the information I found :
Declare Function MessageBoxTimeout Lib "user32.dll" Alias
"MessageBoxTimeoutA" (_
Byval hwnd As Long, _
Byval lpText As String, _
Byval lpCaption As String, _
Byval uType As Long, _
Byval wLanguageID As Long, _
Byval lngMilliseconds As Long) As Long
A timeout value of -1 means probably that the message box is displayed forever. MessageBox passes -1 to the MessageBoxTimeout function as timeout value.
Here are some interesting links :
http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-vb/30806/Messagebox-with-timeout
http://www.codeproject.com/KB/cpp/MessageBoxTimeout.aspx
A quick demo ( tested on Windows XP Pro SP3 ) :
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
TIMEOUT equ 5000 ; A timeout value of -1 indicates an undefined period of time
.data
text db 'This message box will destroy itself after 5000 miliseconds',0
caption db 'Self-destroying message box',0
.code
start:
invoke MessageBoxTimeout,0,ADDR text,ADDR caption,MB_ICONWARNING,LANG_NEUTRAL,TIMEOUT
invoke ExitProcess,0
END start
[attachment deleted by admin]
Lolz, interesting ...
Undocumented APIs rock ! :8)
Hi Vortex:
Undocumented also means big M will drop it
in the next service pack.
Not that I find they documentation any good.
No documentation sometimes is easy to read.
Regards herge
MessageBoxTimeout.exe doesn't function correctly on Windows 98 SE
The MESSAGEBOXTIMEOUT.EXE file is
linked to missing export USER32.DLL MessageBoxTimeoutA
It works OK on Windows XP Pro SP2
Dear Vortex,
MessageBoxTimeout is well-known undocumented API :)
But do you know about following: leastwise on XP-pro-sp2 (I didn't test other OS for the time being) - WM_TIMER closes any Message Box.
What do you think about correlation between this fact and MessageBoxTimeout-mechanism ? Forasmuch MessageBoxTimeout uses exactly WM_TIMER for exit...
Quote from: kero on September 13, 2008, 06:46:24 AM
Dear Vortex,
MessageBoxTimeout is well-known undocumented API :)
But do you know about following: leastwise on XP-pro-sp2 (I didn't test other OS for the time being) - WM_TIMER closes any Message Box.
What do you think about correlation between this fact and MessageBoxTimeout-mechanism ? Forasmuch MessageBoxTimeout uses exactly WM_TIMER for exit...
Hi Kero,
To implement that method, you probably need to create a computer-based training (CBT) application using a WH_CBT style hook + subclassing.
Here is a customized message box based on this article (http://www.catch22.net/tuts/msgbox.asp)
[attachment deleted by admin]
Really interesting article, never thought of that !
I don't have time right now to mess with it, but I will keep it in mind. One question for you Vortex : Can this be used to disable or change the default messagebox sound ?
I guess that would not be an easy task. Probably, it's easier to create a dialog box based custom message box.
Hi, Vortex
I'm afraid you don't understand me...
I know how build timed Message Box with help of WH_CBT or with help of 2-nd thread :)
For example I used it in my ExtraSpy (button "MsgBox), attachment. (BTW, this sparring dialog is supplement to my (friendly!) critique on "Win32 API Tutorial - Dialog Box" by Iczelion: http://www.wasm.ru//forum/viewtopic.php?id=27477 , in Russian).
That is I talk about:
run ANY Message Box, run ExtraSpy, place cursor over Message Box, press CTRL-key + roll mouse wheel => PostMessage(hWndMesBox,WM_TIMER,0,0). This operation will CLOSE Message Box (leastwise on XP-pro-sp2).
[attachment deleted by admin]
http://www.geocities.com/xmemor/2lz/tinyasm.html
Wow, kero, you're really into window handling, aren't you ? :green2 :green2
Hi kero,
You can setup a timer to destroy the messsage box after an elapsed time :
TimerProc PROC hWnd:DWORD,uMsg:DWORD,idEvent:DWORD,dwTime:DWORD
invoke DestroyWindow,hWnd
ret
TimerProc ENDP
[attachment deleted by admin]
Dear Vortex, are you joking ?!
I didn't ask you to help me with timed message box!
On the contrary, I said: "MessageBoxTimeout is well-known undocumented API", and I said also that I know ways via hook and via 2-nd thread, so "timed message box" wasn't my question!
1-st part of my question was: did you detect that WM_TIMER ("leastwise on XP-pro-sp2") CLOSES ANY Message Box? Please read my messages here again :)
Kero,
Calm a little. Why are you insisting on your arguments? I understand very well all what you said. I tried to show here some modest examples and that's all. Your PostMessage method works too. No need to argue on this message box topic...
Vortex,
don't sulk, don't insult me, I don't want to injure you, but no, you didn't understand me (maybe my English too bad, it isn't my natal language).
Let I'll try to explain target of my message bis, last.
1) PostMessage(WM_TIMER) to message box - isn't "my method", that I "suggest".
This was my finding, very surprising for me, when I worked on ExtraSpy (this sparring tool contains the part - CBT-hooked message box, transformed to "main window").
2) Hitherto I knew nothing about this feature of usual message box. So I hope - if it is well-know fact - for adequate link.
3) Since now I have only XP-pro-sp2 - of course I'm interesting what about WM_TIMER+MsgBox on other Win OS (98, 2k, Vista).
4) Since I know that MessageBoxTimeout uses exactly WM_TIMER to close itself - I can also surmise that maybe my finding exists only on XP, as "echo" of MessageBoxTimeout-mechanism (if I'm right, MessageBoxTimeout came to user32.dll only on XP)...
Ergo you see: I didn't want to SUGGEST, - I wanted to KNOW (about WM_TIMER+MsgBox, not other).
For the time being - without success :(
Kero,
Seriously, asking from you to calm down doesn not mean that I am insulting you. I have no intention to harm you in anyway, take it easy and please be patient. I understand that you have a good knowledge on this topic but let me and others to think about the subject. Testing the procedure on other windows installations is a good idea. I guess you can try a virtualization software to test WM_TIMER+MsgBox on other operating systems.
Having the list of APIs exported by Win98 user32.dll ,I can tell you that this OS does not provide MessageBoxTimeout. As you said, there is high chance that only Windows XP and the succeeding operating systems are designed to use this undocumented MessageBoxTimeou function. Next week, I will test WM_TIMER+MsgBox on a Windows Server 2003 system.
Another TimerProc :
TimerProc PROC hWnd:DWORD,uMsg:DWORD,idEvent:DWORD,dwTime:DWORD
invoke KillTimer,hWnd,ID_TIMER
invoke SendMessage,hWnd,WM_CLOSE,0,0
ret
TimerProc ENDP