Entwickler-Ecke

Windows API - ...sich seine eigene MessageDialogBox bastel?


Popov - Di 03.02.04 23:03
Titel: ...sich seine eigene MessageDialogBox bastel?
Hier einige sehr interresante MessageBoxen, die man sich nach seinen eigenen Bedürfnissen anpassen kann. So ist z.B. die normale Box eben normal, d.h. grau ober blau wie die eingestellte Systemfarbe. Hat man bei den Formularen noch sein Canvas, was möglich macht, daß man die Farbe beeinflußt oder vielleicht noch ein schönen Skinn macht, so bleiben die Farben der Messagebox'en eben... naja, eben normal.

Dabei gibt es Funktion CreateMessageDialog und mit der kann man sich seine eigene MessageBox basteln. Hier einige Beispiele:


MessageBox, mit einem eigenem Titel:


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function MessageDlgT(const Msg, Cap: string; AType: TMsgDlgType; AButtons:
  TMsgDlgButtons; HelpCtx: Longint): Word;
begin
  with CreateMessageDialog(Msg, AType, AButtons) do begin
    Caption := Cap;
    Result := ShowModal;
  end;
end;



Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.Button2Click(Sender: TObject);
begin
  MessageDlgT('Das ist die Message.''Ike bin ne Berliner MessageBox',
    mtInformation, [mbOk], 0);
end;



MessageBox, die, abhängig von MessageTyp, unterschiedliche Fenster-Farben hat:

Nebenbei hat sie noch eine Positionsangebe, mit der es möglich ist die Meldung da zu plazieren wo man es will.


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
//Bunte MessageBox mit einem "Hallo :)" als Fenstertitel
function MessageDlgPosC(const Msg: string; AType: TMsgDlgType; AButtons:
  TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer): Word;
begin
  with CreateMessageDialog(Msg, AType, AButtons) do begin
    case AType of
     mtWarning: Color := $0080FFFF;
     mtError: Color := $007171FF;
     mtInformation: Color := $00CAFFCA;
     mtConfirmation: Color := $00FFB9B9;
     mtCustom: Color := clBtnFace;
     else Color := clBtnFace;
    end;

    Caption := 'Hallo :)';

    Left := X;
    Top := Y;
    Result := ShowModal;
  end;
end;


Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Click(Sender: TObject);
begin
  MessageDlgPosC('Das ist die Message.', mtConfirmation, [mbOk], 050200);
end;



MessageBox, mit der eigenen Schriftart:

Hier mit Curier New.


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function MessageDlgPosB(const Msg: string; AType: TMsgDlgType; AButtons:
  TMsgDlgButtons; HelpCtx: Longint): Word;
begin
  with CreateMessageDialog(Msg, AType, AButtons) do begin
    Font.Name := 'Curier New';

    Result := ShowModal;
  end;
end;



MessageBox, die man als Fenster maximieren kann:

Und schon sieht man, daß eine MessageBox auch nur ein normales Fenster ist.


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function MessageDlgPosB(const Msg: string; AType: TMsgDlgType; AButtons:
  TMsgDlgButtons; HelpCtx: Longint; Bmp: TBitmap): Word;
var
  x, y: Integer;
begin
  with CreateMessageDialog(Msg, AType, AButtons) do begin
    BorderStyle := bsSingle;

    Result := ShowModal;
  end;
end;


So, diese Beispiel haben gezeigt, daß man sich seine eigene MessageBox basteln kann. Was man macht, bleibt jedem selbst überlassen, aber man kann das Fenster zumindest beeinflussen.