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

📄 extlistview.pas

📁 上传个考勤系统,希望别人也能用.该代码只能算初级的东东,软件代码复用性不高,重复代码比较多.唯一感觉有点取鉴的可能就是端口和dll的连接,还有线程的使用,本想改一改,但是手头没有考勤机了,对应考勤机是
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    procedure SaveChecks;
    procedure MeasureItem(var Height: UINT); override;
    procedure DrawItem(var Canvas: TCanvas; Index: Integer; Rect: TRect;
       State: TOwnerDrawState; var DefaultDrawing,
       FullRowSelect: boolean); override;
    procedure DrawSubItem(Index, SubItem: Integer; Rect: TRect;
       State: TOwnerDrawState; var DefaultDrawing: boolean); override;
    procedure DefaultDrawHeader(var Canvas: TCanvas; Index: Integer;
       var Rect: TRect; Selected: boolean); override;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure CreateWnd; override;
    procedure Loaded; override;
    procedure DefaultDrawItem(Index: Integer; Rect: TRect;
       State: TOwnerDrawState; FullRowSelect: boolean); override;
    procedure DefaultDrawSubItem(Index, SubItem: integer; Rect: TRect;
       State: TOwnerDrawState); override;
    // Event method handlers -- fire the events if they exist.
    procedure ItemChecked(ItemIndex: integer; Checked: boolean); virtual;
    function MarqueeBegin: boolean; virtual;
    procedure ItemActivate; virtual;
    function HotTrack(var Item: TNMListView): boolean; virtual;
    procedure GetInfoTip(InfoTip: PNMLVGetInfoTip); virtual;

    procedure VMGetDispInfo(var ItemInfo: TLVItemEx); virtual;
    procedure VMCacheHint(var HintInfo: TNMCacheHint); virtual;
    function VMFindItem(var FindInfo: TNMFindItem): integer; virtual;
    procedure VMStateChanged(var StateInfo: TNMODStateChange); virtual;
    procedure VMCaptionEdited(Item: integer; Canceled: boolean; const Text: string);

    // These should be redeclared as PUBLIC as needed.
    property HeaderHandle: HWnd
       read GetHeaderHandle;
    property SubItem_BoundsRect[Item: integer; SubItem: integer]: TRect
       index LVIR_BOUNDS
       read GetSubItemRect;
    property SubItem_IconRect[Item: integer; SubItem: integer]: TRect
       index LVIR_ICON
       read GetSubItemRect;
    property SubItem_LabelRect[Item: integer; SubItem: integer]: TRect
       index LVIR_LABEL
       read GetSubItemRect;
    property SubItem_SelectBoundsRect[Item: integer; SubItem: integer]: TRect
       index LVIR_SELECTBOUNDS
       read GetSubItemRect;
    property HotItem: integer
       read GetHotItem
       write SetHotItem;
    property HotCursor: HCursor
       read GetHotCursor
       write SetHotCursor;
    property WorkArea: TRect
       write SetWorkArea;
    property IsChecked[Index: integer]: boolean
       read GetCheckState
       write SetCheckState;
    property SubItem_ImageIndex[Item: integer; SubItem: integer]: integer
       read GetSubItemImageIndex
       write SetSubItemImageIndex;
    property SelectionMark: integer
       read GetSelectionMark
       write SetSelectionMark;
    property ItemIndent[Index: integer]: integer
       read GetItemIndent
       write SetItemIndent;

    // These should be redeclared as PUBLIC or PUBLISHED as needed
    property ExtendedStyles: TLVExtendedStyles
       read GetExtendedStyles
       write SetExtendedStyles
       default [lvxInfoTip];
    property VirtualMode: boolean
       read FVirtualMode
       write SetVirtualMode
       default FALSE;
    property HoverTime: Longint
       read GetHoverTime
       write SetHoverTime
       default -1;
    property RequireComCtlUpdate: boolean
       read FRequireComCtlUpdate
       write SetRequireComCtlUpdate
       default FALSE;
{$IFDEF DFS_TRY_BACKGROUND_IMAGE}
    property BackgroundImage: TELVBackgroundImage
       read FBackgroundImage
       write SetBackgroundImage;
{$ENDIF}

    // Autosave settings property.
    property SaveSettings: TdfsExtLVSaveSettings
       read FSaveSettings
       write FSaveSettings;

    property ColumnsFormat: TdfsExtListColumns
       read FColumnsFormat
       write SetColumnsFormat;

    // Events
    property OnItemChecked: TLVItemCheckedEvent
       read FOnItemChecked
       write FOnItemChecked;
    property OnMarqueeBegin: TLVMarqueeBeginEvent
       read FOnMarqueeBegin
       write FOnMarqueeBegin;
    property OnItemActivate: TLVItemActivateEvent
       read FOnItemActivate
       write FOnItemActivate;
    property OnHotTrack: TLVHotTrackEvent
       read FOnHotTrack
       write FOnHotTrack;
    property OnInfoTip: TLVInfoTipEvent
       read FOnInfoTip
       write FOnInfoTip;
    property OnVMGetItemInfo: TLVVMGetItemInfoEvent
       read FOnVMGetItemInfo
       write FOnVMGetItemInfo;
    property OnVMCacheHint: TLVVMCacheHintEvent
       read FOnVMCacheHint
       write FOnVMCacheHint;
    property OnVMFindItem: TLVVMFindItemEvent
       read FOnVMFindItem
       write FOnVMFindItem;
    property OnVMStateChanged: TLVVMStateChangedEvent
       read FOnVMStateChanged
       write FOnVMStateChanged;
    property OnVMCaptionEdited: TLVVMCaptionEditedEvent
       read FOnVMCaptionEdited
       write FOnVMCaptionEdited;
    property ShowSortArrows: boolean
       read GetShowSortArrows
       write SetShowSortArrows
       stored TRUE
       default FALSE;
    // Redeclare so we can reset checkboxes.
    property StateImages: {$IFDEF DFS_COMPILER_4_UP} TCustomImageList {$ELSE} TImageList {$ENDIF}
       read GetStateImages
       write SetStateImages;
    // Redeclare so we can know when it changes and hook into it.
    property SmallImages: {$IFDEF DFS_COMPILER_4_UP} TCustomImageList {$ELSE} TImageList {$ENDIF}
       read GetSmallImages
       write SetSmallImages;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    // Force reset of column image information
    procedure UpdateColumnsImages;
    procedure UpdateColumnImage(Index: integer);

    procedure SetIconSpacing(X, Y: integer);
    function GetSubItemAt(X, Y: integer): string;
    procedure SetColumnOrder(Count: integer; const IntArray: array of integer);
    function GetColumnOrder(Count: integer;
       var IntArray: array of integer): boolean;
    function ApproximateViewRect(Count: integer;
       const Proposed: TPoint): TPoint;
    procedure SetItemCountEx(Count: integer; Flags: TLVItemCountFlags);
    function StoreSettings: boolean; override;
    function WriteSettings: boolean; override;
    function LoadSettings: boolean; override;
    function ReadSettings: boolean; override;
    function CheckComCtlVersion(MajorHi, MajorLo,
       MinorHi, MinorLo: word): boolean;

    procedure ELV_EditCaption(Item: integer);
    function ELV_GetNextItem(StartItem: integer; Direction: TSearchDirection;
       States: TItemStates): integer;
    procedure ELV_SetItemState(Index: integer; States: TItemStates;
       Setting: boolean);
  end;

  TdfsExtListView = class(TCustomExtListView)
  public
    property LastColumnClicked;
    property CurrentColumnWidth;
    property HeaderHandle;
    property SubItem_BoundsRect;
    property SubItem_IconRect;
    property SubItem_LabelRect;
    property SubItem_SelectBoundsRect;
    property HotItem;
    property HotCursor;
    property WorkArea;
    property IsChecked;
    property SubItem_ImageIndex;
    property SelectionMark;
    property ItemIndent;
    property CurrentSortAscending;
  published
    property Columns;
    property ColumnSearch;
    property HideSelection;
    property ExtendedStyles;
    property VirtualMode;
    property HoverTime;
    property RequireComCtlUpdate;
{$IFDEF BACKGROUND_FIXED}
    property BackgroundImage;
{$ENDIF}
    property NoColumnResize;
    property SaveSettings;
    property ColumnsFormat;
    // New Events
    property OnItemChecked;
    property OnMarqueeBegin;
    property OnItemActivate;
    property OnHotTrack;
    property OnInfoTip;
    property OnVMGetItemInfo;
    property OnVMCacheHint;
    property OnVMFindItem;
    property OnVMStateChanged;
    property OnVMCaptionEdited;
    property ShowSortArrows;


    // Publish inherited protected properties
    property AutoColumnSort;
    property AutoSortStyle;
    property AutoResort;
    property AutoSortAscending;
    property ReverseSortArrows;
    property Style;

    property OnDrawHeader;
    property OnMeasureItem;
    property OnDrawItem;
    property OnDrawSubItem;
    property OnAfterDefaultDrawItem;
    property OnSortItems;
    property OnSortBegin;
    property OnSortFinished;
    property OnEditCanceled;


    property Align;
{$IFDEF DFS_COMPILER_4_UP}
    property Anchors;
    property BiDiMode;
{$ENDIF}
    property BorderStyle;
{$IFDEF DFS_COMPILER_4_UP}
    property BorderWidth;
{$ENDIF}
    property Color;
    property ColumnClick;
{$IFDEF DFS_COMPILER_4_UP}
    property Constraints;
{$ENDIF}
    property OnClick;
    property OnDblClick;
    property Ctl3D;
    property DragMode;
{$IFDEF DFS_COMPILER_4_UP}
    property DragKind;
{$ENDIF}
    property ReadOnly
       default False;
    property Enabled;
    property Font;
    property IconOptions;
    property Items;
    property AllocBy;
    property MultiSelect;
    property OnChange;
    property OnChanging;
    property OnColumnClick;
    property OnDeletion;
    property OnEdited;
    property OnEditing;
{$IFDEF DFS_COMPILER_4_UP}
    property OnEndDock;
{$ENDIF}
    property OnEnter;
    property OnExit;
    property OnInsert;
    property OnDragDrop;
    property OnDragOver;
    property DragCursor;
    property OnStartDrag;
    property OnEndDrag;
    property OnGetImageIndex;
{$IFDEF DFS_COMPILER_5_UP}
    property OnGetSubItemImage;
{$ENDIF}
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
{$IFDEF DFS_COMPILER_4_UP}
    property OnResize;
    property OnSelectItem;
    property OnStartDock;
{$ENDIF}
    property ParentColor
       default False;
    property ParentFont;
    property ParentShowHint;
{$IFDEF DFS_COMPILER_4_UP}
    property ParentBiDiMode;
{$ENDIF}
    property ShowHint;
    property PopupMenu;
    property ShowColumnHeaders;
    property TabOrder;
    property TabStop
       default True;
    property ViewStyle;
    property Visible;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property LargeImages;
    property SmallImages;
    property StateImages;
  end;


