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