⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvgcaption.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: JvgCaption.PAS, released on 2003-01-15.

The Initial Developer of the Original Code is Andrey V. Chudin,  [chudin att yandex dott ru]
Portions created by Andrey V. Chudin are Copyright (C) 2003 Andrey V. Chudin.
All Rights Reserved.

Contributor(s):
Michael Beck [mbeck att bigfoot dott com].

You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net

Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvgCaption.pas,v 1.31 2005/02/17 10:21:19 marquardt Exp $

unit JvgCaption;

{$I jvcl.inc}

interface

uses
  {$IFDEF USEJVCL}
  {$IFDEF UNITVERSIONING}
  JclUnitVersioning,
  {$ENDIF UNITVERSIONING}
  {$ENDIF USEJVCL}
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  StdCtrls, ExtCtrls,
  {$IFDEF USEJVCL}
  JvComponent,
  {$ENDIF USEJVCL}
  JvgTypes, JvgUtils, JvgCommClasses;

type
  {$IFDEF USEJVCL}
  TJvgCaption = class(TJvComponent)
  {$ELSE}
  TJvgCaption = class(TComponent)
  {$ENDIF USEJVCL}
  private
    FExcludeButtons: Boolean;
    FExcludeIcon: Boolean;
    FCaptBox: TJvgBevelOptions;
    FTextBox: TJvgBevelOptions;
    FIconBox: TJvgBevelOptions;
    FPrevWndProc: Pointer;
    FNewWndProc: Pointer;
    // FParent: TForm;
    FCaptionColor: TColor;
    FTextStyle: TglTextStyle;
    FFont: TFont;
    FTexture: TBitmap;
    FBmp: TBitmap;
    FImage: TImage;
    FTextureTransparent: Boolean;
    FAutoTransparentColor: TglAutoTransparentColor;
    FTransparentColor: TColor;

    FGlyphClose: TBitmap;
    FOwnerWidth: Integer;
    FBtnCount: Integer;
    FCloseRect: TRect;
    FCYCaption: Integer;
    FCXFrame: Integer;
    FCYFrame: Integer;
    FCXSMIcon: Integer;
    FCYSMIcon: Integer;
    FCXIcon: Integer;
    FCYIcon: Integer;
    procedure SetExcludeIcon(Value: Boolean);
    procedure SetExcludeButtons(Value: Boolean);
    procedure SetCaptionColor(Value: TColor);
    procedure SetTextStyle(Value: TglTextStyle);
    procedure SetFont(Value: TFont);
    procedure SetTexture(Value: TBitmap);
    procedure SetImage(Value: TImage);
    function GetTexture: TBitmap;
    procedure SetTextureTransparent(Value: Boolean);
    procedure SetAutoTransparentColor(Value: TglAutoTransparentColor);
    procedure SetTransparentColor(Value: TColor);
    procedure Repaint;
    procedure DrawIcon(DC: HDC; R: TRect);
    function DrawCaption(DrawAll: Boolean): TRect;
    procedure ParentWindowHookProc(var Msg: TMessage);
    procedure SetParentWindowHook;
    procedure FreeParentWindowHook;
    function CountCaptionButtons: Integer;
    procedure SmthChanged(Sender: TObject);
  protected
    //    procedure WndProc(var Message: TMessage);override;
    procedure Loaded; override;
    procedure Notification(Component: TComponent; Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    //    property Parent: TForm read FParent write SetParent;
    property ExcludeButtons: Boolean
      read FExcludeButtons write SetExcludeButtons default True;
    property ExcludeIcon: Boolean
      read FExcludeIcon write SetExcludeIcon default False;
    property CaptionColor: TColor
      read FCaptionColor write SetCaptionColor default clBtnFace;
    property TextStyle: TglTextStyle
      read FTextStyle write SetTextStyle default fstRaised;
    property Font: TFont read FFont write SetFont;
    property CaptBox: TJvgBevelOptions read FCaptBox write FCaptBox;
    property TextBox: TJvgBevelOptions read FTextBox write FTextBox;
    property IconBox: TJvgBevelOptions read FIconBox write FIconBox;
    property Texture: TBitmap read GetTexture write SetTexture;
    property Image: TImage read FImage write SetImage;
    property TextureTransparent: Boolean
      read FTextureTransparent write SetTextureTransparent default False;
    property AutoTransparentColor: TglAutoTransparentColor
      read FAutoTransparentColor write SetAutoTransparentColor default ftcLeftBottomPixel;
    property TransparentColor: TColor
      read FTransparentColor write SetTransparentColor default clBlack;
  end;

{$DEFINE GL_CAPT_BUTTONS}

{$IFDEF USEJVCL}
{$IFDEF UNITVERSIONING}
const
  UnitVersioning: TUnitVersionInfo = (
    RCSfile: '$RCSfile: JvgCaption.pas,v $';
    Revision: '$Revision: 1.31 $';
    Date: '$Date: 2005/02/17 10:21:19 $';
    LogPath: 'JVCL\run'
  );
{$ENDIF UNITVERSIONING}
{$ENDIF USEJVCL}

implementation

{$IFDEF USEJVCL}
uses
  Math,
  JvResources, JvJVCLUtils;
{$ELSE}
uses
  Math;
{$ENDIF USEJVCL}

{$IFDEF GL_CAPT_BUTTONS}
{$IFDEF MSWINDOWS}
{$R ..\Resources\JvgCaption.res}
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
{$R ../Resources/JvgCaption.res}
{$ENDIF UNIX}
{$ENDIF GL_CAPT_BUTTONS}

{$IFNDEF USEJVCL}

resourcestring
  RsEOnlyOneInstanceOfTJvgCaption = 'Cannot create more than one instance of TJvgCaption component';

function JvMakeObjectInstance(Method: TWndMethod): Pointer;
begin
  {$IFDEF COMPILER6_UP}
  Result := Classes.MakeObjectInstance(Method);
  {$ELSE}
  Result := MakeObjectInstance(Method);
  {$ENDIF COMPILER6_UP}
end;

procedure JvFreeObjectInstance(ObjectInstance: Pointer);
begin
  if ObjectInstance <> nil then
    {$IFDEF COMPILER6_UP}
    Classes.FreeObjectInstance(ObjectInstance);
    {$ELSE}
    FreeObjectInstance(ObjectInstance);
    {$ENDIF COMPILER6_UP}
end;

{$ENDIF !USEJVCL}

constructor TJvgCaption.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FCaptBox := TJvgBevelOptions.Create;
  FTextBox := TJvgBevelOptions.Create;
  FIconBox := TJvgBevelOptions.Create;
  FFont := TFont.Create;
  FExcludeButtons := True;
  FExcludeIcon := False;
  FCaptionColor := clBtnFace;
  FTextStyle := fstRaised;
  FTextBox.Inner := bvRaised;
  FIconBox.Inner := bvNone;
  FIconBox.Outer := bvNone;
  FTextureTransparent := False;
  FAutoTransparentColor := ftcLeftBottomPixel;
  FCaptBox.OnChanged := SmthChanged;
  FTextBox.OnChanged := SmthChanged;
  FIconBox.OnChanged := SmthChanged;

  //  FParent := nil;
  if not (AOwner is TForm) then
    Exit; //FParent:=TForm(AOwner) else Exit;

  {$IFDEF GL_CAPT_BUTTONS}
  //if (csDesigning in ComponentState)and not (csLoading in ComponentState) then
  begin
    FGlyphClose := TBitmap.Create;
    FGlyphClose.LoadFromResourceName(HInstance, 'JvgCaptionCLOSE');
  end;
  {$ENDIF GL_CAPT_BUTTONS}

  FCYCaption := GetSystemMetrics(SM_CYCAPTION);
  FCYFrame := GetSystemMetrics(SM_CYFRAME);
  FCXFrame := GetSystemMetrics(SM_CXFRAME);
  FCXSMIcon := GetSystemMetrics(SM_CXSMICON);
  FCYSMIcon := GetSystemMetrics(SM_CYSMICON);
  FCXIcon := GetSystemMetrics(SM_CXICON);
  FCYIcon := GetSystemMetrics(SM_CYICON);

  SetParentWindowHook;
end;

destructor TJvgCaption.Destroy;
begin
  FFont.Free;
  FCaptBox.Free;
  FTextBox.Free;
  FIconBox.Free;
  FTexture.Free;
  FGlyphClose.Free;
  FreeParentWindowHook;
  inherited Destroy;
end;

procedure TJvgCaption.Loaded;
begin
  inherited Loaded;
  if Assigned(FTexture) and not FTexture.Empty then
    FBmp := FTexture;
end;

procedure TJvgCaption.Notification(Component: TComponent;
  Operation: TOperation);
begin
  if (Component <> Self) and (Operation = opInsert) and (Component is TJvgCaption) then
    raise Exception.CreateRes(@RsEOnlyOneInstanceOfTJvgCaption);
end;

procedure TJvgCaption.SetParentWindowHook;
var
  P: Pointer;
begin
  P := Pointer(GetWindowLong(TForm(Owner).Handle, GWL_WNDPROC));
  if P <> FNewWndProc then
  begin
    FPrevWndProc := P;
    FNewWndProc := JvMakeObjectInstance(ParentWindowHookProc);
    SetWindowLong(TForm(Owner).Handle, GWL_WNDPROC, Longint(FNewWndProc));
  end;
end;

procedure TJvgCaption.FreeParentWindowHook;
begin
  if (FNewWndProc <> nil) and (FPrevWndProc <> nil) and
    (Pointer(GetWindowLong(TForm(Owner).Handle, GWL_WNDPROC)) = FNewWndProc) then
  begin
    //Repaint;
    SetWindowLong(TForm(Owner).Handle, GWL_WNDPROC, Longint(FPrevWndProc));
    // (rom) JvFreeObjectInstance call added
    JvFreeObjectInstance(FNewWndProc);
    FNewWndProc := nil;
  end;
end;

procedure TJvgCaption.ParentWindowHookProc(var Msg: TMessage);
var
  Pt: TPoint;

  procedure DefaultProc;
  begin
    Msg.Result := CallWindowProc(FPrevWndProc, TForm(Owner).Handle, Msg.Msg,
      Msg.WParam, Msg.LParam);
  end;

begin
  FOwnerWidth := TForm(Owner).Width;
  case Msg.Msg of
    // WM_CREATE: if TForm(Owner)<>nil then FreeParentWindowHook;
    WM_NCPAINT, // WM_MOUSEMOVE,
    WM_MOUSEACTIVATE, WM_NCACTIVATE, WM_SYSCOLORCHANGE, // WM_NCLBUTTONUP,
    WM_NCLBUTTONDBLCLK, WM_SIZE:
      begin
        DefaultProc;
        DrawCaption(True);
      end;
    WM_NCLBUTTONDOWN:
      begin
        DefaultProc;
        DrawCaption(False);
      end;
    WM_LBUTTONUP:
      begin
        DefaultProc;
        {$IFDEF GL_CAPT_BUTTONS}
        GetCursorPos(Pt);
        Dec(Pt.X, TForm(Owner).Left);
        Dec(Pt.Y, TForm(Owner).Top);
        if PtInRect(FCloseRect, Pt) then
          SendMessage(TForm(Owner).Handle, WM_CLOSE, 0, 0);
        {$ENDIF GL_CAPT_BUTTONS}
      end;
    WM_NCHITTEST:
      begin
        {$IFDEF GL_CAPT_BUTTONS}
        Pt := {TForm(Owner).ScreenToClient}(Point(LoWord(Msg.LParam) -

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -