« Blog Home

§ ListViewWndProc

A way to handle some messages for TListView without subclassing a new component.  In particular, this provides the EditCancel event that Delphi does not provide, and allows hiding the horizontal scrollbar which can be a problem in some circumstances.

type
    TForm1 = class(TForm)
  private
    { Private declarations }
    ...
    fListViewWndProc: TWndMethod;
    procedure ListViewWndProc(var msg: TMessage);
    ...
  end;
procedure TForm1.FormCreate(Sender: TObject);
begin
  ...
  fListViewWndProc := ListView1.WindowProc;
  ListView1.WindowProc := ListViewWndProc;
  ...
end;
procedure TForm1.ListViewWndProc(var msg: TMessage);
var
  oldStyle, newStyle: integer;
begin
  //get listview edit cancel event
  //https://groups.google.com/forum/#!topic/borland.public.delphi.vcl.components.using/4Wp-bHioono YAY Brad Stowers!
  if msg.Msg = CN_NOTIFY then
    begin
      if TWMNotify(msg).NMHdr^.code = LVN_ENDLABELEDIT then
        with PLVDispInfo(Pointer(TWMNotify(msg).NMHdr))^ do
          if (item.pszText = nil) and (item.iItem <> -1) then
            ListViewEditCanceled(item.iItem); //edit canceled. iItem = index
    end;
  //hide horizontal scrollbar
  //http://codeverge.com/embarcadero.delphi.vcl.using/hiding-scrollbars-for-dbctrlgrid/1067707 Peter Below
  if msg.Msg = WM_NCCALCSIZE then
    begin
      oldStyle := GetWindowLong(ListView1.Handle, GWL_STYLE);
      if fHideHScroll then
        newStyle := oldStyle and not WS_HSCROLL
      else
        newStyle := oldStyle or WS_HSCROLL;
      if newStyle <> oldStyle then
        SetWindowLong(ListView1.Handle, GWL_STYLE, newStyle);
    end;
  fListViewWndProc(msg);
end;  //ListViewWndProc

last edited on March 2nd, 2016 at 1:39 PM

Comments

No Comments Here. Add yours below!

Add your comment

Name:
Email: (Will not be displayed - Privacy policy)
Website:
Comments:
  random image I can't read it!
Give me a different one!
Verify Post: Input the text from the image above to verify this post (helps prevent spam)
 

« Blog Home


“Elli Qu- a friend of mine used to say, ‘Aim high.  You may miss the target but at least you won’t shoot your foot off.’”
Miles, Komarr, Lois McMaster Bujold