Delphi的代码帮忙翻译成BCB的吧,实在看不动!
好郁闷!
原文地址:
http://www.cnblogs.com/huangjacky/archive/2009/12/08/1619791.html
Delphi - 在ListView中添加一个进度条
看CxGrid资料的时候,看见了一个为兄弟的文章,我就转一下了.
--------------------------------------------
//需要Use CommCtrl
Function GetSubItemRect( handle, ItemsIndex, SubIndex: Integer ): TRect ;
Begin
ListView_GetSubItemRect( Handle, ItemsIndex, SubIndex, 0, @Result ) ;
End ;
Procedure TFormMain.lvw_listCustomDrawSubItem( Sender: TCustomListView ;
Item: TListItem ;SubItem: Integer ;State: TCustomDrawState ;
Var DefaultDraw: Boolean ) ;
Var
l_Rect: TRect ;
l_intPercent: Integer ;
Begin
If SubItem = 3 Then
Begin
If Item.Data = Nil Then
Exit ;
l_intPercent := PListData( Item.Data ).Percent ;
//获取ListView子项的Rect
l_Rect := GetSubItemRect( Item.Handle, Item.Index, SubItem ) ;
//画一条外边框
InflateRect( l_Rect, -1, -1 ) ;
Sender.Canvas.Brush.Color := clBlack ;
Sender.Canvas.FrameRect( l_Rect ) ;
//先填充底色
InflateRect( l_Rect, -1, -1 ) ;
Sender.Canvas.Brush.Color := lvw_list.Color ;
Sender.Canvas.FillRect( l_Rect ) ;
//再根据进度画出完成区域
If l_intPercent = 100 Then
Sender.Canvas.Brush.Color := clGreen
Else
Sender.Canvas.Brush.Color := clPurple ;
l_Rect.Right := l_Rect.Left + Floor( ( l_Rect.Right - l_Rect.Left ) * l_intPercent / 100 ) ;
Sender.Canvas.FillRect( l_Rect ) ;
//恢复笔刷
Sender.Canvas.Brush.Color := lvw_list.Color ;
//关键的一句,屏蔽系统自绘过程
DefaultDraw := False ;
End ;
End ;
相关定义
Type
TListData = Record
FileName: String ;
Percent: Integer ;
End ;
PListData = ^TListData ;
[解决办法]
BCB 2010下测试过了..
Unit1.h的内容:
//---------------------------------------#ifndef Unit1H#define Unit1H//---------------------------------------#include <Classes.hpp>#include <Controls.hpp>#include <StdCtrls.hpp>#include <Forms.hpp>#include <CommCtrl.h>#include <ComCtrls.hpp>//---------------------------------------class TForm1 : public TForm{__published: // IDE-managed Components TListView *lv; TButton *Button1; void __fastcall lvCustomDrawSubItem(TCustomListView *Sender, TListItem *Item, int SubItem, TCustomDrawState State, bool &DefaultDraw); void __fastcall Button1Click(TObject *Sender);private: // User declarationspublic: // User declarations __fastcall TForm1(TComponent* Owner);};//---------------------------------------extern PACKAGE TForm1 *Form1;//---------------------------------------#endifstruct TListData{ String FileName; int Percent;};TRect GetSubItemRect(HWND__ * handle,int ItemsIndex,int SubIndex);
[解决办法]
其实我喜欢这么用:
Unit1.h
struct TListData{ String FileName; int Percent; TProgressBar *pb;};TRect GetSubItemRect(HWND__ * handle,int ItemsIndex,int SubIndex);
[解决办法]
按我12楼说的
把HWND__* handle 改成HWND handle后
这段在CB6.0 CB2007 和2010 都是通用的