{ You may find this function useful in install programs and such.  Example of
  usage is:
     if not CheckDLLVersion('COMCTL32.DLL', 4, 70, 0, 0) then ....
  which returns TRUE if COMCTL32.DLL is version 4.70.0.0 or higher. }
function CheckDLLVersion(const DLLName: string; MajorHi, MajorLo,
   MinorHi, MinorLo: word): boolean;


implementation

uses
{$IFDEF DFS_COMPILER_3_UP}
  ActiveX,
{$ELSE}
  OLE2, ExtColEd,
{$ENDIF}
  Registry;


function ListView_GetColumnEx(LVWnd: HWND; iCol: Integer;
   var pcol: TLVColumnEx): bool;
begin
  Result := bool(SendMessage(LVWnd, LVM_GETCOLUMN, iCol, LPARAM(@pcol)));
end;

function ListView_SetColumnEx(LVWnd: HWnd; iCol: Integer;
   const pcol: TLVColumnEx): Bool;
begin
  Result := bool(SendMessage(LVWnd, LVM_SETCOLUMN, iCol, Longint(@pcol)));
end;

function ListView_InsertColumnEx(LVWnd: HWND; iCol: Integer;
                                 const pcol: TLVColumnEx): Integer;
begin
  Result := SendMessage(LVWnd, LVM_INSERTCOLUMN, iCol, Longint(@pcol));
