From ac9c5de1ef2bb0f99eda900969bd9826beeb7a8d Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Mon, 9 Jun 2008 02:31:51 +0000 Subject: [PATCH] Fixes compilation of TTrayIcon example git-svn-id: trunk@15369 - --- examples/trayicon/frmtest.lfm | 8 +- examples/trayicon/frmtest.lrs | 74 +++---- examples/trayicon/frmtest.pas | 398 +++++++++++++++++----------------- examples/trayicon/wndtray.lpi | 133 ++++++------ 4 files changed, 296 insertions(+), 317 deletions(-) diff --git a/examples/trayicon/frmtest.lfm b/examples/trayicon/frmtest.lfm index b3a70ac266..44e926b3c5 100644 --- a/examples/trayicon/frmtest.lfm +++ b/examples/trayicon/frmtest.lfm @@ -1,7 +1,7 @@ object frmTrayTest: TfrmTrayTest - Left = 290 + Left = 183 Height = 249 - Top = 175 + Top = 176 Width = 393 HorzScrollBar.Page = 392 VertScrollBar.Page = 248 @@ -54,9 +54,9 @@ object frmTrayTest: TfrmTrayTest end object chkOnPaintDrawing: TCheckBox Left = 32 - Height = 18 + Height = 19 Top = 152 - Width = 335 + Width = 261 Caption = 'Test drawing the icon in the Form''s OnPaint event' OnChange = chkOnPaintDrawingChange TabOrder = 4 diff --git a/examples/trayicon/frmtest.lrs b/examples/trayicon/frmtest.lrs index e70db5cc57..253aec5521 100644 --- a/examples/trayicon/frmtest.lrs +++ b/examples/trayicon/frmtest.lrs @@ -1,49 +1,27 @@ { This is an automatically generated lazarus resource file } - -LazarusResources.Add('TfrmTrayTest','FORMDATA',[ - 'TPF0'#12'TfrmTrayTest'#11'frmTrayTest'#4'Left'#3'"'#1#6'Height'#3#249#0#3'To' - +'p'#3#175#0#5'Width'#3#137#1#18'HorzScrollBar.Page'#3#136#1#18'VertScrollBar' - +'.Page'#3#248#0#13'ActiveControl'#7#7'btnShow'#7'Caption'#6#26'TTrayIcon tes' - +'t application'#12'ClientHeight'#3#249#0#11'ClientWidth'#3#137#1#8'OnCreate' - +#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#7'OnPaint'#7#9'FormPaint'#10 - +'LCLVersion'#6#6'0.9.25'#0#7'TButton'#7'btnShow'#4'Left'#2' '#6'Height'#2'!' - +#3'Top'#2' '#5'Width'#3#136#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6 - +#4'Show'#7'OnClick'#7#12'btnShowClick'#8'TabOrder'#2#0#0#0#7'TButton'#7'btnH' - +'ide'#4'Left'#2' '#6'Height'#2'!'#3'Top'#2'X'#5'Width'#3#136#0#25'BorderSpac' - +'ing.InnerBorder'#2#4#7'Caption'#6#4'Hide'#7'OnClick'#7#12'btnHideClick'#8'T' - +'abOrder'#2#1#0#0#7'TButton'#12'btnPaintTest'#4'Left'#3#216#0#6'Height'#2'!' - +#3'Top'#2' '#5'Width'#3#136#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6 - +#14'Raw Paint Test'#7'OnClick'#7#17'btnPaintTestClick'#8'TabOrder'#2#2#0#0#7 - +'TButton'#17'btnDisplayMessage'#4'Left'#3#216#0#6'Height'#2'!'#3'Top'#2'X'#5 - +'Width'#3#136#0#7'Caption'#6#15'Display Message'#7'OnClick'#7#11'HandleClick' - +#8'TabOrder'#2#3#0#0#9'TCheckBox'#17'chkOnPaintDrawing'#4'Left'#2' '#6'Heigh' - +'t'#2#18#3'Top'#3#152#0#5'Width'#3'O'#1#7'Caption'#6'1Test drawing the icon ' - +'in the Form''s OnPaint event'#8'OnChange'#7#23'chkOnPaintDrawingChange'#8'T' - +'abOrder'#2#4#0#0#10'TPopupMenu'#9'PopupMenu'#4'left'#3#136#0#3'top'#3#184#0 - +#0#9'TMenuItem'#9'MenuItem1'#7'Caption'#6#9'New Item1'#0#0#9'TMenuItem'#9'Me' - +'nuItem3'#7'Caption'#6#9'New Item3'#0#0#9'TMenuItem'#9'MenuItem2'#7'Caption' - +#6#9'New Item2'#0#0#0#9'TTrayIcon'#11'SystrayIcon'#4'left'#3#181#0#3'top'#3 - +#184#0#0#0#0#12'TfrmTrayTest'#11'frmTrayTest'#4'Left'#3'"'#1#6'Height'#3#249 - +#0#3'Top'#3#175#0#5'Width'#3#137#1#18'HorzScrollBar.Page'#3#136#1#18'VertScr' - +'ollBar.Page'#3#248#0#13'ActiveControl'#7#7'btnShow'#7'Caption'#6#26'TTrayIc' - +'on test application'#12'ClientHeight'#3#249#0#11'ClientWidth'#3#137#1#8'OnC' - +'reate'#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#7'OnPaint'#7#9'FormP' - +'aint'#10'LCLVersion'#6#6'0.9.25'#0#7'TButton'#7'btnShow'#4'Left'#2' '#6'Hei' - +'ght'#2'!'#3'Top'#2' '#5'Width'#3#136#0#25'BorderSpacing.InnerBorder'#2#4#7 - +'Caption'#6#4'Show'#7'OnClick'#7#12'btnShowClick'#8'TabOrder'#2#0#0#0#7'TBut' - +'ton'#7'btnHide'#4'Left'#2' '#6'Height'#2'!'#3'Top'#2'X'#5'Width'#3#136#0#25 - +'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#4'Hide'#7'OnClick'#7#12'btnHide' - +'Click'#8'TabOrder'#2#1#0#0#7'TButton'#12'btnPaintTest'#4'Left'#3#216#0#6'He' - +'ight'#2'!'#3'Top'#2' '#5'Width'#3#136#0#25'BorderSpacing.InnerBorder'#2#4#7 - +'Caption'#6#14'Raw Paint Test'#7'OnClick'#7#17'btnPaintTestClick'#8'TabOrder' - +#2#2#0#0#7'TButton'#17'btnDisplayMessage'#4'Left'#3#216#0#6'Height'#2'!'#3'T' - +'op'#2'X'#5'Width'#3#136#0#7'Caption'#6#15'Display Message'#7'OnClick'#7#11 - +'HandleClick'#8'TabOrder'#2#3#0#0#9'TCheckBox'#17'chkOnPaintDrawing'#4'Left' - +#2' '#6'Height'#2#18#3'Top'#3#152#0#5'Width'#3'O'#1#7'Caption'#6'1Test drawi' - +'ng the icon in the Form''s OnPaint event'#8'OnChange'#7#23'chkOnPaintDrawin' - +'gChange'#8'TabOrder'#2#4#0#0#10'TPopupMenu'#9'PopupMenu'#4'left'#3#136#0#3 - +'top'#3#184#0#0#9'TMenuItem'#9'MenuItem1'#7'Caption'#6#9'New Item1'#0#0#9'TM' - +'enuItem'#9'MenuItem3'#7'Caption'#6#9'New Item3'#0#0#9'TMenuItem'#9'MenuItem' - +'2'#7'Caption'#6#9'New Item2'#0#0#0#9'TTrayIcon'#11'SystrayIcon'#4'left'#3 - +#181#0#3'top'#3#184#0#0#0#0 -]); + +LazarusResources.Add('TfrmTrayTest','FORMDATA',[ + 'TPF0'#12'TfrmTrayTest'#11'frmTrayTest'#4'Left'#3#183#0#6'Height'#3#249#0#3'T' + +'op'#3#176#0#5'Width'#3#137#1#18'HorzScrollBar.Page'#3#136#1#18'VertScrollBa' + +'r.Page'#3#248#0#13'ActiveControl'#7#7'btnShow'#7'Caption'#6#26'TTrayIcon te' + +'st application'#12'ClientHeight'#3#249#0#11'ClientWidth'#3#137#1#8'OnCreate' + +#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#7'OnPaint'#7#9'FormPaint'#10 + +'LCLVersion'#6#6'0.9.25'#0#7'TButton'#7'btnShow'#4'Left'#2' '#6'Height'#2'!' + +#3'Top'#2' '#5'Width'#3#136#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6 + +#4'Show'#7'OnClick'#7#12'btnShowClick'#8'TabOrder'#2#0#0#0#7'TButton'#7'btnH' + +'ide'#4'Left'#2' '#6'Height'#2'!'#3'Top'#2'X'#5'Width'#3#136#0#25'BorderSpac' + +'ing.InnerBorder'#2#4#7'Caption'#6#4'Hide'#7'OnClick'#7#12'btnHideClick'#8'T' + +'abOrder'#2#1#0#0#7'TButton'#12'btnPaintTest'#4'Left'#3#216#0#6'Height'#2'!' + +#3'Top'#2' '#5'Width'#3#136#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6 + +#14'Raw Paint Test'#7'OnClick'#7#17'btnPaintTestClick'#8'TabOrder'#2#2#0#0#7 + +'TButton'#17'btnDisplayMessage'#4'Left'#3#216#0#6'Height'#2'!'#3'Top'#2'X'#5 + +'Width'#3#136#0#7'Caption'#6#15'Display Message'#7'OnClick'#7#11'HandleClick' + +#8'TabOrder'#2#3#0#0#9'TCheckBox'#17'chkOnPaintDrawing'#4'Left'#2' '#6'Heigh' + +'t'#2#19#3'Top'#3#152#0#5'Width'#3#5#1#7'Caption'#6'1Test drawing the icon i' + +'n the Form''s OnPaint event'#8'OnChange'#7#23'chkOnPaintDrawingChange'#8'Ta' + +'bOrder'#2#4#0#0#10'TPopupMenu'#9'PopupMenu'#4'left'#3#136#0#3'top'#3#184#0#0 + +#9'TMenuItem'#9'MenuItem1'#7'Caption'#6#9'New Item1'#0#0#9'TMenuItem'#9'Menu' + +'Item3'#7'Caption'#6#9'New Item3'#0#0#9'TMenuItem'#9'MenuItem2'#7'Caption'#6 + +#9'New Item2'#0#0#0#9'TTrayIcon'#11'SystrayIcon'#4'left'#3#181#0#3'top'#3#184 + +#0#0#0#0 +]); diff --git a/examples/trayicon/frmtest.pas b/examples/trayicon/frmtest.pas index 3aa1b3d103..312050806a 100644 --- a/examples/trayicon/frmtest.pas +++ b/examples/trayicon/frmtest.pas @@ -1,199 +1,199 @@ -{ - frmtest.dpr - - ***************************************************************************** - * * - * This demonstration program is public domain, which means no copyright, * - * but also no warranty! * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * * - ***************************************************************************** - - Author: Felipe Monteiro de Carvalho -} -unit frmtest; - -{$ifdef fpc} - {$mode delphi}{$H+} -{$endif} - -interface - -uses - Classes, SysUtils, -{$ifdef fpc} - LResources, -{$endif} - Forms, Controls, Graphics, Dialogs, Buttons, StdCtrls, Menus, - ExtCtrls; - -type - - { TfrmTrayTest } - - TfrmTrayTest = class(TForm) - btnShow: TButton; - btnHide: TButton; - btnPaintTest: TButton; - btnDisplayMessage: TButton; - chkOnPaintDrawing: TCheckBox; - MenuItem1: TMenuItem; - MenuItem2: TMenuItem; - MenuItem3: TMenuItem; - PopupMenu: TPopupMenu; - SystrayIcon: TTrayIcon; - procedure btnShowClick(Sender: TObject); - procedure btnHideClick(Sender: TObject); - procedure btnPaintTestClick(Sender: TObject); - procedure chkOnPaintDrawingChange(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure FormDestroy(Sender: TObject); - procedure FormPaint(Sender: TObject); - procedure HandleClick(Sender: TObject); - private - { private declarations } - pathMedia: string; - MyImage: TIcon; - procedure DoPaint(Sender: TObject); - public - { public declarations } - end; - -var - frmTrayTest: TfrmTrayTest; - -{$ifndef fpc} - {$R frmtest.dfm} -{$endif} - -implementation - -{$ifdef Windows} -uses Windows; -{$endif} -{$IFDEF Darwin} -uses -{$ifdef ver2_2_0} - FPCMacOSAll; -{$else} - MacOSAll; -{$endif} -{$ENDIF} - -{ TfrmTrayTest } - -procedure TfrmTrayTest.btnShowClick(Sender: TObject); -begin - SystrayIcon.Visible := True; -end; - -procedure TfrmTrayTest.btnHideClick(Sender: TObject); -begin - SystrayIcon.Visible := False; -end; - -procedure TfrmTrayTest.btnPaintTestClick(Sender: TObject); -var - SecondImage: TIcon; -begin - SecondImage := TIcon.Create; - - try - SecondImage.Height := 22; - SecondImage.Width := 22; - {$IFDEF FPC} - SecondImage.Canvas.Draw(0, 0, MyImage); - {$ENDIF} - Canvas.Draw(0, 0, SecondImage); - finally - SecondImage.Free; - end; -end; - -procedure TfrmTrayTest.chkOnPaintDrawingChange(Sender: TObject); -begin - Invalidate; -end; - -procedure TfrmTrayTest.FormCreate(Sender: TObject); -const - IDI_ICON1 = 101; - IDI_ICON2 = 115; - BundleResourceFolder = '/Contents/Resources/'; -var -{$IFDEF Darwin} - pathRef: CFURLRef; - pathCFStr: CFStringRef; - pathStr: shortstring; -{$ENDIF} -begin - pathMedia := ''; - - // Under Mac OS X we need to get the location of the bundle -{$IFDEF Darwin} - pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle()); - pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle); - CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding()); - CFRelease(pathRef); - CFRelease(pathCFStr); - - pathMedia := pathStr + BundleResourceFolder; -{$ENDIF} - -{$ifdef Windows} - SystrayIcon.Icon.Handle := LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); - -// Loading from a file should also work -// SystrayIcon.Icon.LoadFromFile('icon.ico'); -{$else} - SystrayIcon.Icon.LoadFromFile(pathMedia + 'icon.ico'); -{$endif} - - SystrayIcon.Hint := 'my tool tip'; - - SystrayIcon.OnClick := HandleClick; - -// SystrayIcon.OnPaint := DoPaint; - - SystrayIcon.PopUpMenu := PopupMenu; - - // Loads the icon - - MyImage := TIcon.Create; - - MyImage.LoadFromFile(pathMedia + 'icon.ico'); -end; - -procedure TfrmTrayTest.FormDestroy(Sender: TObject); -begin - MyImage.Free; -end; - -procedure TfrmTrayTest.FormPaint(Sender: TObject); -begin - if chkOnPaintDrawing.Checked then btnPaintTestClick(Sender); -end; - -procedure TfrmTrayTest.HandleClick(Sender: TObject); -begin - Application.MessageBox('Text', 'Caption', 0); -end; - -procedure TfrmTrayTest.DoPaint(Sender: TObject); -begin - {$IFDEF FPC} - SystrayIcon.Canvas.Draw(0, 0, MyImage); - {$ENDIF} - WriteLn('Paint'); -end; - -initialization -{$ifdef fpc} - {$I frmtest.lrs} -{$endif} - -end. - +{ + frmtest.dpr + + ***************************************************************************** + * * + * This demonstration program is public domain, which means no copyright, * + * but also no warranty! * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * * + ***************************************************************************** + + Author: Felipe Monteiro de Carvalho +} +unit frmtest; + +{$ifdef fpc} + {$mode delphi}{$H+} +{$endif} + +interface + +uses + Classes, SysUtils, +{$ifdef fpc} + LResources, +{$endif} + Forms, Controls, Graphics, Dialogs, Buttons, StdCtrls, Menus, + ExtCtrls; + +type + + { TfrmTrayTest } + + TfrmTrayTest = class(TForm) + btnShow: TButton; + btnHide: TButton; + btnPaintTest: TButton; + btnDisplayMessage: TButton; + chkOnPaintDrawing: TCheckBox; + MenuItem1: TMenuItem; + MenuItem2: TMenuItem; + MenuItem3: TMenuItem; + PopupMenu: TPopupMenu; + SystrayIcon: TTrayIcon; + procedure btnShowClick(Sender: TObject); + procedure btnHideClick(Sender: TObject); + procedure btnPaintTestClick(Sender: TObject); + procedure chkOnPaintDrawingChange(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); + procedure FormPaint(Sender: TObject); + procedure HandleClick(Sender: TObject); + private + { private declarations } + pathMedia: string; + MyImage: TIcon; + procedure DoPaint(Sender: TObject); + public + { public declarations } + end; + +var + frmTrayTest: TfrmTrayTest; + +{$ifndef fpc} + {$R frmtest.dfm} +{$endif} + +implementation + +{$ifdef Windows} +uses Windows; +{$endif} +{$IFDEF Darwin} +uses +{$ifdef ver2_2_0} + FPCMacOSAll; +{$else} + MacOSAll; +{$endif} +{$ENDIF} + +{ TfrmTrayTest } + +procedure TfrmTrayTest.btnShowClick(Sender: TObject); +begin + SystrayIcon.Visible := True; +end; + +procedure TfrmTrayTest.btnHideClick(Sender: TObject); +begin + SystrayIcon.Visible := False; +end; + +procedure TfrmTrayTest.btnPaintTestClick(Sender: TObject); +var + SecondImage: TIcon; +begin + SecondImage := TIcon.Create; + + try + SecondImage.Height := 22; + SecondImage.Width := 22; + {$IFDEF FPC} + SecondImage.Canvas.Draw(0, 0, MyImage); + {$ENDIF} + Canvas.Draw(0, 0, SecondImage); + finally + SecondImage.Free; + end; +end; + +procedure TfrmTrayTest.chkOnPaintDrawingChange(Sender: TObject); +begin + Invalidate; +end; + +procedure TfrmTrayTest.FormCreate(Sender: TObject); +const + IDI_ICON1 = 101; + IDI_ICON2 = 115; + BundleResourceFolder = '/Contents/Resources/'; +{$IFDEF Darwin} +var + pathRef: CFURLRef; + pathCFStr: CFStringRef; + pathStr: shortstring; +{$ENDIF} +begin + pathMedia := ''; + + // Under Mac OS X we need to get the location of the bundle +{$IFDEF Darwin} + pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle()); + pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle); + CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding()); + CFRelease(pathRef); + CFRelease(pathCFStr); + + pathMedia := pathStr + BundleResourceFolder; +{$ENDIF} + +{$ifdef Windows} + SystrayIcon.Icon.Handle := LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); + +// Loading from a file should also work +// SystrayIcon.Icon.LoadFromFile('icon.ico'); +{$else} + SystrayIcon.Icon.LoadFromFile(pathMedia + 'icon.ico'); +{$endif} + + SystrayIcon.Hint := 'my tool tip'; + + SystrayIcon.OnClick := HandleClick; + +// SystrayIcon.OnPaint := DoPaint; + + SystrayIcon.PopUpMenu := PopupMenu; + + // Loads the icon + + MyImage := TIcon.Create; + + MyImage.LoadFromFile(pathMedia + 'icon.ico'); +end; + +procedure TfrmTrayTest.FormDestroy(Sender: TObject); +begin + MyImage.Free; +end; + +procedure TfrmTrayTest.FormPaint(Sender: TObject); +begin + if chkOnPaintDrawing.Checked then btnPaintTestClick(Sender); +end; + +procedure TfrmTrayTest.HandleClick(Sender: TObject); +begin + Application.MessageBox('Text', 'Caption', 0); +end; + +procedure TfrmTrayTest.DoPaint(Sender: TObject); +begin + {$IFDEF FPC} + SystrayIcon.Canvas.Draw(0, 0, MyImage); + {$ENDIF} + WriteLn('Paint'); +end; + +initialization +{$ifdef fpc} + {$I frmtest.lrs} +{$endif} + +end. + diff --git a/examples/trayicon/wndtray.lpi b/examples/trayicon/wndtray.lpi index ef610682ea..33e8fbd271 100644 --- a/examples/trayicon/wndtray.lpi +++ b/examples/trayicon/wndtray.lpi @@ -1,66 +1,67 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +