Entwickler-Ecke

Grafische Benutzeroberflächen (VCL & FireMonkey) - Frage zu Messageboxen


Delphinator - Do 08.08.02 21:45
Titel: Frage zu Messageboxen
Hallo,

da die FAQ's und die Delphi-Hilfe mir nicht weiterhelfen konnten, und ich noch kein Buch habe, poste ich meine Frage einfach mal hierher.
Ich habe einen Button, der eine Messagebox auf den Bildschirm bringt, sobald man draufdrückt. Soweit sogut. Hierzu habe ich folgenden Code:

Quelltext
1:
messagebox(form1.handle, PChar('Hallo Welt'), PChar('Information.'),0);                    


Ich habe mittlerweile rausgefunden, einfach durch probieren, wie man Icons in die Messagebox bekommt, auch wie man verschiedene Buttons in die Messagebox bekommt. Nur, wie kombiniere ich das? Also das ich verschiedene Buttons UND ein Icon in der Messagebox habe???

Danke für die Hilfe!

Greetz,
Delphinator


s4lzh3r1ng - Do 08.08.02 21:51

Ganz einfach:

Aufruf:

application.messagebox('Achtung','',[Bilder]+[Buttons])

Folgende Buttons können ausgewählt werden:
0 = Ok
1 = OK, Abbrechen
2 = Beenden,wiederholen,Ignorieren
3 = Ja, Nein, Abbrechen
4 = Ja,Nein
5 = Wiederholen,Abbrechen
6 = Hilfe
7= -Abbrechen, Hilfe
9 = -
10 = OK,Abbrechen,Hilfe

Folgende Bilder können ausgewählt werden: (mehr weiß ich auch nicht :wink: )
32 =?
48 = !


Delphinator - Do 08.08.02 21:59

Hi,
erst mal vielen Dank für die Antwort. Da ich jetzt weiß, wie die Teile kombiniert werden, kann ich mal noch was dazu sagen. Angaben über Icons und Buttons funzen wie mit dem BCB:


Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
MB_ICONINFORMATION // Info-Icon
MB_ICONERROR // Error-Icon
MB_ICONQUESTION // Frage-Icon
MB_OK // OK-Button
MB_OKCANCEL // OK und CANCEL - Button
MB_YESNO // Ja/Nein-Button
Edit------------------------------------------------------
MB_ABORTRETRYIGNORE // Abbrechen, Wiederholen und Ignorieren
MB_YESNOCANCEL // Ja, Nein, Abbrechen
MB_RETRYCANCEL // Wiederholen, Abbrechen
MB_ICONEXCLAMATION // Warnung-Icon
Edit Ende---------------------------------------------------


Greetz,
Delphinator


cbs - Do 08.08.02 22:09

jau, tippel doch einfachmal messagebox in den codeeditor und positioniere dann den cursor (einfügemarke oder das teil halt "|" ,was blingt, wo man was halt schreiben kann) drüber. dann drücke mal F1 delphi zeigt dir dann auch infos dazu an wenn das nich inner hilfe steht (oder in einer anderen hilfe steht)

probiers mal aus, das ergebniss was delphi dann ausspuckt müsste dann soaussehen:

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
The MessageBox function creates, displays, and operates a message box. The message box contains an application-defined message and title, plus any combination of predefined icons and push buttons. 

int MessageBox(

    HWND hWnd,  // handle of owner window
    LPCTSTR lpText,  // address of text in message box
    LPCTSTR lpCaption,  // address of title of message box  
    UINT uType   // style of message box
   );  
 

Parameters

hWnd

Identifies the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window. 

lpText

Points to a null-terminated string containing the message to be displayed. 

lpCaption

Points to a null-terminated string used for the dialog box title. If this parameter is NULL, the default title Error is used. 

uType

Specifies a set of bit flags that determine the contents and behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags. 
Specify one of the following flags to indicate the buttons contained in the message box:

Flag  Meaning
MB_ABORTRETRYIGNORE  The message box contains three push buttons: Abort, Retry, and Ignore.
MB_OK  The message box contains one push button: OK. This is the default.
MB_OKCANCEL  The message box contains two push buttons: OK and Cancel.
MB_RETRYCANCEL  The message box contains two push buttons: Retry and Cancel.
MB_YESNO  The message box contains two push buttons: Yes and No.
MB_YESNOCANCEL  The message box contains three push buttons: Yes, No, and Cancel.
 

Specify one of the following flags to display an icon in the message box:

Flag  Meaning
MB_ICONEXCLAMATION, 
MB_ICONWARNING
  An exclamation-point icon appears in the message box.
MB_ICONINFORMATION, MB_ICONASTERISK
  An icon consisting of a lowercase letter i in a circle appears in the message box.
