1 | {$INCLUDE Switches.inc}
|
---|
2 | unit Messg;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | uses
|
---|
7 | ScreenTools, LCLIntf, LCLType, LMessages, Messages, SysUtils, Classes,
|
---|
8 | Graphics, Controls, Forms, ButtonA, DrawDlg;
|
---|
9 |
|
---|
10 | const
|
---|
11 | WM_PLAYSOUND = WM_USER;
|
---|
12 |
|
---|
13 | type
|
---|
14 | TMessageKind = (mkOK, mkOKCancel, mkYesNo, mkYesNoCancel, mkOkCancelRemove,
|
---|
15 | mkOkHelp, mkModel);
|
---|
16 |
|
---|
17 | TMessgDlg = class(TBaseMessgDlg)
|
---|
18 | Button1: TButtonA;
|
---|
19 | Button2: TButtonA;
|
---|
20 | procedure FormCreate(Sender: TObject);
|
---|
21 | procedure FormPaint(Sender: TObject);
|
---|
22 | procedure FormShow(Sender: TObject);
|
---|
23 | procedure Button1Click(Sender: TObject);
|
---|
24 | procedure Button2Click(Sender: TObject);
|
---|
25 | procedure FormKeyPress(Sender: TObject; var Key: char);
|
---|
26 | public
|
---|
27 | Kind: TMessageKind;
|
---|
28 | OpenSound: string;
|
---|
29 | private
|
---|
30 | procedure OnPlaySound(var Msg: TMessage); message WM_PLAYSOUND;
|
---|
31 | end;
|
---|
32 |
|
---|
33 | var
|
---|
34 | MessgDlg: TMessgDlg;
|
---|
35 |
|
---|
36 | procedure SimpleMessage(SimpleText: string);
|
---|
37 | procedure SoundMessage(SimpleText, SoundItem: string);
|
---|
38 |
|
---|
39 |
|
---|
40 | implementation
|
---|
41 |
|
---|
42 | uses
|
---|
43 | Sound;
|
---|
44 |
|
---|
45 | {$R *.lfm}
|
---|
46 |
|
---|
47 | procedure TMessgDlg.FormCreate(Sender: TObject);
|
---|
48 | begin
|
---|
49 | inherited;
|
---|
50 | OpenSound := '';
|
---|
51 | end;
|
---|
52 |
|
---|
53 | procedure TMessgDlg.FormShow(Sender: TObject);
|
---|
54 | begin
|
---|
55 | Button1.Visible := true;
|
---|
56 | Button2.Visible := not(Kind in [mkOK]);
|
---|
57 | if Button2.Visible then
|
---|
58 | Button1.Left := 101
|
---|
59 | else
|
---|
60 | Button1.Left := 159;
|
---|
61 | if Kind = mkYesNo then
|
---|
62 | begin
|
---|
63 | Button1.Caption := Phrases.Lookup('BTN_YES');
|
---|
64 | Button2.Caption := Phrases.Lookup('BTN_NO')
|
---|
65 | end
|
---|
66 | else
|
---|
67 | begin
|
---|
68 | Button1.Caption := Phrases.Lookup('BTN_OK');
|
---|
69 | Button2.Caption := Phrases.Lookup('BTN_CANCEL');
|
---|
70 | end;
|
---|
71 |
|
---|
72 | SplitText(true);
|
---|
73 | CorrectHeight;
|
---|
74 | end;
|
---|
75 |
|
---|
76 | procedure TMessgDlg.FormPaint(Sender: TObject);
|
---|
77 | begin
|
---|
78 | inherited;
|
---|
79 | if OpenSound <> '' then
|
---|
80 | PostMessage(Handle, WM_PLAYSOUND, 0, 0);
|
---|
81 | end;
|
---|
82 |
|
---|
83 | procedure TMessgDlg.Button1Click(Sender: TObject);
|
---|
84 | begin
|
---|
85 | ModalResult := mrOK;
|
---|
86 | end;
|
---|
87 |
|
---|
88 | procedure TMessgDlg.Button2Click(Sender: TObject);
|
---|
89 | begin
|
---|
90 | ModalResult := mrIgnore;
|
---|
91 | end;
|
---|
92 |
|
---|
93 | procedure TMessgDlg.FormKeyPress(Sender: TObject; var Key: char);
|
---|
94 | begin
|
---|
95 | if Key = #13 then
|
---|
96 | ModalResult := mrOK;
|
---|
97 | // else if (Key=#27) and (Button2.Visible) then ModalResult:=mrCancel
|
---|
98 | end;
|
---|
99 |
|
---|
100 | procedure SimpleMessage(SimpleText: string);
|
---|
101 | begin
|
---|
102 | with MessgDlg do
|
---|
103 | begin
|
---|
104 | MessgText := SimpleText;
|
---|
105 | Kind := mkOK;
|
---|
106 | ShowModal;
|
---|
107 | end;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | procedure SoundMessage(SimpleText, SoundItem: string);
|
---|
111 | begin
|
---|
112 | with MessgDlg do
|
---|
113 | begin
|
---|
114 | MessgText := SimpleText;
|
---|
115 | OpenSound := SoundItem;
|
---|
116 | Kind := mkOK;
|
---|
117 | ShowModal;
|
---|
118 | end;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TMessgDlg.OnPlaySound(var Msg: TMessage);
|
---|
122 | begin
|
---|
123 | Play(OpenSound);
|
---|
124 | OpenSound := '';
|
---|
125 | end;
|
---|
126 |
|
---|
127 | end.
|
---|