我根据您的指导,已经都实现了,十分感谢但是更新的时候我不知道图标应该如何更新。
procedure TRealMessengerX.UpdatafriendListBox(
  UpdataListbox: TListBox; PUpdataEmployee: PEmployee);
var
i: Integer; 
begin 
i := UpdataListbox.Items.IndexOfObject(TObject(PUpdataEmployee));
if i > -1 then
UpdataListbox.Items[i] :=PUpdataEmployee.Name + '(' + PUpdataEmployee.State + ')'+ #9 + PUpdataEmployee.userinfo;end;这个是更新的函数,已经都好使了,文字等等都正常更新了,但是图标应该如何更新呢

解决方案 »

  1.   

    您正在与blazingfire 交谈!   
    yujingfree      2008年05月20日 20点37分11秒 说:
    真不好意思还需要麻烦您。 
    我都已经做完毕了,但是还有一个问题就是更新头像的问题,我已经开帖子了 
    http://topic.csdn.net/u/20080520/13/368272b5-9ec3-4e41-ba98-1ca0d721a05a.html?seed=907436633 
    谢谢您了
    blazingfire      2008年05月20日 20点59分31秒 说:
    小兄弟,你把代码粘出来吧。只要自绘的
    yujingfree      2008年05月20日 21点08分54秒 说:
    procedure TRealMessengerX.FriendListBoxDrawItem(Control: TWinControl; 
    Index: Integer; Rect: TRect; State: TOwnerDrawState); 
    var 
    ImgRect, MemoRect: TRect; 
    Cnvs: TCanvas; 
    B: TBitmap; 
    S, Memo: string; 
    iPos: Integer; 
    MousePt: TPoint; 
    begin 
    Cnvs := friendListBox.Canvas; 
    ImgRect := Rect; 
    ImgRect.Right := ImgRect.Left + (ImgRect.Bottom - ImgRect.Top); //画图区域 
    Inc(Rect.Left,0);// 
    DrawText(Cnvs.Handle, PChar(S), -1, 
    Rect, DT_SingleLine or DT_VCENTER); // Cnvs.Font.Color := clGrayText; 
    Inc(MemoRect.Left,0);//+++ 
    DrawText(Cnvs.Handle, PChar(Memo), -1, 
    MemoRect, DT_SingleLine or DT_VCENTER); //这个函数里边添加了您给我的代码 
    MousePt := friendListBox.ScreenToClient(Mouse.CursorPos); ///&&鼠标位置 
    if odSelected in State then 
    begin 
    Cnvs.Brush.Color := TColor($00FFF4DD); 
    Cnvs.Pen.Color := TColor($00F3D6B2); 
    end 
    else if PtInRect(Rect, MousePt) then ///&&鼠标选中项目 
    begin 
    Cnvs.Brush.Color := TColor($00FFF4DD); 
    Cnvs.Pen.Color := TColor($00F3D6B2); 
    end 
    else 
    begin 
    Cnvs.Brush.Color := friendListBox.Color; 
    Cnvs.Pen.Color := friendListBox.Color; 
    end; 
    Cnvs.Brush.Style := bsSolid; 
    Cnvs.Rectangle(Rect); Cnvs.Brush.Style := bsClear; 
    if ImageListfriend.Count > 0 then 
    begin 
    B := TBitmap.Create; 
    try 
    ImageListfriend.GetBitmap(0, B); 
    B.PixelFormat := pf24bit; 
    B.Transparent := True; 
    InflateRect(ImgRect, -2, -2); 
    Cnvs.StretchDraw(ImgRect, B); 
    finally 
    B.Free; 
    end; 
    end; Rect.Left := ImgRect.Right; 
    MemoRect := Rect; 
    MemoRect.Top := (Rect.Top + Rect.Bottom) div 2; 
    Rect.Bottom := MemoRect.Top; 
    S := friendListBox.Items[Index]; iPos := Pos(#9, S); 
    Memo := Copy(S, iPos + 1, Length(S)); //提取备注 
    S := Copy(S, 1, iPos - 1); //提取名称 
    Cnvs.Font.Assign(friendListBox.Font); 
    Inc(Rect.Left, 10);////+++在画S之前加,具体多少根据你自己的需要 
    DrawText(Cnvs.Handle, PChar(S), -1, 
    Rect, DT_SingleLine or DT_VCENTER); //垂直、水平居中 画名字 Cnvs.Font.Color := clGrayText; 
    Inc(MemoRect.Left, 10);////+++在画Memo之前加,具体多少根据你自己的需要 
    DrawText(Cnvs.Handle, PChar(Memo), -1, 
    MemoRect, DT_SingleLine or DT_VCENTER); //垂直、水平居中 画名字 
    end; 
      

  2.   

    Result是什么?再哪里定义的?
      

  3.   


    procedure TRealMessengerX.FriendListBoxDrawItem(Control: TWinControl;
      Index: Integer; Rect: TRect; State: TOwnerDrawState);
    var
      ImgRect, MemoRect: TRect;
      Cnvs: TCanvas;
      B: TBitmap;
      S, Memo: string;
      iPos: Integer;
      MousePt: TPoint;
      Employee: PEmployee;
    begin
      Cnvs := friendListBox.Canvas;
      ImgRect := Rect;
      ImgRect.Right := ImgRect.Left + (ImgRect.Bottom - ImgRect.Top); //画图区域
      Inc(Rect.Left, 0); //
      DrawText(Cnvs.Handle, PChar(S), -1,
        Rect, DT_SingleLine or DT_VCENTER); //  Cnvs.Font.Color := clGrayText;
      Inc(MemoRect.Left, 0); //+++
      DrawText(Cnvs.Handle, PChar(Memo), -1,
        MemoRect, DT_SingleLine or DT_VCENTER); //这个函数里边添加了您给我的代码
      MousePt := friendListBox.ScreenToClient(Mouse.CursorPos); ///&&鼠标位置
      if odSelected in State then
      begin
        Cnvs.Brush.Color := TColor($00FFF4DD);
        Cnvs.Pen.Color := TColor($00F3D6B2);
      end
      else if PtInRect(Rect, MousePt) then ///&&鼠标选中项目
      begin
        Cnvs.Brush.Color := TColor($00FFF4DD);
        Cnvs.Pen.Color := TColor($00F3D6B2);
      end
      else
      begin
        Cnvs.Brush.Color := friendListBox.Color;
        Cnvs.Pen.Color := friendListBox.Color;
      end;
      Cnvs.Brush.Style := bsSolid;
      Cnvs.Rectangle(Rect);  Cnvs.Brush.Style := bsClear;
      if ImageListfriend.Count > 0 then
      begin
        B := TBitmap.Create;
        try
          //!!!!取出当前Index对应的 PEmployee+++++
          Employee := PEmployee(FriendListBox.Items.Objects[Index]);
          //!!!!计算出图标++++
          iPos := GetDrawImageIndex(Employee);
          //!!!!出来图标+++
          ImageListfriend.GetBitmap(iPos, B);
          B.PixelFormat := pf24bit;
          B.Transparent := True;
          InflateRect(ImgRect, -2, -2);
          Cnvs.StretchDraw(ImgRect, B);
        finally
          B.Free;
        end;
      end;  Rect.Left := ImgRect.Right;
      MemoRect := Rect;
      MemoRect.Top := (Rect.Top + Rect.Bottom) div 2;
      Rect.Bottom := MemoRect.Top;
      S := friendListBox.Items[Index];  iPos := Pos(#9, S);
      Memo := Copy(S, iPos + 1, Length(S)); //提取备注
      S := Copy(S, 1, iPos - 1); //提取名称
      Cnvs.Font.Assign(friendListBox.Font);
      Inc(Rect.Left, 10); ////+++在画S之前加,具体多少根据你自己的需要
      DrawText(Cnvs.Handle, PChar(S), -1,
        Rect, DT_SingleLine or DT_VCENTER); //垂直、水平居中 画名字  Cnvs.Font.Color := clGrayText;
      Inc(MemoRect.Left, 10); ////+++在画Memo之前加,具体多少根据你自己的需要
      DrawText(Cnvs.Handle, PChar(Memo), -1,
        MemoRect, DT_SingleLine or DT_VCENTER); //垂直、水平居中 画名字
    end
      

  4.   

    注意GetDrawImageIndex的Index值到底是什么,要根据你的ImageList的内容和你程序要求来定,我不知道。只是告诉你方法,只是!
      

  5.   

    那我明白,是不是当我想要更新的时候ListBox.Repaint重绘之后,他自己就调用FriendListBoxDrawItem的函数了,也是说我就不用管他的图标问题了?