Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a message box for a specified time?

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) ?

like image 595
TLama Avatar asked Dec 28 '13 16:12

TLama


People also ask

How can you display the current date and time in message boxes?

Here is the code: DateTime current = DateTime. Now; MessageBox. Show(current.

How do you display a message in Visual Basic?

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.

Which function you can display some message in the form of message box?

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.


1 Answers

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.:

  • Maurizio Pisano: MessageBoxTimeout API (CodeProject)
  • Eddie Shipman: Undocumented MessageBoxTimeOut function (Embarcadero)
like image 191
TLama Avatar answered Nov 20 '22 01:11

TLama