source: tags/1.3.5/Messg.pas

Last change on this file was 558, checked in by chronos, 7 months ago
  • Modified: Code cleanup.
File size: 2.7 KB
Line 
1{$INCLUDE Switches.inc}
2unit Messg;
3
4interface
5
6uses
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
12const
13 WM_PLAYSOUND = WM_USER;
14
15type
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
35var
36 MessgDlg: TMessgDlg;
37
38procedure SimpleMessage(SimpleText: string);
39procedure SoundMessage(SimpleText, SoundItem: string);
40
41
42implementation
43
44uses
45 Sound;
46
47{$R *.lfm}
48
49procedure TMessgDlg.FormCreate(Sender: TObject);
50begin
51 inherited;
52 OpenSound := '';
53end;
54
55procedure TMessgDlg.FormShow(Sender: TObject);
56begin
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;
76end;
77
78procedure TMessgDlg.FormPaint(Sender: TObject);
79begin
80 inherited;
81 if OpenSound <> '' then
82 PostMessage(Handle, WM_PLAYSOUND, 0, 0);
83end;
84
85procedure TMessgDlg.Button1Click(Sender: TObject);
86begin
87 ModalResult := mrOK;
88end;
89
90procedure TMessgDlg.Button2Click(Sender: TObject);
91begin
92 ModalResult := mrIgnore;
93end;
94
95procedure TMessgDlg.FormKeyPress(Sender: TObject; var Key: Char);
96begin
97 if Key = #13 then
98 ModalResult := mrOK;
99 // else if (Key=#27) and (Button2.Visible) then ModalResult:=mrCancel
100end;
101
102procedure SimpleMessage(SimpleText: string);
103begin
104 with MessgDlg do
105 begin
106 MessgText := SimpleText;
107 Kind := mkOK;
108 ShowModal;
109 end;
110end;
111
112procedure SoundMessage(SimpleText, SoundItem: string);
113begin
114 with MessgDlg do
115 begin
116 MessgText := SimpleText;
117 OpenSound := SoundItem;
118 Kind := mkOK;
119 ShowModal;
120 end;
121end;
122
123procedure TMessgDlg.OnPlaySound(var Msg: TMessage);
124begin
125 Play(OpenSound);
126 OpenSound := '';
127end;
128
129end.
Note: See TracBrowser for help on using the repository browser.