MessageBox
MsgBox
MsgBox ist eine
SelfBrew-DialogBox und vereint ShowMessagePos mit MessageBox.
Dabei wird die Box immer in der Mitte der aktuellen Form
ausgegeben.
|
function MsgBox(const Msg,
Cap:
string; AType:
TMsgDlgType; AButtons:
– benötigt MMSystem in uses! (für Sound)
TMsgDlgButtons; HelpCtx: Longint): Word;
var
ActvForm: TForm;
begin
ShowApplication;
ActvForm := Screen.ActiveForm;
with
CreateMessageDialog(Msg, AType, AButtons)
do begin
Caption := Cap;
FormStyle := fsStayOnTop;
Left := round(ActvForm.Left +(ActvForm.Width
-Width)/2);
Top := round(ActvForm.Top +(ActvForm.Height
-Height)/2);
if AType = mtWarning
then SndPlaySound('SystemAsterisk',SND_ASYNC);
if AType = mtError
then SndPlaySound('AppGPFault',SND_ASYNC);
Result := ShowModal;
end;
end; |
Anwendung:
|
MsgBox('Das
ist die Message.', 'FensterText',mtINFORMATION,
[mbOk], 0);
// mit OK Button |
Mehrere
Buttons und deren Abfrage (
var
Antwort : Integer; ):
|
Antwort := MsgBox('Das
ist die Message.', 'FensterText',mtINFORMATION,
[mbYes, mbNo, mbCancel], 0);
if Antwort = mrYes
then ShowMessage('Ja
wurde gedrückt'); |
Icons
|
ohne |
|
|
|
|
MsgBox |
mtCustom |
mtWarning |
mtInformation |
mtConfirmation |
mtError |
MessageBox |
n/a |
MB_ICONEXCLAMATION |
MB_ICONINFORMATION |
MB_ICONQUESTION |
MB_ICONSTOP |
ShowMessage
Einzeilige Ausgabe
|
ShowMessage('das
ist ein Hinweis!'); |
Einzeilige Ausgabe mit Positionierung
|
ShowMessagePos('das
ist ein Hinweis!',
100, 100); |
Die Positionsangabe bezieht sich
auf die linke obere Ecke des Ausgabefensters. Damit die Ausgabe
nicht so lautlos daher kommt, kann
hier noch ein Tönchen
abgespielt werden...
MessageBox
Einzeilige Ausgabe mit Icon
|
Application.MessageBox ('Einzeiliger
Text','Hinweis!',MB_OK +MB_ICONINFORMATION); |
Mehrzellige Ausgabe mit Icon
(
var
MeinText:
String; )
|
MeinText :=
'erste Zeile' +
#10#13 +
'zweite Zeile' +
#10#13 +
'dritte Zeile' ;
Application.MessageBox (@MeinText[1],'Hinweis!',MB_OK+MB_ICONINFORMATION); |
Abfrage Ja/Nein
mit Icon (
var
Antwort : Integer; )
- MB_DefButton1 = Button1 ist vorselektiert
|
Antwort :=
Application.MessageBox ('Beenden?','Frage?',
MB_YesNo+MB_ICONQUESTION+MB_DefButton1);
if
Antwort = IDYes
then
// mach was |
Abfrage Ja/Nein/Abbruch
mit Icon (
var
Antwort : Integer; )
- MB_DefButton2 = Button2 ist vorselektiert
|
Antwort := Application.MessageBox ('Was?','Was!',MB_YesNoCancel+MB_ICONQUESTION+MB_DefButton2);
if
Antwort = IDYes then
// mach was |
Dialog mit Abfrage Ja/Nein und einer CheckBox |
|
|
|
|
var
AMsgDialog: TForm;
ACheckBox: TCheckBox; |
|
AMsgDialog :=
CreateMessageDialog('Hier steht die
Mitteilung...', mtWarning, [mbYes, mbNo]);
ACheckBox := TCheckBox.Create(AMsgDialog);
with
AMsgDialog
do
try
Caption :=
'Fenster-Text';
Height := 150;
// Fensterhöhe
with ACheckBox
do
begin
Parent
:= AMsgDialog;
Caption
:= 'CheckBox-Text...';
width
:= 155;
// CheckBox-Feldlänge
top :=
95;
// CheckBox-Feld Position vertikal
Left :=
8;
// CheckBox-Feld Position horizontal
end;
case ShowModal
of
ID_YES:
ShowMessage('Ja wurde gedrückt');
// oder mach was anderes
ID_NO:
ShowMessage('Nein wurde gedrückt');
// oder mach was anderes
end;
if ACheckBox.Checked
then
ShowMessage('Der Haken wurde gesetzt');
// oder mach was anderes
finally
ACheckBox.Free;
free;
end; |
Weitere Fenstertypen:
mtError, mtInformation, mtConfirmation, mtCustom
|