home *** CD-ROM | disk | FTP | other *** search
- ////////////////////////////////////////////////////////////////////////////////
- // Jazarsoft FormEx //
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // VERSION : 2.1 //
- // AUTHOR : James Azarja //
- // CREATED : 30 July 2000 //
- // MODIFIED : 16 March 2001 //
- // WEBSITE : http://www.jazarsoft.com //
- // SUPPORT : support@jazarsoft.com //
- // BUG-REPORT : bugreport@jazarsoft.com //
- // COMMENT : comment@jazarsoft.com //
- // LEGAL : Copyright (C) 2000-2001 Jazarsoft. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // This code may be used and modified by anyone so long as this header and //
- // copyright information remains intact. //
- // //
- // The code is provided "as-is" and without warranty of any kind, //
- // expressed, implied or otherwise, including and without limitation, any //
- // warranty of merchantability or fitness for a particular purpose.á //
- // //
- // In no event shall the author be liable for any special, incidental, //
- // indirect or consequential damages whatsoever (including, without //
- // limitation, damages for loss of profits, business interruption, loss //
- // of information, or any other loss), whether or not advised of the //
- // possibility of damage, and on any theory of liability, arising out of //
- // or in connection with the use or inability to use this software.áá //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // HISTORY //
- // //
- // 1.0 - Initial Public Release //
- // 1.1 - Fixed "Minimize" bug. //
- // Fixed "Scrolling Caption" bug. //
- // Added SendKeys Feature //
- // 2.0 - Major code reconstruction //
- // - Unnecessary code //
- // - Transparent Form //
- // + Gradient Background //
- // + FormShaper Feature //
- // + Animated Cursor Feature //
- // + Animated Icon Feature //
- // + Capture Window Feature //
- // 2.1 - + Added BeginSizeMove and EndSizeMove Event //
- // Thanks to Morris Howorth (morris.howorth@zen.co.uk) //
- // Fixed "null icons bugs" for the animated icon //
- // //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // NOTE //
- // //
- // FormEx 2.0 Completely NOT COMPATIBLE WITH earlier version //
- // //
- ////////////////////////////////////////////////////////////////////////////////
-
- unit FormEx;
-
- {$HINTS OFF}
- {$WARNINGS OFF}
- {$IFDEF VER130}
- {$DEFINE D4PLUS}
- {$ENDIF}
- {$IFDEF VER120}
- {$DEFINE D4PLUS}
- {$ENDIF}
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ShellApi, Registry, ExtCtrls, ImgList, Menus, DsgnIntf;
-
- Const
- { FormEx Cursor Handle }
- crFormExCursor = 999;
- SysMenuExID = $FFF;
-
- {$IFNDEF D4PLUS}
- SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
- SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
- {$ENDIF}
-
- WM_ICONTRAYNOTIFY = WM_USER + 1234;
- IconID = 12345;
-
-
- type
- { Events }
- TOnNonClientClick = procedure (Sender: TObject;Var Position : TPoint) of object;
- TOnDropFiles = Procedure (Sender: TObject;Var Files: TStrings;Var Position : TPoint) of object;
- TOnIconCycle = procedure(Sender: TObject; Current: Integer) of object;
-
- TScrollDirection = (dLeft,
- dRight);
-
- TDrawMethod = (dmNormal,
- dmCenter,
- dmTile,
- dmStretch);
-
- TFormMoveableStyle = (fmsDefault,
- fmsNever,
- fmsAlways);
-
- TFormTopMostStyle = (ftmsDefault,
- ftmsWhenAcceptFiles,
- ftmsAlways);
-
- TFormTaskStyle = (ftsDefault,
- ftsWhenVisible,
- ftsAlways);
-
- TFormCoverStyle = (fcsNone,
- fcsImage,
- fcsGradient);
-
-
- TFormExThread = class(TThread)
- private
- protected
- procedure Execute; override;
- public
- constructor Create;
- destructor Destroy; override;
- procedure Release;
- end;
-
- TTrayIcon = class(TPersistent)
- private
- ParentForm : tForm;
- ParentFormEx : TComponent;
- Timer : TTimer;
-
- FEnabled : Boolean;
- FIcon : TIcon;
- FIconVisible : Boolean;
- FHint : String;
- FShowHint : Boolean;
- FLeftPopupMenu : TPopupMenu;
- FRightPopupMenu: TPopupMenu;
-
- FIconList : TImageList;
- FCycleIcons : Boolean;
- FCycleInterval : Cardinal;
- IconIndex : Integer;
- procedure SetCycleIcons(Value: Boolean);
- procedure SetCycleInterval(Value: Cardinal);
- procedure HandleIconMessage(var Msg: TMessage);
- function InitIcon: Boolean;
- procedure SetIcon(Value: TIcon);
- procedure SetIconVisible(Value: Boolean);
- procedure SetHint(Value: String);
- procedure SetShowHint(Value: Boolean);
- procedure PopupAtCursor(Index:Integer);
- protected
- IconData : TNotifyIconData;
- procedure Click; dynamic;
- procedure DblClick; dynamic;
- procedure CycleIcon; dynamic;
- procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer); dynamic;
- procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer); dynamic;
- procedure MouseMove(Shift: TShiftState; X, Y: Integer); dynamic;
-
- function ShowIcon: Boolean; virtual;
- function HideIcon: Boolean; virtual;
- function ModifyIcon: Boolean; virtual;
-
- Procedure OnTimer(Sender:TObject);
- public
- constructor Create(Parent:tForm;ParentClass:tComponent);
- destructor Destroy; override;
- Procedure NextIconCycle;
- published
- property IconList : TImageList read FIconList write FIconList;
- property CycleIcons : Boolean read FCycleIcons write SetCycleIcons;
- property CycleInterval : Cardinal read FCycleInterval write SetCycleInterval;
- property Enabled : Boolean read FEnabled write FEnabled;
- property Hint : String read FHint write SetHint;
- property ShowHint : Boolean read FShowHint write SetShowHint;
- property Icon : TIcon read FIcon write SetIcon stored True;
- property IconVisible : Boolean read FIconVisible write SetIconVisible;
- property LeftPopupMenu : TPopupMenu read FLeftPopupMenu write FLeftPopupMenu;
- property RightPopUpMenu : tPopUpMenu read FRightPopUpMenu write FRightPopUpMenu;
- end;
-
- TRatio = class (TPersistent)
- private
- FEnabled : Boolean;
- FWidth : Integer;
- FHeight : Integer;
- FAspectRatio : Single;
- protected
- procedure SetWidth(value:integer);
- procedure SetHeight(value:integer);
- procedure SetAspectRatio(value:single);
- public
- published
- property Enabled : Boolean Read FEnabled Write FEnabled;
- property Width : Integer Read FWidth Write SetWidth;
- property Height : Integer Read FHeight Write SetHeight;
- property AspectRatio : Single Read FAspectRatio Write SetAspectRatio;
- end;
-
- TResize = class (TPersistent)
- private
- FEnabled : Boolean;
- FRatio : TRatio;
- FBorderWidth : Integer;
- FMaxWidth : Integer;
- FMinWidth : Integer;
- FMaxHeight : Integer;
- FMinHeight : Integer;
- procedure SetRatio(Value:TRatio);
- public
- constructor Create;
- destructor Destroy;override;
- published
- property Enabled : Boolean Read FEnabled Write FEnabled;
- property Ratio : TRatio Read FRatio Write SetRatio;
- property BorderWidth : Integer Read FBorderWidth Write FBorderWidth;
- property MaxWidth : Integer Read FMaxWidth Write FMaxWidth;
- property MaxHeight : Integer Read FmaxHeight Write FMaxHeight;
- property MinWidth : Integer Read FMinWidth Write FMinWidth;
- property MinHeight : Integer Read FMinHeight Write FMinHeight;
- end;
-
- TMargin = class (TPersistent)
- private
- FLeftMin : Integer;
- FLeftMax : Integer;
- FTopMin : Integer;
- FTopMax : Integer;
- FRightMin : Integer;
- FRightMax : Integer;
- FBottomMin : Integer;
- FBottomMax : Integer;
- FEnabled : Boolean;
- public
- constructor Create;
- published
- property Enabled : Boolean Read FEnabled Write FEnabled;
- property LeftMin : Integer Read FLeftMin Write FLeftMin;
- property LeftMax : Integer Read FLeftMax Write FLeftMax;
- property RightMin : Integer Read FRightMin Write FRightMin;
- property RightMax : Integer Read FRightMax Write FRightMax;
- property TopMin : Integer Read FTopMin Write FTopMin;
- property TopMax : Integer Read FTopMax Write FTopMax;
- property BottomMin : Integer Read FBottomMin Write FBottomMin;
- property BottomMax : Integer Read FBottomMax Write FBottomMax;
- end;
-
- TPlacement = class (TPersistent)
- private
- ParentForm : tForm;
- FMargin : TMargin;
- FAlwaysOnScreen : Boolean;
- FTopMost : tFormTopMostStyle;
-
- FMoveable : tFormMoveableStyle;
- Procedure SetTopMost(Value:tFormTopMostStyle);
- protected
- procedure TopMostAction;
- public
- constructor Create(Parent:TForm);
- destructor Destroy;override;
- published
- property Margin : TMargin Read FMargin Write FMargin;
- property TopMost : tFormTopMostStyle Read FTopMost Write SetTopMost;
- property AlwaysOnScreen : Boolean Read FAlwaysOnScreen Write FAlwaysOnScreen;
- property Moveable : tFormMoveableStyle Read FMoveable Write FMoveable;
- end;
-
- TFormSaver = Class(TPersistent)
- private
- FGlobal : Boolean;
- FKeyName : String;
- FEnabled : Boolean;
-
- FPosition : Boolean;
- FSize : Boolean;
- protected
- public
- published
- property Global : Boolean Read FGlobal Write FGlobal;
- property KeyName : String Read FKeyname Write FKeyName;
- property Enabled : Boolean Read FEnabled Write FEnabled;
-
- property Position : Boolean Read FPosition Write FPosition;
- property Size : Boolean Read FSize Write FSize;
- end;
-
- TCoverGradient = Class(TPersistent)
- private
- FSource ,
- FDestination : tColor;
- protected
- public
- constructor Create;
- destructor Destroy;override;
- published
- property Source : tColor Read FSource Write FSource;
- property Destination : tColor Read FDestination Write FDestination;
- end;
-
- TCoverImage = Class(TPersistent)
- private
- FDrawMethod : tDrawMethod;
- FClient : tBitmap;
- procedure SetClient(Value:tBitmap);
- Procedure SetDrawMethod(Value:tDrawMethod);
- protected
- public
- constructor Create;
- destructor Destroy;override;
- published
- property Image : tBitmap Read FClient Write SetClient;
- property DrawMethod : tDrawMethod Read FDrawMethod Write SetDrawMethod;
- end;
-
- TCover = Class(TPersistent)
- private
- FStyle : tFormCoverStyle;
- FCoverImage : tCoverImage;
- FCoverGradient : tCoverGradient;
- protected
- public
- constructor Create;
- destructor Destroy;override;
- published
- property Style : tFormCoverStyle Read FStyle Write FStyle;
- property Image : tCoverImage Read FCoverImage Write FCoverImage;
- property Gradient : tCoverGradient Read FCoverGradient Write FCoverGradient;
- end;
-
- TCaptionScroll = class(TPersistent)
- private
- ParentForm : TForm;
- ParentHwnd : Hwnd;
-
- OldAppCaption ,
- OldFormCaption ,
- FCaption ,
- FSpace : String;
- TmpCount : Integer;
- FIsMainWindow : Boolean;
- FDirection : TScrollDirection;
- FEnabled : Boolean;
- FInterval : Word;
- FWindowHandle : Hwnd;
- Timer : TTimer;
- procedure SetCaption(Value: String);
- procedure SetEnabled(Value: Boolean);
- procedure SetInterval(Value: Word);
- protected
- procedure ProcessCaption; dynamic;
- Procedure OnTimer(Sender: TObject);
- public
- constructor Create(Parent:TForm);
- destructor Destroy; override;
- published
- property Caption : String read FCaption write SetCaption;
- property Direction : TScrollDirection read FDirection write FDirection;
- property IsMainWindow : Boolean read FIsMainWindow write FIsMainWindow;
- property Space : String read FSpace write FSpace;
- property Enabled : Boolean read FEnabled write SetEnabled;
- property Interval : Word read FInterval write SetInterval;
- end;
-
- TAnimatedIcon = class (TPersistent)
- private
- FEnabled : Boolean;
- FIcons : TImageList;
- FDelay : Integer;
-
- Timer : TTimer;
- FIndex : Integer;
- Ic : TIcon;
- ParentForm : tForm;
- Procedure SetEnabled(Value:Boolean);
- protected
- Procedure OnTimer(Sender: TObject);
- public
- Constructor Create(Parent:tForm);
- destructor Destroy;override;
- property Index : Integer Read FIndex;
- published
- property Enabled : Boolean Read FEnabled Write SetEnabled;
- property Icons : TImageList Read FIcons Write FIcons;
- property Delay : Integer Read FDelay Write FDelay;
- end;
-
- TAppearance = Class(TPersistent)
- private
- ParentForm : tForm;
- ParentHwnd : Hwnd;
-
- Old ,
- Oldh ,
- Oldw ,
- Oldx ,
- Oldy : Integer;
- Olds : TWindowState;
- OldStyleEx : Integer;
-
- FCover : TCover;
- FShowTitleBar : Boolean;
- FShowOnTaskBar : tFormTaskStyle;
- FAcceptFiles : Boolean;
- FShapePoints : tStrings;
- FCursor : tFilename;
- FFullScreen : Boolean;
- FCaptionScroll : tCaptionScroll;
- FAlwaysMinimize : Boolean;
- FAnimatedIcon : tAnimatedIcon;
-
- Procedure SetAlwaysMinimize(Value:Boolean);
- Procedure SetFullScreen(Value:Boolean);
- Procedure SetShowTitleBar(Value:Boolean);
- Procedure SetCover(Value:tCover);
- Procedure SetShowOnTaskbar(Value:tFormTaskStyle);
- procedure SetAcceptFiles(Value: Boolean);
- Procedure SetShapePoints(Value : tStrings);
- Procedure SetCursor(Value : tFilename);
- protected
- Procedure TitleBarAction;
- procedure TaskAction;
- Procedure ApplyShape;
- Procedure RemoveShape;
- public
- constructor Create(Parent:TForm);
- destructor Destroy;override;
- published
- property AnimatedIcon : tAnimatedIcon Read FAnimatedIcon Write FAnimatedIcon;
- property Cover : TCover Read FCover Write SetCover;
- property ShowTitleBar : Boolean Read FShowTitleBar Write SetShowTitleBar;
- property ShowOnTaskBar : tFormTaskStyle Read FShowOnTaskBar Write SetShowOnTaskBar;
- property AcceptFiles : Boolean Read FAcceptFiles Write SetAcceptFiles;
- property Shape : tStrings Read FShapePoints Write SetShapePoints;
- property Cursor : TFilename Read FCursor Write SetCursor;
- property FullScreen : Boolean Read FFullScreen Write SetFullScreen;
- property CaptionScroll : tCaptionScroll Read FCaptionScroll Write FCaptionScroll;
- property AlwaysMinimize : Boolean Read FAlwaysMinimize Write SetAlwaysMinimize;
- end;
-
- TFormEx = class(TComponent)
- private
- PrevParentWndProc : Pointer;
- SeekAndDestroy : Boolean;
- ParentHwnd : HWND;
- ParentForm : tForm;
- FormExThread : tFormExThread;
-
- BGBuffer : tBitmap;
-
- { Sub Properties }
- FPlacement : TPlacement;
- FResize : TResize;
- FFormSaver : TFormSaver;
- FAppearance : TAppearance;
- FTrayIcon : tTrayIcon;
-
- { Events }
- FOnNonClientClick : tOnNonClientClick;
- FOnDropFiles : tOnDropFiles;
- FOnMinimize : tNotifyEvent;
- FOnMaximize : tNotifyEvent;
- FOnRestore : tNotifyEvent;
- FOnEndSizeMove : tNotifyEvent;
- FOnBeginSizeMove : tNotifyEvent;
- FOnFontChange : tNotifyEvent;
-
- FOnTrayIconClick ,
- FOnTrayIconDblClick : TNotifyEvent;
- FOnTrayIconCycle : TOnIconCycle;
- FOnTrayIconMouseDown ,
- FOnTrayIconMouseUp : TMouseEvent;
- FOnTrayIconMouseMove : TMouseMoveEvent;
-
- { Variable }
- FSysMenuEx : tPopUpMenu;
-
- IgnoreNextMessage : Boolean;
-
- Procedure SetSysMenuEx(Value:tPopupMenu);
- protected
- procedure NewParentWndProc(var Message:Tmessage);
-
- procedure RebuildBG;
- procedure BuildBGImage;
- procedure BuildBGGradient;
-
- procedure DrawBG;
-
- procedure SaveSettings;
- procedure LoadSettings;
- public
- constructor create(AOwner:TComponent);override;
- destructor destroy;override;
- procedure Loaded;override;
-
- Procedure SendKeys(WinHandle:Hwnd;Buffer:String);
- Procedure CaptureWindow(WinHandle:Hwnd;Filename:String);
- Procedure Flash(Number,Delay:Integer);
- Procedure CenterOnForm(Form:tForm);
- Procedure HorizontalCenter(Form:tForm);
- Procedure VerticalCenter(Form:tForm);
- procedure SizeForWindowsDesktop; { Outside taskbar area }
- published
- property Appearance : TAppearance Read FAppearance Write FAppearance;
- property Placement : TPlacement Read FPlacement Write FPlacement;
- property Resize : TResize Read FResize Write FResize;
- property FormSaver : TFormSaver Read FFormSaver Write FFormSaver;
- property TrayIcon : tTrayIcon Read FTrayIcon Write FTrayIcon;
-
- property SysMenuEx : tPopUpMenu Read FSysMenuEx Write SetSysMenuEx;
-
- property OnNonClientClick : tOnNonClientClick Read FOnNonClientClick Write FOnNonClientClick;
- property OnDropFiles : tOnDropFiles Read FOnDropFiles Write FOnDropFiles;
- property OnMinimize : tNotifyEvent Read FOnMinimize Write FOnMinimize;
- property OnMaximize : tNotifyEvent Read FOnMaximize Write FOnMaximize;
- property OnRestore : tNotifyEvent Read FOnRestore Write FOnRestore;
- property OnBeginSizeMove : tNotifyEvent Read FOnBeginSizeMove Write FOnBeginSizeMove;
- property OnEndSizeMove : tNotifyEvent Read FOnEndSizeMove Write FOnEndSizeMove;
- property OnFontChange : tNotifyEvent Read FOnFontChange Write FOnFontChange;
-
- property OnTrayIconClick : TNotifyEvent read FOnTrayIconClick write FOnTrayIconClick;
- property OnTrayIconDblClick : TNotifyEvent read FOnTrayIconDblClick write FOnTrayIconDblClick;
- property OnTrayIconMouseDown : TMouseEvent read FOnTrayIconMouseDown write FOnTrayIconMouseDown;
- property OnTrayIconMouseUp : TMouseEvent read FOnTrayIconMouseUp write FOnTrayIconMouseUp;
- property OnTrayIconMouseMove : TMouseMoveEvent read FOnTrayIconMouseMove write FOnTrayIconMouseMove;
- property OnTrayIconCycle : TOnIconCycle read FOnTrayIconCycle write FOnTrayIconCycle;
- end;
-
- procedure Register;
-
- implementation
- Var
- Designing : Boolean;
-
- constructor TFormExThread.Create;
- begin
- FreeOnTerminate := TRUE;
- inherited Create(TRUE);
- end;
-
- destructor TFormExThread.Destroy;
- Begin
- inherited Destroy;
- end;
-
- procedure TFormExThread.Release;
- Begin
- end;
-
- procedure TFormExThread.Execute;
- begin
- ReturnValue := 0;
- end;
-
- constructor TTrayIcon.Create(Parent:tForm;ParentClass:tComponent);
- begin
- inherited Create;
-
- FIconVisible := False;
- FCycleInterval := 200;
- FEnabled := False;
- ParentForm := Parent;
- ParentFormEx := ParentClass;
-
- FIcon := TIcon.Create;
-
- IconData.cbSize := SizeOf(TNotifyIconData);
- IconData.wnd := AllocateHWnd(HandleIconMessage);
- IconData.uId := IconID;
- IconData.uFlags := NIF_ICON + NIF_MESSAGE + NIF_TIP;
- IconData.uCallbackMessage := WM_ICONTRAYNOTIFY;
- end;
-
- destructor TTrayIcon.Destroy;
- begin
- SetIconVisible(False);
- FIcon.Free;
- DeallocateHWnd(IconData.Wnd);
- inherited Destroy;
- end;
-
- procedure TTrayIcon.Click;
- begin
- if Assigned(TFormEx(ParentFormEx).FOnTrayIconClick) then
- TFormEx(ParentFormEx).FOnTrayIconClick(Self);
- end;
-
- procedure TTrayIcon.DblClick;
- begin
- if Assigned(TFormEx(ParentFormEx).FOnTrayIconDblClick) then
- TFormEx(ParentFormEx).FOnTrayIconDblClick(Self);
- end;
-
-
- procedure TTrayIcon.MouseDown(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- begin
- if Assigned(TFormEx(ParentFormEx).FOnTrayIconMouseDown) then
- TFormEx(ParentFormEx).FOnTrayIconMouseDown(Self, Button, Shift, X, Y);
- end;
-
- procedure TTrayIcon.MouseUp(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- begin
- if Assigned(TFormEx(ParentFormEx).FOnTrayIconMouseUp) then
- TFormEx(ParentFormEx).FOnTrayIconMouseUp(Self, Button, Shift, X, Y);
- end;
-
-
- procedure TTrayIcon.MouseMove(Shift: TShiftState; X, Y: Integer);
- begin
- if Assigned(TFormEx(ParentFormEx).FOnTrayIconMouseMove) then
- TFormEx(ParentFormEx).FOnTrayIconMouseMove(Self, Shift, X, Y);
- end;
-
- procedure TTrayIcon.CycleIcon;
- begin
- if Assigned(TFormEx(ParentFormEx).FOnTrayIconCycle) then
- TFormEx(ParentFormEx).FOnTrayIconCycle(Self, IconIndex);
- end;
-
- procedure TTrayIcon.NextIconCycle;
- begin
- if Assigned(FIconList) then
- begin
- CycleIcon;
- FIconList.GetIcon(IconIndex, FIcon);
- ModifyIcon;
-
- if IconIndex < FIconList.Count-1 then Inc(IconIndex)
- else IconIndex := 0;
- end;
- end;
-
- procedure TTrayIcon.HandleIconMessage(var Msg: TMessage);
-
- function ShiftState: TShiftState;
- begin
- Result := [];
- if GetKeyState(VK_SHIFT) < 0 then Include(Result, ssShift);
- if GetKeyState(VK_CONTROL) < 0 then Include(Result, ssCtrl);
- if GetKeyState(VK_MENU) < 0 then Include(Result, ssAlt);
- end;
-
- var
- Pt: TPoint;
- Shift: TShiftState;
- I: Integer;
- M: TMenuItem;
- begin
- if Msg.Msg = WM_ICONTRAYNOTIFY then
- begin
- case Msg.lParam of
-
- WM_MOUSEMOVE:
- if FEnabled then
- begin
- Shift := ShiftState;
- GetCursorPos(Pt);
- MouseMove(Shift, Pt.X, Pt.Y);
- end;
-
- WM_LBUTTONDOWN:
- if FEnabled then
- begin
- Shift := ShiftState + [ssLeft];
- GetCursorPos(Pt);
- MouseDown(mbLeft, Shift, Pt.X, Pt.Y);
- PopUpAtCursor(0);
- end;
-
- WM_RBUTTONDOWN:
- if FEnabled then
- begin
- Shift := ShiftState + [ssRight];
- GetCursorPos(Pt);
- MouseDown(mbRight, Shift, Pt.X, Pt.Y);
- PopUpAtCursor(1);
- end;
-
- WM_MBUTTONDOWN:
- if FEnabled then
- begin
- Shift := ShiftState + [ssMiddle];
- MouseDown(mbMiddle, Shift, Pt.X, Pt.Y);
- GetCursorPos(Pt);
- end;
-
- WM_LBUTTONUP:
- if FEnabled then
- begin
- Shift := ShiftState + [ssLeft];
- GetCursorPos(Pt);
- MouseUp(mbLeft, Shift, Pt.X, Pt.Y);
- end;
-
- WM_RBUTTONUP:
- if FEnabled then
- begin
- Shift := ShiftState + [ssRight];
- GetCursorPos(Pt);
- MouseUp(mbRight, Shift, Pt.X, Pt.Y);
- end;
-
- WM_MBUTTONUP:
- if FEnabled then
- begin
- Shift := ShiftState + [ssMiddle];
- GetCursorPos(Pt);
- MouseUp(mbMiddle, Shift, Pt.X, Pt.Y);
- end;
-
- WM_LBUTTONDBLCLK:
- if FEnabled then
- begin
- DblClick;
- If FLeftPopUpMenu=nil then
- Begin
- M := nil;
- if Assigned(FRightPopupMenu) then
- if (FRightPopupMenu.AutoPopup) then
- for I := FRightPopUpMenu.Items.Count -1 downto 0 do
- begin
- if FRightPopupMenu.Items[I].Default then
- M := FRightPopupMenu.Items[I];
- end;
- if M <> nil then
- M.Click;
- End;
- end;
- end;
- end
-
- else
- case Msg.Msg of
- WM_QUERYENDSESSION: Msg.Result := 1;
- else
- Msg.Result := DefWindowProc(IconData.Wnd, Msg.Msg, Msg.wParam, Msg.lParam);
- end;
- end;
-
-
- procedure TTrayIcon.SetIcon(Value: TIcon);
- begin
- FIcon.Assign(Value);
- ModifyIcon;
- end;
-
- procedure TTrayIcon.SetIconVisible(Value: Boolean);
- begin
- if Value then ShowIcon else HideIcon;
- FIconVisible:=Value;
- end;
-
- procedure TTrayIcon.SetCycleIcons(Value: Boolean);
- begin
- If (FCycleIcons<>Value) then
- Begin
- FCycleIcons := Value;
- If Value then
- Begin
- IconIndex := 0;
- Timer:=tTimer.Create(nil);
- Timer.Interval:=FCycleInterval;
- Timer.Enabled:=True;
- Timer.OnTimer:=OnTimer;
- End else
- If Assigned(Timer) then Timer.Free;
- End;
- end;
-
-
- procedure TTrayIcon.SetCycleInterval(Value: Cardinal);
- begin
- If Value<>FCycleInterval then
- Begin
- FCycleInterval := Value;
-
- If FCycleIcons then
- Begin
- Timer.Interval:=Value;
- End;
- End;
- end;
-
- procedure TTrayIcon.SetHint(Value: String);
- begin
- If Value<>FHint then
- Begin
- FHint := Value;
- ModifyIcon;
- End;
- end;
-
- procedure TTrayIcon.SetShowHint(Value: Boolean);
- begin
- If Value<>FShowHint then
- begin
- FShowHint := Value;
- ModifyIcon;
- end;
- end;
-
- Procedure TTrayIcon.OnTimer(Sender:TObject);
- Begin
- NextIconCycle;
- End;
-
- function TTrayIcon.InitIcon: Boolean;
- begin
- Result := False;
- if Not Designing then
- begin
- IconData.hIcon := FIcon.Handle;
- if (FHint <> '') and (FShowHint) then
- StrLCopy(IconData.szTip, PChar(FHint), SizeOf(IconData.szTip))
- else
- IconData.szTip := '';
- Result := True;
- end;
- end;
-
-
- function TTrayIcon.ShowIcon: Boolean;
- begin
- Result := False;
- if InitIcon then Result := Shell_NotifyIcon(NIM_ADD, @IconData);
- end;
-
- function TTrayIcon.HideIcon: Boolean;
- begin
- Result := Shell_NotifyIcon(NIM_DELETE, @IconData);
- end;
-
- function TTrayIcon.ModifyIcon: Boolean;
- begin
- Result := False;
- if InitIcon then
- Result := Shell_NotifyIcon(NIM_MODIFY, @IconData);
- end;
-
- procedure TTrayIcon.PopupAtCursor(Index:Integer);
- var
- CursorPos: TPoint;
- begin
- Case Index of
- 0 : Begin
- if Assigned(LeftPopupMenu) then
- if LeftPopupMenu.AutoPopup then
- if GetCursorPos(CursorPos) then
- begin
- Application.ProcessMessages;
- SetForegroundWindow((ParentForm as TWinControl).Handle);
- if Assigned(Screen.ActiveControl) then
- SetFocus(Screen.ActiveControl.Handle);
- LeftPopupMenu.PopupComponent := ParentForm ;
- LeftPopupMenu.Popup(CursorPos.X, CursorPos.Y);
- PostMessage((ParentForm as TWinControl).Handle, WM_NULL, 0, 0);
- end;
- End;
- 1 : Begin
- if Assigned(RightPopupMenu) then
- if RightPopupMenu.AutoPopup then
- if GetCursorPos(CursorPos) then
- begin
- Application.ProcessMessages;
- SetForegroundWindow((ParentForm as TWinControl).Handle);
- if Assigned(Screen.ActiveControl) then
- SetFocus(Screen.ActiveControl.Handle);
- RightPopupMenu.PopupComponent := ParentForm ;
- RightPopupMenu.Popup(CursorPos.X, CursorPos.Y);
- PostMessage((ParentForm as TWinControl).Handle, WM_NULL, 0, 0);
- end;
- End;
- End;
- end;
-
- procedure TRatio.SetWidth(Value:Integer);
- begin
- If (Value<>FWidth) then
- Begin
- FWidth := Value;
- If Height=0 then FAspectRatio:=0 else
- FAspectRatio:=Width/Height;
- End;
- end;
-
- procedure TRatio.SetHeight(value:integer);
- begin
- If (Value<>FHeight) then
- Begin
- FHeight := Value;
- If Height=0 then FAspectRatio:=0 else
- FAspectRatio:=Width/Height;
- End;
- end;
-
- procedure TRatio.SetAspectRatio(Value:Single);
- begin
- If (FAspectRatio<>Value) then
- Begin
- FAspectRatio:=Value;
- FWidth:=100;
- If Value=0 then FHeight:=0 else
- FHeight:=Trunc(100/value);
- End;
- End;
-
- destructor TResize.Destroy;
- begin
- FRatio.Free;
- inherited Destroy;
- end;
-
- constructor TResize.Create;
- begin
- inherited Create;
- FRatio := TRatio.Create;
- FBorderWidth := 2;
- end;
-
- procedure TResize.SetRatio(Value:TRatio);
- begin
- FRatio.Assign(Value);
- end;
-
- constructor TMargin.Create;
- begin
- inherited Create;
- LeftMin := -5;
- LeftMax := 10;
- RightMin := -5;
- RightMax := 10;
- TopMin := -5;
- TopMax := 10;
- BottomMin := -5;
- BottomMax := 10;
- Enabled := False;
- end;
-
- destructor TPlacement.Destroy;
- begin
- FMargin.Free;
- inherited Destroy;
- end;
-
- constructor TPlacement.Create(Parent:tForm);
- begin
- FMargin := TMargin.Create;
- ParentForm := Parent;
- inherited Create;
- end;
-
- Procedure TPlacement.SetTopMost(Value:tFormTopMostStyle);
- Begin
- if Value<>FTopMost then
- Begin
- FTopMost := Value;
- If Not Designing then TopMostAction;
- End;
- End;
-
- Procedure TPlacement.TopMostAction;
- Begin
- If (FTopMost=ftmsAlways) then
- SetWindowPos(ParentForm.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE) else
- SetWindowPos(ParentForm.Handle, HWND_NOTOPMOST,0,0,0,0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
- End;
-
-
- constructor TCoverGradient.Create;
- Begin
- inherited Create;
- FSource:=clBlue;
- FDestination:=clNavy;
- End;
-
- destructor TCoverGradient.Destroy;
- Begin
- inherited Destroy;
- End;
-
- constructor TCoverImage.Create;
- Begin
- inherited Create;
- FClient:=tBitmap.Create;
- FDrawMethod:=dmTile;
- End;
-
- destructor TCoverImage.Destroy;
- Begin
- FClient.Free;
- inherited Destroy;
- End;
-
- procedure TCoverImage.SetClient(Value:tBitmap);
- Begin
- If (Value<>FClient) then
- begin
- FClient.Free;
- FClient:=tBitmap.Create;
- FClient.Assign(Value);
- End;
- End;
-
- Procedure TCoverImage.SetDrawMethod(Value:tDrawMethod);
- Begin
- if (Value<>FDrawMethod) then
- Begin
- FDrawMethod:=Value;
- End;
- End;
-
- constructor TCover.Create;
- Begin
- inherited Create;
- FCoverImage := tCoverImage.Create;
- FCoverGradient := tCoverGradient.Create;
- End;
-
- destructor TCover.Destroy;
- Begin
- FCoverGradient.Free;
- FCoverImage.Free;
- inherited Destroy;
- End;
-
- procedure TFormEx.SaveSettings;
- Begin
- If Not FormSaver.Enabled then Exit;
-
- With TRegistry.Create do
- Begin
- If FormSaver.Global then
- RootKey:=HKEY_LOCAL_MACHINE else
- RootKey:=HKEY_CURRENT_USER;
- If OpenKey(FormSaver.KeyName,true) then
- Begin
- If FormSaver.Size then
- Begin
- WriteInteger('Width',ParentForm.Width);
- WriteInteger('Height',ParentForm.Height);
- End;
- If FormSaver.Position then
- Begin
- WriteInteger('X',ParentForm.Left);
- WriteInteger('Y',ParentForm.Top);
- End;
- End;
-
- End;
-
- End;
-
- procedure TFormEx.LoadSettings;
- Begin
- If Not FormSaver.Enabled then Exit;
-
- With TRegistry.Create do
- Begin
-
- If FormSaver.Global then
- RootKey:=HKEY_LOCAL_MACHINE else
- RootKey:=HKEY_CURRENT_USER;
- If OpenKey(FormSaver.KeyName,False) then
- Begin
- If FormSaver.Size then
- Begin
- If ValueExists('Width') then
- ParentForm.Width:=ReadInteger('Width');
- If ValueExists('Height') then
- ParentForm.Height:=ReadInteger('Height');
- End;
- If FormSaver.FPosition then
- Begin
- If ValueExists('X') then
- ParentForm.Left:=ReadInteger('X');
- If ValueExists('Y') then
- ParentForm.Top:=ReadInteger('Y');
- End;
- End;
-
- End;
- End;
-
- constructor tCaptionScroll.Create(Parent:tForm);
- begin
- inherited Create;
- ParentForm:= Parent;
- ParentHwnd:= Parent.Handle;
- FInterval := 200;
- FSpace := ' ';
- TmpCount := 1;
- OldAppCaption := Application.Title;
- OldFormCaption := Parent.Caption;
- FCaption := Parent.Caption;
- end;
-
- destructor tCaptionScroll.Destroy;
- begin
- inherited Destroy;
- end;
-
- procedure tCaptionScroll.SetCaption(Value: String);
- begin
- if (FCaption <> Value) then
- begin
- FCaption := Value;
- If Not Designing then
- Begin
- If (ParentForm.Caption='') then
- begin
- ParentForm.Caption := Value;
- End;
- if FIsMainWindow then
- Application.Title := Value;
- TmpCount := 1;
- End;
- end;
- end;
-
- Procedure tCaptionScroll.SetEnabled(Value:Boolean);
- Begin
- If (Value<>FEnabled) then
- Begin
- FEnabled:=Value;
- If Not Designing then
- Begin
- If FEnabled then
- Begin
- Timer:=TTimer.Create(nil);
- Timer.OnTimer:=OnTimer;
- Timer.Interval:=FInterval;
- Timer.Enabled:=True;
- ParentForm.Caption := FCaption;
- if FIsMainWindow then Application.Title := FCaption;
- TmpCount := 1;
- End else
- If Not FEnabled then
- Begin
- If Assigned(Timer) then
- Timer.Free;
- Application.Title:=OldAppCaption;
- ParentForm.Caption:=OldFormCaption;
- End;
- End;
- End;
- End;
-
- procedure tCaptionScroll.SetInterval(Value: Word);
- begin
- if (Value <> FInterval) then
- begin
- FInterval := Value;
- Timer.Interval:=Value;
- end;
- end;
-
- Procedure TCaptionScroll.OnTimer(Sender: TObject);
- Begin
- ProcessCaption;
- End;
-
- procedure tCaptionScroll.ProcessCaption;
- var
- St: String;
- MaxCaptionLength : Integer;
- begin
- try
- St := FCaption + FSpace;
- ParentForm.Caption := Copy(St, TmpCount, Length(St) - TmpCount + 1) + Copy(St, 1, TmpCount - 1);
- if FIsMainWindow then Application.Title := ParentForm.Caption;
- if Direction = dLeft then
- begin
- inc(TmpCount);
- if TmpCount > Length(St) then TmpCount := 1;
- end
- else
- begin
- dec(TmpCount);
- if TmpCount = 0 then TmpCount := Length(St);
- end;
- except
- end;
- end;
-
- constructor TAnimatedIcon.Create(Parent:tForm);
- begin
- inherited Create;
- ParentForm:= Parent;
- FDelay := 200;
- end;
-
- destructor TAnimatedIcon.Destroy;
- begin
- inherited Destroy;
- end;
-
- Procedure TAnimatedIcon.SetEnabled(Value:Boolean);
- Begin
- If (Value<>FEnabled) then
- Begin
- FEnabled:=Value;
- If Not Designing then
- Begin
- If FEnabled then
- Begin
- Ic:=tIcon.Create;
- Timer:=TTimer.Create(nil);
- Timer.OnTimer:=OnTimer;
- Timer.Interval:=FDelay;
- Timer.Enabled:=True;
- FIndex:=0;
- End else
- If Not FEnabled then
- Begin
- If Assigned(Timer) then
- Timer.Free;
- If Assigned(IC) then
- Ic.Free;
- End;
- End;
- End;
- End;
-
- Procedure TAnimatedIcon.OnTimer(Sender: TObject);
- Begin
- If Assigned(Icons) then
- Begin
- Icons.GetIcon(FIndex,Ic);
- Inc(FIndex);
- ParentForm.Icon:=Ic;
- If FIndex>Icons.Count then FIndex:=0;
- End;
- End;
-
- constructor TAppearance.Create(Parent:tForm);
- Begin
- inherited Create;
- ParentForm := Parent;
- ParentHwnd := Parent.Handle;
- OldStyleEx := GetWindowLong(ParentHwnd,GWL_EXSTYLE);
- FShowTitleBar := True;
- FShapePoints := tStringList.Create;
- FCover := TCover.Create;
- FCaptionScroll := tCaptionScroll.Create(ParentForm);
- FAlwaysMinimize:= False;
- FAnimatedIcon := TAnimatedIcon.Create(ParentForm);
- End;
-
- destructor TAppearance.Destroy;
- Begin
- FAnimatedIcon.Free;
- FCaptionScroll.Free;
- FCover.Free;
- FShapePoints.Free;
- inherited Destroy;
- End;
-
- Procedure TAppearance.ApplyShape;
- Var Index : Integer;
- ArrPoints : Array of TPoint;
- MainhRgn : hRgn;
- X,Y : Integer;
-
- Procedure ParsePoint(Point:String;var X,Y:Integer);
- Begin
- X:=StrToInt(Copy(Point,1,Pos(',',Point)-1))+1;
- Y:=StrToInt(Copy(Point,Pos(',',Point)+1, Length(Point) - Pos(',',Point)+1))+1;
- End;
-
- Begin
- If (FShapePoints.Count<>0) And Not Designing then
- Begin
- SetLength(ArrPoints, FShapePoints.Count);
- For Index:=0 to FShapePoints.Count-1 do
- Begin
- ParsePoint(FShapePoints[Index],X,Y);
- ArrPoints[Index].X:=X;
- ArrPoints[Index].Y:=Y;
- End;
- MainhRgn:=CreatePolygonRgn(ArrPoints[0],FShapePoints.Count,2);
- SetWindowRgn(ParentHwnd,MainhRgn,True);
- End;
- End;
-
- Procedure TAppearance.RemoveShape;
- Begin
- SetWindowRgn(ParentHwnd,0,True);
- End;
-
- Procedure TAppearance.SetShapePoints(Value : tStrings);
- Begin
- If Value<>FShapePoints then
- Begin
- FShapePoints.Assign(Value);
- End;
- End;
-
- Procedure TAppearance.SetAcceptFiles(Value: Boolean);
- Begin
- If (Value <> FAcceptFiles) then
- Begin
- FAcceptFiles := Value;
- If Not Designing then
- DragAcceptFiles(ParentHwnd, FAcceptFiles)
- End;
- End;
-
- Procedure TAppearance.SetShowOnTaskBar(Value:tFormTaskStyle);
- Begin
- If Value<>FShowOnTaskBar then
- Begin
- FShowOnTaskBar:=Value;
- If Not Designing then TaskAction;
- End;
- End;
-
- Procedure TAppearance.TaskAction;
- begin
- If (FShowOnTaskBar<>ftsDefault) then
- Begin
- If (FShowOnTaskBar=ftsAlways) then
- Begin
- If (GetWindowLong(ParentHwnd,GWL_EXSTYLE) and WS_EX_APPWINDOW)<>WS_EX_APPWINDOW then
- SetWindowLong(ParentHwnd,GWL_EXSTYLE,OldStyleEX or (WS_EX_APPWINDOW or WS_EX_CONTROLPARENT));
- End else
- If (FShowOnTaskBar=ftsWhenVisible) and IsWindowVisible(ParentHwnd) then
- Begin
- If (GetWindowLong(ParentHwnd,GWL_EXSTYLE) and WS_EX_APPWINDOW)<>WS_EX_APPWINDOW then
- SetWindowLong(ParentHwnd,GWL_EXSTYLE,OldStyleEX or (WS_EX_APPWINDOW or WS_EX_CONTROLPARENT))
- End else
- If (FShowOnTaskBar=ftsWhenVisible) and Not IsWindowVisible(ParentHwnd) then
- SetWindowLong(ParentHwnd,GWL_EXSTYLE,OldStyleEX);
- End else
- Begin
- SetWindowLong(ParentHwnd,GWL_EXSTYLE,OldStyleEX);
- End;
-
- If not Designing then
- DragAcceptFiles(ParentHwnd, FAcceptFiles)
- End;
-
-
- procedure TAppearance.SetShowTitlebar(value: boolean);
- Begin
- If (Value<>FShowTitleBar) then
- Begin
- FShowTitleBar := Value;
- If Not Designing then TitleBarAction;
- End;
- End;
-
- Procedure TAppearance.TitleBarAction;
- Var
- Save : LongInt;
- Begin
- If ParentForm = nil then exit;
- With ParentForm do
- begin
- case BorderStyle of
- bsNone,
- bsSizeToolWin,
- bsToolWindow: Exit;
- end;
-
- Save:=GetWindowLong(Handle,GWL_STYLE);
-
- If (Save and WS_CAPTION)=WS_CAPTION then
- Begin
- Case BorderStyle of
- bsSingle,
- bsSizeable : SetWindowLong(Handle,gwl_Style,Save and
- (Not(ws_Caption)) or ws_border);
- bsDialog : SetWindowLong(Handle,gwl_Style,Save and
- (Not(ws_Caption)) or ds_modalframe or ws_dlgframe);
- End;
-
- If Not FShowTitleBar then
- begin
- Height:=Height + getSystemMetrics(SM_CYCAPTION);
- end else
- Height:=Height - getSystemMetrics(SM_CYCAPTION);
-
- if FShowTitleBar then
- begin
- Height:=Height - getSystemMetrics(SM_CYCAPTION);
- end else
- Height:=Height + getSystemMetrics(SM_CYCAPTION);
-
- Refresh;
- End;
- End;
- end;
-
- Procedure TAppearance.SetCover(Value:tCover);
- Begin
- If (Value<>FCover) then
- begin
- FCover:=Value;
- End;
- End;
-
- Procedure TAppearance.SetCursor(Value : tFilename);
- Begin
- If (Value<>FCursor) then
- Begin
- FCursor:=Value;
- Screen.Cursors[crFormExCursor]:=LoadCursorFromFile(Pchar(FCursor));
- ParentForm.Cursor := crFormExCursor;
- End;
- End;
-
- Procedure TAppearance.SetFullScreen(value:boolean);
- Begin
- If (Value<>FFullscreen) Then
- Begin
- FFullScreen := Value;
- If FFullscreen Then
- Begin
- if not Designing then
- Begin
- Old:=Getwindowlong(ParentHwnd, Gwl_Style);
- Setwindowlong(ParentHwnd, Gwl_Style, Getwindowlong(ParentHwnd, Gwl_Style) And Not Ws_Caption);
- Oldh:=ParentForm.Height;
- Oldw:=ParentForm.Width;
- Oldx:=ParentForm.Left;
- Oldy:=ParentForm.Top;
- Olds:=ParentForm.Windowstate;
- ParentForm.Windowstate:=Wsmaximized;
- ParentForm.Clientheight:=Screen.Height;
- ParentForm.Refresh;
- End;
- End
- Else
- Begin
- if not Designing then
- Begin
- Setwindowlong(ParentHwnd, Gwl_Style, Old);
- ParentForm.Height:=Oldh;
- ParentForm.Width:=Oldw;
- ParentForm.Left:=Oldx;
- ParentForm.Top:=Oldy;
- ParentForm.Windowstate:=Olds;
- ParentForm.Refresh;
- End;
- End;
- End;
- End;
-
- Procedure TAppearance.SetAlwaysMinimize(Value:Boolean);
- Begin
- If (Value<>FAlwaysMinimize) then
- Begin
- FAlwaysMinimize:=Value;
- End;
- End;
-
- procedure TFormEx.NewParentWndProc(var Message:TMessage);
- var SkipOldWndProc : Boolean;
- Pos : tPoint;
- CPos : tPoint;
- Files : tStrings;
- FileCount : Integer;
- Index : Integer;
- Filename : ShortString;
- IsLeft ,
- IsRight ,
- IsTop ,
- IsBottom : Boolean;
- PR : PRect;
- I : Integer;
-
- DCH : HDC;
- PS : TPaintStruct;
-
- Begin
- SkipOldWndProc:=False;
-
- With Message do
- Begin
-
- If IgnoreNextMessage then
- begin
- Result := CallWindowProc(PrevParentWndProc, ParentHwnd, Msg, WParam, LParam);
- IgnoreNextMessage:=False;
- Exit;
- End;
-
- { Try to handle Window Message }
- If (Msg=WM_FONTCHANGE) then
- Begin
- If Assigned(FOnFontChange) then
- FOnFontChange(Self);
- End else
-
- if (Msg = WM_ENTERSIZEMOVE) then
- Begin
- If Assigned(FOnBeginSizeMove) then
- FOnBeginSizeMove(Self);
- End else
-
- if (Msg = WM_EXITSIZEMOVE) then
- Begin
- If Assigned(FOnEndSizeMove) then
- FOnEndSizeMove(Self);
- End else
-
- if (Msg = WM_QUERYOPEN) then
- Begin
- If FAppearance.AlwaysMinimize then
- begin
- SkipOldWndProc:=True;
- Result:=0;
- End;
- End else
-
- if (Msg=WM_ERASEBKGND) then
- Begin
- If FAppearance.Cover.Style<>fcsnone then
- Begin
- DrawBG;
- SkipOldWndProc:=True;
- Result:=1;
- End;
- End else
-
- If (Msg=WM_SIZE) then
- Begin
- End else
-
- If (Msg=WM_MOVE) then
- Begin
- End else
-
- If (Msg=WM_MOVING) then
-
- With FPlacement do
- Begin
- PR := Pointer(LParam);
-
- If ((PR^.left < Margin.LeftMax) and (PR^.Left > Margin.LeftMin) and (Margin.Enabled)) or
- ((AlwaysOnScreen) and (PR^.Left < 0))then
- Begin
- PR^.Left := 0;
- PR^.Right := ParentForm.Width;
- End;
-
- If ((PR^.Top < Margin.TopMax) and (PR^.Top > Margin.TopMin) and (Margin.Enabled)) or
- ((AlwaysOnScreen) and (PR^.Top < 0)) then
- begin
- PR^.Top := 0;
- PR^.Bottom := ParentForm.Height;
- end;
-
- if ((PR^.Bottom > screen.Height-Margin.BottomMax) and
- (PR^.Bottom+Margin.BottomMin < screen.Height) and (Margin.Enabled)) or
- ((AlwaysOnScreen) and (PR^.Bottom>screen.height)) then
- begin
- PR^.Bottom := Screen.Height;
- PR^.Top := Screen.Height - ParentForm.Height;
- end;
-
- if ((PR^.Right > Screen.Width - Margin.RightMax) and
- (PR^.Right + Margin.RightMin < Screen.Width) and (Margin.Enabled)) or
- ((AlwaysOnScreen) and (PR^.Right > Screen.Width)) then
- begin
- PR^.Right := Screen.Width;
- PR^.Left := Screen.Width - ParentForm.width;
- end;
- Result := CallWindowProc(PrevParentWndProc, ParentHwnd, Msg, WParam, LParam);
-
- End else
-
- If (Msg=WM_GETMINMAXINFO) then
- Begin
- Result := CallWindowProc(PrevParentWndProc, ParentHwnd, Msg, WParam, LParam);
- With PMinMaxInfo(lParam)^ do
- Begin
- With FResize do
- Begin
- if (FMaxWidth <> 0) then ptMaxTrackSize.X := FMaxWidth;
- if (FMaxHeight <> 0) then ptMaxTrackSize.Y := FMaxHeight;
- if (FMinWidth <> 0) then ptMinTrackSize.X := FMinWidth;
- if (FMinHeight <> 0) then ptMinTrackSize.Y := FMinHeight;
- End;
- End;
- End else
-
- If (Msg=WM_SIZING) then
- Begin
- If (Resize.Ratio.Enabled And
- (Resize.Ratio.AspectRatio<>0)) Then
- Begin
- PR := Pointer(LParam);
- If WParam = WMSZ_LEFT then
- PR^.Bottom := PR^.Top + trunc((PR^.Right-PR^.Left) / Resize.Ratio.AspectRatio) else
- If WParam = WMSZ_RIGHT then
- PR^.Bottom := PR^.Top + trunc((PR^.Right-PR^.Left) / Resize.Ratio.AspectRatio) else
- If WParam = WMSZ_TOP then
- PR^.Right := PR^.Left + trunc((PR^.Bottom-PR^.Top)*Resize.Ratio.AspectRatio) else
- If WParam = WMSZ_BOTTOM then
- PR^.Right := PR^.Left + trunc((PR^.Bottom-PR^.Top)*Resize.Ratio.AspectRatio) else
- If WParam = WMSZ_BOTTOMRIGHT then
- PR^.Right := PR^.Left + trunc((PR^.Bottom-PR^.Top)*Resize.Ratio.AspectRatio) else
- If WParam = WMSZ_BOTTOMLEFT then
- PR^.Left := PR^.Right - trunc((PR^.Bottom-PR^.Top)*Resize.Ratio.AspectRatio) else
- If WParam = WMSZ_TOPLEFT then
- PR^.Left := PR^.Right - trunc((PR^.Bottom-PR^.Top)*Resize.Ratio.AspectRatio) else
- If WParam = WMSZ_TOPRIGHT then
- PR^.Right := PR^.Left + trunc((PR^.Bottom-PR^.Top)*Resize.Ratio.AspectRatio);
- SkipOldWndProc := True;
- End;
- End else
-
- If (Msg=WM_SYSCOMMAND) then
- Begin
-
- If (WParam>SysMenuExID) and (FSysMenuEx<>nil) then
- Begin
- For I:=0 to FSysMenuEx.Items.Count-1 do
- Begin
- If FSysMenuEx.Items[I].Tag=WParam-SysMenuExID then
- FSysMenuEx.Items[I].Click;
- End;
- End;
-
- if (WParam=SC_MINIMIZE) then
- Begin
- If Assigned(FOnMinimize) then FOnMinimize(Self);
- If (FAppearance.ShowOnTaskBar=ftsAlways) then
- Begin
- SkipOldWndProc:=True;
- ShowWindow(ParentHwnd,SW_MINIMIZE);
- End;
- End else
- if (WParam=SC_MAXIMIZE) then
- Begin
- If Assigned(FOnMaximize) then FOnMaximize(Self);
- If (FAppearance.ShowOnTaskBar=ftsAlways) then
- Begin
- SkipOldWndProc:=True;
- ShowWindow(ParentHwnd,SW_MAXIMIZE);
- End;
- End else
- If (WParam=SC_RESTORE) then
- Begin
- If Assigned(FOnRestore) then FOnRestore(Self);
- If (FAppearance.ShowOnTaskBar=ftsAlways) then
- Begin
- SkipOldWndProc:=True;
- ShowWindow(ParentHwnd,SW_RESTORE);
- End;
- End;
- End else
-
- If (Msg=WM_SHOWWINDOW) then
- Begin
-
- if Bool(Wparam) then
- Begin
- LoadSettings;
- End else
- Begin
- { Hide }
- End;
-
- End else
-
- If (Msg=WM_DROPFILES) then
- Begin
- If Not Designing then
- Begin
-
- If (FPlacement.TopMost=ftmsWhenAcceptFiles) then
- SetForegroundWindow(ParentHwnd);
-
- DragQueryPoint(wParam, Pos);
-
- Files := TStringList.Create;
- Try
- FileCount := DragQueryFile(wParam, UINT(-1), nil, 0);
-
- For Index := 0 to (FileCount - 1) do
- Begin
- I:=DragQueryFile(wParam, Index, @Filename[1], 255);
- Filename[0]:=Char(I);
- Files.Add(Filename);
- End;
-
- If (FileCount > 0) and Assigned(FOnDropFiles) then
- FOnDropFiles(Self, Files, Pos);
- Finally
- Files.Free;
- End;
- End;
- End else
-
- If (Msg=WM_WINDOWPOSCHANGING) then
- Begin
- If (FPlacement.Moveable=fmsNever) then
- Begin
- PWindowPos(Lparam).X:=ParentForm.Left;
- PWindowPos(Lparam).Y:=ParentForm.Top;
- SkipOldWndProc:=True;
- Result:=0
- End;
- End else
-
- If (Msg=WM_NCHITTEST) then
- Begin
- Pos.x:=LoWord(LParam);
- Pos.y:=HiWord(LParam);
-
- If Assigned(FOnNonClientClick) then FOnNonClientClick(Self,Pos);
-
-
- Result := CallWindowProc(PrevParentWndProc, ParentHwnd, Msg, WParam, LParam);
- SkipOldWndProc:=True;
-
- If FResize.Enabled then
- Begin
-
- CPos := ParentForm.ScreenToClient(Pos);
-
- IsLeft := CPos.X < FResize.BorderWidth;
- IsTop := Pos.Y < ParentForm.Top + FResize.BorderWidth;
- IsRight := CPos.X + FResize.BorderWidth >= ParentForm.ClientWidth;
- IsBottom := CPos.Y + FResize.BorderWidth >= ParentForm.ClientHeight;
-
- If IsLeft then
- If IsTop then Result:=HTTOPLEFT else
- If IsBottom then Result:=HTBOTTOMLEFT else
- Result:=HTLEFT
- else
- If IsRight then
- If isTop then Result:=HTTOPRIGHT else
- If isBottom then Result:=HTBOTTOMRIGHT else
- Result:=HTRIGHT
- else
- If IsTop then
- Result:=HTTOP
- else
- If IsBottom then
- Result:=HTBOTTOM;
- end;
-
- If (Result=HTCLIENT) and (FPlacement.Moveable=fmsAlways) then
- Begin
- Result:=HTCAPTION;
-
- Pos:=ParentForm.ScreenToClient(Pos);
- if (ParentForm is TForm) then
- with (ParentForm as TForm) do
- begin
- for i := 0 to ComponentCount - 1 do
- Begin
- if Components[i] is TGraphicControl then
- Begin
- With (Components[i] as TGraphicControl) do
- Begin
- If (Pos.X >= Left) and (Pos.X<=Left+Width) and
- (Pos.Y >= Top ) and (Pos.Y<=Top+Height) and
- (Align=alNone) then
- Begin
- Result:=htClient;
- Break;
- End;
- End;
- End;
- end;
- End;
-
- End else
- If (Result=HTCAPTION) and (FPlacement.Moveable=fmsNever) then
- Begin
- Result:=HTCLIENT;
- End;
-
- End else
-
- If (Msg = WM_CLOSE) or (Msg = WM_DESTROY) then
- Begin
- SaveSettings;
- SeekAndDestroy := True;
- End;
-
-
- If Not SkipOldWndProc then
- Result := CallWindowProc(PrevParentWndProc, ParentHwnd, Msg, WParam, LParam);
-
- End;
- End;
-
- Constructor TFormEx.Create(AOwner:TComponent);
- Var P : Pointer;
- Begin
- inherited Create(AOwner);
-
- Designing:=(csDesigning in ComponentState);
- ParentHwnd:=(AOwner as TForm).Handle;
- ParentForm:=(AOwner as TForm);
- BGBuffer:=tBitmap.Create;
-
- If Not Designing then
- Begin
- PrevParentWndProc := Pointer(GetWindowLong(ParentHwnd, GWL_WNDPROC));
- P := MakeObjectInstance(NewParentWndProc);
- SetWindowLong(ParentHwnd, GWL_WNDPROC, LongInt(p));
-
- { FormExThread := tFormExThread.Create;
- FormExThread.Resume;
- } End;
-
- { Initialize Properties }
- FFormSaver := TFormSaver.Create;
- FFormSaver.Global := False;
- FFormSaver.FEnabled := False;
- If Not Designing then
- FFormSaver.FKeyName := 'Software\'+Application.Title+'\'+ParentForm.Caption;
- FFormSaver.Position := True;
- FFormSaver.Size := True;
-
- FResize := TResize.Create;
- FResize.Ratio.Width := ParentForm.Width;
- FResize.Ratio.Height := ParentForm.Height;
-
- FPlacement := TPlacement.Create(ParentForm);
- FPlacement.TopMost := ftmsDefault;
- FPlacement.Moveable := fmsDefault;
-
- FAppearance := TAppearance.Create(ParentForm);
- FAppearance.ShowOnTaskBar := ftsDefault;
- FAppearance.AcceptFiles := False;
- FAppearance.FullScreen := False;
-
-
- FTrayIcon := TTrayIcon.Create(ParentForm,Self);
-
- RebuildBG;
- End;
-
- procedure TFormEx.Loaded;
- begin
- inherited Loaded;
- Placement.TopMostAction;
- Appearance.ApplyShape;
- end;
-
- Destructor TFormEx.destroy;
- Begin
-
- If Not Designing then
- Begin
- { FormExThread.Release;
- } If not SeekAndDestroy then
- SetWindowLong(ParentHwnd, GWL_WNDPROC, LongInt(PrevParentWndProc));
-
- End;
-
- FTrayIcon.Free;
- FAppearance.Free;
- FFormSaver.Free;
- FPlacement.Free;
- FResize.Free;
-
- BGBuffer.Free;
- inherited destroy;
- End;
-
-
-
-
- procedure TFormEx.DrawBG;
- var Width,
- Height : Integer;
- Begin
- Width := ParentForm.ClientWidth;
- Height := ParentForm.ClientHeight;
- If (BGBuffer.Width<>Width) or
- (BGBuffer.Height<>Height) then RebuildBG;
- BitBlt(ParentForm.Canvas.Handle,0,0,Width,Height,BGBuffer.Canvas.Handle,0,0,SRCCopy);
- End;
-
- Procedure TFormEx.BuildBGGradient;
- Type
- tRGB = Record
- R, G, B : Byte;
- End;
-
- Function RGBtoColor(RGB:TRGB):TColor;
- Begin
- Result:=Windows.RGB(RGB.B,RGB.G,RGB.R);
- End;
-
- Function ColorToRGB(Color:TColor):TRGB;
- Begin
- Result.R:=GetRValue(Color);
- Result.G:=GetGValue(Color);
- Result.B:=GetBValue(Color);
- End;
-
-
- Var
- Width ,
- Height ,
- Y : Integer;
- Buffer : tBitmap;
- Rect : tRect;
- SourceRGB,
- DestRGB,
- CurrRGB : tRGB;
- RMode ,
- GMode ,
- BMode : Byte;
- begin
- SourceRGB := ColorToRGB(FAppearance.Cover.Gradient.Source);
- DestRGB := ColorToRGB(FAppearance.Cover.Gradient.Destination);
-
- Width := ParentForm.ClientWidth;
- Height := ParentForm.ClientHeight;
-
- Buffer := TBitmap.create;
- Buffer.Width := Width;
- Buffer.Height := Height;
-
- CurrRGB:=SourceRGB;
- If SourceRGB.R > DestRGB.R then RMode:=2 else { Dec }
- If SourceRGB.R < DestRGB.R then RMode:=1; { Inc }
- If SourceRGB.G > DestRGB.G then GMode:=2 else { Dec }
- If SourceRGB.G < DestRGB.G then GMode:=1; { Inc }
- If SourceRGB.B > DestRGB.B then BMode:=2 else { Dec }
- If SourceRGB.B < DestRGB.B then BMode:=1; { Inc }
-
- Rect.Left :=0;
- Rect.Right:=Buffer.width;
-
- For Y:=0 to 255 do
- begin
- Rect.Top := (Y) * Buffer.Height div 256;
- Rect.Bottom := (Y+1) * Buffer.Height div 256;
- Begin
- If CurrRGB.R <> DestRGB.R then
- If RMode = 1 then CurrRGB.R:=CurrRGB.R+1 else CurrRGB.R:=CurrRGB.R-1;
- If CurrRGB.G <> DestRGB.G then
- If GMode = 1 then CurrRGB.G:=CurrRGB.G+1 else CurrRGB.G:=CurrRGB.G-1;
- If CurrRGB.B <> DestRGB.B then
- If BMode = 1 then CurrRGB.B:=CurrRGB.B+1 else CurrRGB.B:=CurrRGB.B-1;
- Buffer.canvas.brush.color:=tcolor(rgb(CurrRGB.R,CurrRGB.G,CurrRGB.B));
- End;
- Buffer.Canvas.Fillrect(rect);
- End;
-
- BGBuffer.Free;
- BGBuffer:=tBitmap.Create;
- BGBuffer.Assign(Buffer);
- Buffer.Free;
- End;
-
- Procedure TFormEx.BuildBGImage;
- var w,h,x,y:integer;
- Buffer:tBitmap;
- Width,Height : Integer;
- Begin
- If FAppearance.Cover.Image.Image.Empty then
- Begin
- Exit;
- End;
-
- Width := ParentForm.ClientWidth;
- Height := ParentForm.ClientHeight;
-
- With FAppearance.Cover.Image do
- Begin
-
- Buffer:=tbitmap.create;
- Buffer.width:=Width;
- Buffer.Height:=Height;
-
- If FDrawMethod=dmNormal then
- Begin
- BitBlt(Buffer.Canvas.Handle,1,1,Image.Width,Image.Height,Image.Canvas.Handle,0,0,SRCCopy);
- End else
- If fDrawMethod=dmCenter then
- begin
- X := (Width - Image.Width) div 2;
- Y := (Height - Image.Height) div 2;
- BitBlt(Buffer.Canvas.Handle,X,Y,Image.Width,Image.Height,Image.Canvas.Handle,0,0,SRCCopy);
- End else
- If FDrawMethod=dmStretch then
- Begin
- StretchBlt(Buffer.Canvas.Handle,1,1,Width,Height,Image.Canvas.Handle,0,0,Image.Width,Image.Height,SRCCopy);
- End else
- If FDrawMethod=dmTile then
- Begin
- X:=1;
- Y:=1;
- W:=Image.Width;
- H:=Image.Height;
-
- While (X < Width) do
- Begin
- Y:=0;
- while (Y < Height) do
- Begin
- BitBlt(Buffer.Canvas.Handle,X,Y,Image.Width,Image.Height,Image.Canvas.Handle,0,0,SRCCopy);
- Inc(Y,H);
- end;
- Inc(X,W);
- End;
- End;
-
- BGBuffer.Free;
- BGBuffer:=tBitmap.Create;
- BGBuffer.Assign(Buffer);
-
- Buffer.Free;
- End;
- End;
-
- Procedure TFormEx.RebuildBG;
- Begin
- If FAppearance.Cover.Style=fcsImage then
- BuildBGImage else
- If FAppearance.Cover.Style=fcsGradient then
- BuildBGGradient;
- end;
-
- procedure TFormEx.SendKeys(WinHandle:Hwnd;Buffer:String);
- Var
- I: Integer;
- W: Word;
- D: DWORD;
- P: ^DWORD;
- begin
- P:=@D;
- SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,P,0);
- If IsIconic(WinHandle) then
- ShowWindow(WinHandle,SW_RESTORE);
- SetForegroundWindow(WinHandle);
- For I := 1 to Length(Buffer) do
- Begin
- W:=VkKeyScan(Buffer[i]);
- keybd_event(w,0,0,0);
- keybd_event(w,0,KEYEVENTF_KEYUP,0);
- End;
- SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,nil,0);
- SetForegroundWindow(ParentHwnd);
- SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,D,nil,0);
- end;
-
- procedure TFormEx.CaptureWindow(WinHandle:Hwnd;Filename:String);
- Var
- I : Integer;
- W : Word;
- D : DWORD;
- P : ^DWORD;
- DC : HDC;
- Buffer : tBitmap;
- Rect : TRect;
- begin
- P:=@D;
- SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,P,0);
- If IsIconic(WinHandle) then
- ShowWindow(WinHandle,SW_RESTORE);
- SetForegroundWindow(WinHandle);
- UpdateWindow(WinHandle);
-
- GetWindowRect(WinHandle,Rect);
- DC:=GetWindowDC(WinHandle);
- Buffer:=tBitmap.Create;
- Try
- Buffer.Width:=Rect.Right-Rect.Left;
- Buffer.Height:=Rect.Bottom-Rect.Top;
- BitBlt(Buffer.Canvas.Handle,0,0,Buffer.Width,Buffer.Height,
- DC,0,0,SRCCopy);
- Buffer.SaveToFile(Filename);
- Finally
- Buffer.Free;
- End;
- ReleaseDC(WinHandle,DC);
-
- SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,nil,0);
- SetForegroundWindow(ParentHwnd);
- SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,D,nil,0);
- end;
-
- Procedure TFormEx.Flash(Number,Delay:Integer);
- Var I:Integer;
- T:Integer;
- Begin
- For I:=1 to Number do
- Begin
- FlashWindow(ParentHwnd,True);
- T:=GetTickCount; While GetTickCount-T<Delay do;
- FlashWindow(ParentHwnd,False);
- T:=GetTickCount; While GetTickCount-T<Delay do;
- End;
- End;
-
- Procedure tFormEx.SetSysMenuEx(Value:tPopupMenu);
- var SysMenu : HMenu;
- Count : Integer;
- Begin
- If (Value<>FSysMenuEx) then
- Begin
- { Reset System Menu }
- SysMenu:=GetSystemMenu(ParentHwnd,True);
- FSysMenuEx:=Value;
- If FSysMenuEx=nil then Exit;
-
- SysMenu:=GetSystemMenu(ParentHwnd,False);
- For count:=0 to FSysMenuEx.Items.Count-1 do
- Begin
- If FSysMenuEx.Items[Count].Caption<>'-' then
- AppendMenu(SysMenu, mf_ByCommand, FSysMenuEx.Items[Count].Tag + SysMenuExID, Pchar(FSysMenuEx.Items[Count].Caption)) else
- AppendMenu(SysMenu, mf_ByCommand or MF_SEPARATOR, 0, '');
- End;
- End;
- End;
-
- Procedure TFormEx.CenterOnForm(Form:tForm);
- Begin
- parentForm.Left:=Form.Left +((Form.ClientWidth-parentForm.Width) div 2);
- parentForm.Top :=Form.Top +((Form.ClientHeight-parentForm.Height) div 2);
- End;
-
- Procedure TFormEx.HorizontalCenter(Form:tForm);
- Begin
- parentForm.Left:=Form.Left +((Form.ClientWidth-parentForm.Width) div 2);
- End;
-
- Procedure TFormEx.VerticalCenter(Form:tForm);
- Begin
- parentForm.Top :=Form.Top +((Form.ClientHeight-parentForm.Height) div 2);
- End;
-
-
- // ================================================================================================
- // Sizes the specified form perfectly in the Win95/NT4 client area, outside the taskbar, regardless
- // of the taskbar's size or location. Freeware by Peter M. Jagielski.
- // Call from Form.Create Event !
- // ================================================================================================
-
- procedure TFormEx.SizeForWindowsDesktop; { Outside taskbar area }
- var
- TaskBarHandle: HWnd;
- TaskBarCoord: TRect;
- CxScreen,
- CyScreen,
- CxFullScreen,
- CyFullScreen,
- CyCaption: Integer;
- begin
- TaskBarHandle := FindWindow('Shell_TrayWnd',Nil);
- if TaskBarHandle = 0 then
- parentForm.WindowState := wsMaximized
- else
- begin
- parentForm.WindowState := wsNormal;
- GetWindowRect(TaskBarHandle,TaskBarCoord);
- CxScreen := GetSystemMetrics(SM_CXSCREEN);
- CyScreen := GetSystemMetrics(SM_CYSCREEN);
- CxFullScreen := GetSystemMetrics(SM_CXFULLSCREEN);
- CyFullScreen := GetSystemMetrics(SM_CYFULLSCREEN);
- CyCaption := GetSystemMetrics(SM_CYCAPTION);
- parentForm.Width := CxScreen - (CxScreen - CxFullScreen) + 1;
- parentForm.Height := CyScreen - (CyScreen - CyFullScreen) + CyCaption + 1;
- parentForm.Top := 0;
- parentForm.Left := 0;
- parentForm.Position := poDefault;
- if (TaskBarCoord.Top = -2) and (TaskBarCoord.Left = -2) then
- if TaskBarCoord.Right > TaskBarCoord.Bottom then
- parentForm.Top := TaskBarCoord.Bottom
- else
- parentForm.Left := TaskBarCoord.Right;
- end;
- end;
-
- procedure Register;
- begin
- RegisterComponents('Jazarsoft', [TFormEx]);
- end;
-
- end.
-