source: tags/1.3.1/Messg.pas

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