end;

function ListView_GetHeader(LVWnd: HWnd): HWnd;
begin
  Result := HWnd(SendMessage(LVWnd, LVM_GETHEADER, 0, 0));
end;

function ListView_SetIconSpacing(LVWnd: HWnd; cx, cy: integer): DWORD;
begin
  Result := SendMessage(LVWnd, LVM_SETICONSPACING, 0, MAKELONG(cx,cy));
end;

function ListView_SetExtendedListViewStyle(LVWnd: HWnd; ExStyle: LPARAM): DWORD;
begin
  Result := SendMessage(LVWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, ExStyle);
end;

function ListView_GetExtendedListViewStyle(LVWnd: HWnd): DWORD;
begin
  Result := SendMessage(LVWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
end;

function ListView_GetSubItemRect(LVWnd: HWnd; ParentItem, SubItem,
   Code: integer; var Rect: TRect): boolean;
begin
  Rect.Top := SubItem;
  Rect.Left := Code;
  Result := (SendMessage(LVWnd, LVM_GETSUBITEMRECT, ParentItem,
     LPARAM(@Rect)) <> 0);
end;

{$IFNDEF DFS_C3D4COMMCTRL}
  // C3 & D4 users don't need this because their COMMCTRL.PAS file has it right
  // and they can simply use the existing TLVHitTestInfo and
  // ListView_SubItemHitTest
function ListView_SubItemHitTestEx(LVWnd: HWnd;
   var HitTestInfo: TLVHitTestInfoEx): integer;
begin
  Result := SendMessage(LVWnd, LVM_SUBITEMHITTEST, 0, LPARAM(@HitTestInfo));
end;
{$ENDIF}

function ListView_SetColumnOrderArray(LVWnd: HWnd; Count: integer;
                                      IntArray: PIntArray): boolean;
begin
  Result := (SendMessage(LVWnd, LVM_SETCOLUMNORDERARRAY, Count,
     LPARAM(IntArray)) <> 0);

⌨️ 快捷键说明

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