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