如题,在调度listview的列宽时,不会触发OnCustomDrawSubItem消息,导致我在 SubItem中画出的图片不能及时刷新,我想获取列宽变化的消息,用listview.refresh刷新,但怎么也找不到。请大家帮忙了,

解决方案 »

  1.   

    在调度listview的列宽时会触发OnResize.在OnResize写处理代码即可.
      

  2.   

    To Wangzhi_04(代码工):
         OnResize我试过了,没用。
      我现在就差这么一点了,实在不想放弃。
      

  3.   

    TO sephil(NAILY Soft 【哈里波特大】) 
      OnColumnDragged 也不行啊。在Column区域连 鼠标的Move事件都捕捉不到!
      

  4.   

    只能重新继承一个控件了
    下面这个控件可以做到:
    {
      Question:
      How do I capture a column resize event in TListView, the OnResize
      only works when the ListView is changed?  Answer:
      The event can be added with a bit of work. See the custom TListview derivative
      below. It has 3 new events:
      OnColumnResize, OnBeginColumnResize, OnEndColumnResize
    }unit PBExListview;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls;type
      TLVColumnResizeEvent = procedure(Sender: TCustomListview;
        columnindex: Integer;
        columnwidth: Integer) of object;
      TPBExListview = class(TListview)
      private
        FBeginColumnResizeEvent: TLVColumnResizeEvent;
        FEndColumnResizeEvent: TLVColumnResizeEvent;
        FColumnResizeEvent: TLVColumnResizeEvent;  protected
        procedure DoBeginColumnResize(columnindex, columnwidth: Integer);
          virtual;
        procedure DoEndColumnResize(columnindex, columnwidth: Integer);
          virtual;
        procedure DoColumnResize(columnindex, columnwidth: Integer);
          virtual;
        procedure WMNotify(var Msg: TWMNotify); message WM_NOTIFY;
        function FindColumnIndex(pHeader: pNMHdr): Integer;
        function FindColumnWidth(pHeader: pNMHdr): Integer;
        procedure CreateWnd; override;
      published
        property OnBeginColumnResize: TLVColumnResizeEvent
          read FBeginColumnResizeEvent write FBeginColumnResizeEvent;
        property OnEndColumnResize: TLVColumnResizeEvent
          read FEndColumnResizeEvent write FEndColumnResizeEvent;
        property OnColumnResize: TLVColumnResizeEvent
          read FColumnResizeEvent write FColumnResizeEvent;
      end;procedure Register;implementationuses CommCtrl;procedure Register;
    begin
      RegisterComponents('PBGoodies', [TPBExListview]);
    end;procedure TPBExListview.DoBeginColumnResize(columnindex, columnwidth: Integer);
    begin
      if Assigned(FBeginColumnResizeEvent) then
        FBeginColumnResizeEvent(Self, columnindex, columnwidth);
    end;procedure TPBExListview.DoEndColumnResize(columnindex, columnwidth: Integer);
    begin
      if Assigned(FEndColumnResizeEvent) then
        FEndColumnResizeEvent(Self, columnindex, columnwidth);
    end;procedure TPBExListview.DoColumnResize(columnindex, columnwidth: Integer);
    begin
      if Assigned(FColumnResizeEvent) then
        FColumnResizeEvent(Self, columnindex, columnwidth);
    end;function TPBExListview.FindColumnIndex(pHeader: pNMHdr): Integer;
    var
      hwndHeader        : HWND;
      iteminfo          : THdItem;
      ItemIndex         : Integer;
      buf               : array[0..128] of Char;
    begin
      Result := -1;
      hwndHeader := pHeader^.hwndFrom;
      ItemIndex := pHDNotify(pHeader)^.Item;
      FillChar(iteminfo, SizeOf(iteminfo), 0);
      iteminfo.Mask := HDI_TEXT;
      iteminfo.pszText := buf;
      iteminfo.cchTextMax := SizeOf(buf) - 1;
      Header_GetItem(hwndHeader, ItemIndex, iteminfo);
      if CompareStr(Columns[ItemIndex].Caption, iteminfo.pszText) = 0 then
        Result := ItemIndex
      else
      begin
        for ItemIndex := 0 to Columns.Count - 1 do
          if CompareStr(Columns[ItemIndex].Caption, iteminfo.pszText) = 0 then
          begin
            Result := ItemIndex;
            Break;
          end;
      end;
    end;procedure TPBExListview.WMNotify(var Msg: TWMNotify);
    begin
      inherited;
      case Msg.NMHdr^.code of
        HDN_ENDTRACK:
          DoEndColumnResize(FindColumnIndex(Msg.NMHdr),
            FindColumnWidth(Msg.NMHdr));
        HDN_BEGINTRACK:
          DoBeginColumnResize(FindColumnIndex(Msg.NMHdr),
            FindColumnWidth(Msg.NMHdr));
        HDN_TRACK:
          DoColumnResize(FindColumnIndex(Msg.NMHdr),
            FindColumnWidth(Msg.NMHdr));
      end;
    end;procedure TPBExListview.CreateWnd;
    var
      wnd               : HWND;
    begin
      inherited;
      wnd := GetWindow(Handle, GW_CHILD);
      SetWindowLong(wnd, GWL_STYLE,
        GetWindowLong(wnd, GWL_STYLE) and not HDS_FULLDRAG);
    end;function TPBExListview.FindColumnWidth(pHeader: pNMHdr): Integer;
    begin
      Result := -1;
      if Assigned(PHDNotify(pHeader)^.pItem) and
        ((PHDNotify(pHeader)^.pItem^.mask and HDI_WIDTH) <> 0) then
        Result := PHDNotify(pHeader)^.pItem^.cxy;
    end;end.