Forum
Grundkurs
»Introduktion
»Snabbguide
»Komponenter
»Händelser
»Strängar
»Räkna med Delphi »Egna
typer
»Selektion
»Iteration
»Menyer
»Funktioner
»Arraystrukturer
Tips & Tricks
»Nya tips
»Blandat
»Databaser
»Filer
»Forms
»Grafik
»Internet
»Komponenter
»Matematik
»Multimedia
»Objekt/ActiveX
»Skrivare
»Strängar
»System
»Mest lästa tips
Artiklar
»Delphi och ADO
»Bygga en DLL
»Skapa en enkel rapport
»Hantera registret
»Enheter, units
»Klassen TCanvas
»Använd LookUp Controls
Nya
tips
Lägg
till tips
Delphilänkar
Gästbok
|
|
|
|
Förhindra storleksändring av Listviewkolumner
|
Kategori: Komponenter
Inlagt: 2007-04-27
Läst: 1612
Inlagt av: Staffan Berg
|
Beskrivning |
Detta exempel förhindrar användaren att storleksändra kolumnerna i en TListview.
|
Kod |
unit TestUnit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls; type TForm1 = class(TForm) ListView1: TListView; procedure FormShow(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); private { Private declarations } WndMethod: TWndMethod; function GetIndex(aNMHdr: pNMHdr): Integer; procedure CheckMesg(var aMesg: TMessage); public { Public declarations } end; var Form1: TForm1; implementation uses CommCtrl; {$R *.dfm} function TForm1.GetIndex(aNMHdr: pNMHdr): Integer; var hHWND: HWND; HdItem: THdItem; iIndex: Integer; iResult: Integer; iLoop: Integer; sCaption: string ; sText: string ; Buf: array [0..128] of Char; begin Result := -1; hHWND := aNMHdr^.hwndFrom; iIndex := pHDNotify(aNMHdr)^.Item; FillChar(HdItem, SizeOf(HdItem), 0); with HdItem do begin pszText := Buf; cchTextMax := SizeOf(Buf) - 1; Mask := HDI_TEXT; end; Header_GetItem(hHWND, iIndex, HdItem); with ListView1 do begin sCaption := Columns[iIndex].Caption; sText := HdItem.pszText; iResult := CompareStr(sCaption, sText); if iResult = 0 then Result := iIndex else begin iLoop := Columns.Count - 1; for iIndex := 0 to iLoop do begin iResult := CompareStr(sCaption, sText); if iResult <> 0 then Continue; Result := iIndex; break; end; end; end; end; procedure TForm1.CheckMesg(var aMesg: TMessage); var HDNotify: ^THDNotify; NMHdr: pNMHdr; iCode: Integer; iIndex: Integer; begin case aMesg.Msg of WM_NOTIFY: begin HDNotify := Pointer(aMesg.lParam); iCode := HDNotify.Hdr.code; if (iCode = HDN_BEGINTRACKW) or (iCode = HDN_BEGINTRACKA) then begin NMHdr := TWMNotify(aMesg).NMHdr; // chekck column index iIndex := GetIndex(NMHdr); // prevent resizing of columns if index's less than 3 if iIndex < 3 then aMesg.Result := 1; end else WndMethod(aMesg); end; else WndMethod(aMesg); end; end; procedure TForm1.FormShow(Sender: TObject); begin WndMethod := ListView1.WindowProc; ListView1.WindowProc := CheckMesg; end; procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin ListView1.WindowProc := WndMethod; end;
|
|
|