home *** CD-ROM | disk | FTP | other *** search
- unit Smiley;
-
- {$R Smiley.res}
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs,
- Messages, Classes, Graphics, Controls,
- Forms, StdCtrls, ExtCtrls;
-
- procedure Register;
-
- type
- tMood = (smHappy, smSad, smShades,
- smTongue, smIndifferent, smOoh);
-
- type
- TSmiley = class(TImage)
- private
- { Private declarations }
- Face : TBitmap;
- FMood : TMood;
- procedure SetBitmap;
- procedure SetMood(NewMood: TMood);
- function GetMood: TMood;
- public
- { Public declarations }
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure Toggle;
- {procedure WMSize(var Message: TMessage); message wm_size;
- procedure WMWindowPosChanging(var Message: TWMWindowPosMsg); message wm_WindowPosChanging; }
- published
- property Mood: TMood read GetMood write SetMood;
-
- end;
-
- implementation
-
- constructor TSmiley.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FMood := smHappy;
- Face := TBitmap.Create;
- Face.Handle := LoadBitmap(hInstance, 'Happy');
- Self.Height := 26;
- Self.Width := 26;
- SetBitmap;
- end;
-
- destructor TSmiley.Destroy;
- begin
- Face.Free;
- inherited Destroy;
- end;
-
- {procedure TSmiley.WMSize(var Message: TMessage);
- begin
- inherited;
- if (Width <> 26) or (Height <> 26) then SetBounds(Left, Top, 26, 26);
- end;
-
- procedure TSmiley.WMWindowPosChanging(var Message: TWMWindowPosMsg);
- begin
- Message.WindowPos^.cx := 26;
- Message.WindowPos^.cy := 26;
- end;}
-
- procedure TSmiley.Toggle;
- begin
- try
- Inc(FMood);
- except
- on ERangeError do fMood := smHappy;
- end;
- SetBitmap;
- end;
-
- procedure TSmiley.SetBitmap;
- begin
- Case FMood of
- smHappy : Face.Handle := LoadBitmap(hInstance, 'Happy');
- smSad : Face.Handle := LoadBitmap(hInstance, 'Sad');
- smShades : Face.Handle := LoadBitmap(hInstance, 'Shades');
- smOoh : Face.Handle := LoadBitmap(hInstance, 'Ooh');
- smIndifferent : Face.Handle := LoadBitmap(hInstance, 'Indifferent');
- smTongue : Face.Handle := LoadBitmap(hInstance, 'Tongue');
- end;
-
- Self.Picture.Graphic := Face as TGraphic;
- end;
-
- procedure TSmiley.SetMood(NewMood: TMood);
- begin
- FMood := NewMood;
- SetBitmap;
- end;
-
- function TSmiley.GetMood: TMood;
- begin
- Result := FMood;
- end;
-
- procedure Register;
- begin
- RegisterComponents('Custom', [TSmiley]);
- end;
-
- end.
-
-