Is there a way to show a message box for a specified time (that means, the message box will close itself when the specified time elapses) ?
Here is the code: DateTime current = DateTime. Now; MessageBox. Show(current.
The MsgBox function displays a message box and waits for the user to click a button and then an action is performed based on the button clicked by the user.
In an Access desktop database, the MsgBox Function displays a message in a dialog box, waits for the user to click a button, and returns an Integer indicating which button the user clicked. Required. String expression displayed as the message in the dialog box.
Windows API has a function for showing a message box for a specified time, but for some reason is that function undocumented, which means it is not officially supported and may well be subject to change.
That function is called MessageBoxTimeout
, and it has even export in the user32.dll
library, what makes me feel that the only thing this function lacks is the official documentation. But who knows...
The following script shows how to display a message box for 5 seconds before the wizard form is shown. If the user doesn't click the OK button, nor manually close the window, the message box is automatically closed when that 5 seconds period elapses:
[Code]
#ifdef UNICODE
#define AW "W"
#else
#define AW "A"
#endif
const
MB_TIMEDOUT = 32000;
MB_ICONERROR = $10;
MB_ICONQUESTION = $20;
MB_ICONWARNING = $30;
MB_ICONINFORMATION = $40;
function MessageBoxTimeout(hWnd: HWND; lpText: string; lpCaption: string;
uType: UINT; wLanguageId: Word; dwMilliseconds: DWORD): Integer;
external 'MessageBoxTimeout{#AW}@user32.dll stdcall';
procedure InitializeWizard;
begin
MessageBoxTimeout(WizardForm.Handle, 'This message will be automatically ' +
'closed in 5 seconds!', 'Caption...', MB_OK or MB_ICONINFORMATION, 0, 5000);
end;
For more information about parameters and result values refer to the MessageBox
function help site and some of the unofficial articles describing the MessageBoxTimeout
function itself, like e.g.:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With