MB_ICONQUESTION  A question-mark icon appears in the message box.
MB_ICONSTOP, 
MB_ICONERROR, 
MB_ICONHAND
  A stop-sign icon appears in the message box.
 

Specify one of the following flags to indicate the default button:

Flag  Meaning
MB_DEFBUTTON1  The first button is the default button. MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified.
MB_DEFBUTTON2  The second button is the default button.
MB_DEFBUTTON3  The third button is the default button.
MB_DEFBUTTON4  The fourth button is the default button.
 

Specify one of the following flags to indicate the modality of the dialog box:

...
...
Return Values

The return value is zero if there is not enough memory to create the message box.
If the function succeeds, the return value is one of the following menu-item values returned by the dialog box: 

Value  Meaning
IDABORT  Abort button was selected.
IDCANCEL  Cancel button was selected.
IDIGNORE  Ignore button was selected.
IDNO  No button was selected.
IDOK  OK button was selected.
IDRETRY  Retry button was selected.
IDYES  Yes button was selected.
 
...
...
See Also

FlashWindow, MessageBeep, MessageBoxEx, MessageBoxIndirect, SetForegroundWindow

gekürtzte ausgabe


cb_katze - Fr 09.08.02 08:44

Hi ...

versuch es doch auch mal mit MESSAGEDLG() - da kannst Du auch gleich noch auswerten, welche der dargestellten Tasten in der MessageBox gedrückt wurde:

Bspl.:

Quelltext
1:
2:
3:
4:
5:
6:
7:
  if MessageDlg('Willkommen in meiner Object PascalAnwendung. Jetzt beenden?',
    mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  begin
    MessageDlg('Programm wird beendet.', mtInformation,
      [mbOk], 0);
    Close;
  end;
Quelle: Delphi-Hilfe

Aufbau:
1. Parameter = Ausgabetext;
2. Parameter = Bild (mtWarning - Ein Meldungsfenster mit einem gelben Ausrufezeichen; mtError -Ein Meldungsfenster mit einem roten Stoppschild; mtInformation - Ein Meldungsfenster mit einem blauen "i"; mtConfirmation - Ein Meldungsfenster mit einem grünen Fragezeichen; mtCustom - Ein Meldungsfenster ohne Bitmap. Als Fenstertitel wird der Name der Anwendung angezeigt)
3. Parameter = Schalter (mbYes - Eine Schaltfläche mit dem Text 'Ja'; mbNo - Eine Schaltfläche mit dem Text 'Nein'; mbOK - Eine Schaltfläche mit dem Text 'OK'; mbCancel - Eine Schaltfläche mit dem Text 'Abbrechen'; mbAbort - Eine Schaltfläche mit dem Text 'Abbruch'; mbRetry - Eine Schaltfläche mit dem Text 'Wiederholen'; mbIgnore - Eine Schaltfläche mit dem Text 'Ignorieren'; mbAll - Eine Schaltfläche mit dem Text 'Alle'; mbNoToAll - Eine Schaltfläche mit dem Text 'Nein für alle'; mbYesToAll - Eine Schaltfläche mit dem Text 'Ja für alle'; mbHelp - Eine Schaltfläche mit dem Text 'Hilfe')
4. Parameter = 0 (i.d.R.)

... naja den Rest (Auswertung und so findest Du auch noch in der Delphi-Hilfe => einfach F1 auf das Wort MessageDlg !


cbs - Fr 09.08.02 09:18

@cb_katze: ???? mit messagebox kann ich das doch auch auswerten!!!


Quelltext
1:
2:
3:
4:
5:
6:
7:
  if Application.MessageBox(PChar('Klicken Sie auf Ja oder Nein'),
    PChar('TestBox'), MB_YESNO + MB_ICONQUESTION) = IDYES then
    begin
      Showmessage('auf Ja geklickt');
    end else begin
      Showmessage('auf Nein geklickt');
    end;

in dem fall kann man die umwandlung in PChar sogar weglassen


cb_katze - Fr 09.08.02 09:27

... ja schon :oops: - aber ich dachte, du wolltest eher wissen, welche icons + schalter du wie kombinieren kannst !


cbs - Fr 09.08.02 09:53

ich sowie so nicht, wenn dann Delphinator, er hat das posting eröffnet

ich hab bloss auf seine frage geantwortet


Delphinator - Fr 09.08.02 15:47

Hallo Allerseits!

Danke für die vielen umfangreichen Antworten. Man beachte bitte meine Erweiterung in meinem Posting weiter oben :roll: Dort hab ich noch ein paar Möglichkeiten hingeschrieben.


Greetz,
Delphinator