Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.04.11;
Скачать: CL | DM;

Вниз

Помогите с ListView!!!!   Найти похожие ветки 

 
Dimaxx ©   (2003-07-26 23:45) [0]

Братцы!!! Поможите хто может! Нужно получить OwnerDraw-файловую панель как в Windows Commander!!! Пробовал с OnLVCustomDraw, но там еще нужно самому отрисовывать заголовок. Потом при отрисовке элементов (если пользователь меняет размер колонки) тект "мажется". Вобщем, ерунда получается. Помогите!!


 
SPeller ©   (2003-07-27 03:25) [1]

Total Commander использует не ListView, а ListBox. Посмотри класс окна этих панелей - TMyListBox. А отрисовать листбокс с колонками - проще простого. Тем более, что заголовки у него тоже самодельные используются. При таком раскладе всё получается просто, я даже сам делал такой же листбокс. :)


 
SPeller ©   (2003-07-27 03:31) [2]

Вот пример:

function TfrmMain.ListBoxMeasureItem(Sender: PObj; Idx: Integer): Integer;
var TCwnd, LBwnd: Cardinal;
begin
{  LBwnd := FindWindowEx( TCWindow, 0, "TMyListBox", nil );
 if LBwnd <> 0 then
   Result := SendMessage( LBwnd, LB_GETITEMHEIGHT, 0, 0 )
 else}
   Result := 16;
   LBItemHeight := Result;
end;


function TfrmMain.ListBoxDrawItem(Sender: PObj; DC: HDC; const Rect: TRect;
 ItemIdx: Integer; DrawAction: TDrawAction; ItemState: TDrawState): Boolean;

var R: TRect;
   TxtColor, BkColor, BorderColor: Cardinal;
   hBr, oldBr, hPen, oldPen, oldBm, tmBmp, tmDC, fnt, oldfnt: Cardinal;
   lf: tagLOGFONT;
   iName, iType, iSize, tm: string;
   i, SelCount: Cardinal;
   hIcon, IconDC, oldIconObj: Cardinal;
   LeftMargin: Integer;
   IID: Byte; i_Type: TItemType;
begin
 Result := True;
 R := Rect;
 tmDC := CreateCompatibleDC( DC );
 tmBmp := CreateCompatibleBitmap( DC, R.Right - R.Left, R.Bottom - R.Top );
 oldBM := SelectObject( tmDC, tmBmp );
 iName := CurList.Items[ ItemIdx ];
 if iName = "" then iName := "(Default)";
 iType := ItemType2String[ CurList.Data[ ItemIdx ] ];
 i_Type := CurList.Data[ ItemIdx ];
 if ( i_Type = itString ) or ( i_Type = itDWord ) or ( i_Type = itBinary ) then begin
   Reg.RootKey := CurList.Root;
   Reg.OpenKey( DelFirstFolder( CurList.Path ), False );
   iSize := Int2Str( Reg.GetDataSize( CurList.Items[ ItemIdx ] ) );
   Reg.CloseKey;
 end;

 BkColor := BackColor;
 BorderColor := BkColor;
 TxtColor := ForeColor;

 if {odsFocused}odsSelected in ItemState then begin
     BorderColor := CursorColor;
     if InverseCursor then begin
         BkColor := CursorColor;
         TxtColor := CursorText;
     end else begin
           BkColor := BackColor;
           txtColor := ForeColor;
     end;
{  end else begin
     if odsSelected in ItemState then
         TxtColor := MarkColor;}
 end;

 FillChar( lf, SizeOf( lf ), 0 );
 lf.lfHeight := FontSize;
 lf.lfWeight := FontWeight;
 lf.lfCharSet := DEFAULT_CHARSET;
 Move( FontName[ 1 ], lf.lfFaceName, Length( FontName ) );
 fnt := CreateFontIndirect( lf );
 oldFnt := SelectObject( tmDC, fnt );

 hBr := CreateSolidBrush( BkColor );
 oldBr := SelectObject( tmDC, hBr );

 hPen := CreatePen( PS_SOLID, 1, BorderColor );
 oldPen := SelectObject( tmDC, hPen );

 SetTextColor( tmDC, TxtColor );
 SetBkColor( tmDC, BkColor );

 Rectangle( tmDC, 0, 0, R.Right - R.Left, R.Bottom - R.Top );
 LeftMargin := 16;
 R.Right := R.Right - R.Left;
 R.Bottom := R.Bottom - R.Top;
 R.Top := 0;
 R.Left := 3 + LeftMargin;
 DrawText( tmDC, PChar( iName ), Length( iName ), R, DT_LEFT or DT_VCENTER or DT_SINGLELINE );
 if ( i_Type = itString ) or ( i_Type = itDWord ) or ( i_Type = itBinary ) then begin
   R.Left := FirstTab;
   DrawText( tmDC, PChar( iType ), Length( iType ), R, DT_LEFT or DT_VCENTER or DT_SINGLELINE );
   R.Right := ThirdTab;
   DrawText( tmDC, PChar( iSize ), Length( iSize ), R, DT_RIGHT or DT_VCENTER or DT_SINGLELINE );
 end else begin
   R.Left := SecondTab;
   DrawText( tmDC, PChar( iType ), Length( iType ), R, DT_LEFT or DT_VCENTER or DT_SINGLELINE );
 end;
 IID := 0;
 case i_Type of
   itFolder, itHKCU, itHKCR, itHKLM, itHKDD, itHKPD, itHKCC, itHKU: IID := I_FOLDER;
   itDWord, itString, itBinary: IID := I_PARAM;
   itBack: IID := I_UP;
 end;
 hIcon := LoadIconFromTC( {ItemIdx + 1}IID );
 if hIcon <> 0 then DrawIconEx( tmDC, 0, 0, hIcon, 16, 16, 0, 0, DI_NORMAL );

 BitBlt( DC, Rect.Left, Rect.Top, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top, tmDC, 0, 0, SRCCOPY );

 SelectObject( tmDC, oldBm );
 SelectObject( tmDC, oldFnt );
 SelectObject( tmDC, oldPen );
 SelectObject( tmDC, oldBr );
 DeleteDC( tmDC );
{  DeleteDC( IconDC );}
//  DeleteObject( hIcon );
 DeleteObject( tmBmp );
 DeleteObject( fnt );
 DeleteObject( hPen );
 DeleteObject( hBr );

 ListBox.ItemData[ ItemIdx ] := PInteger( @ItemState )^;
end;


Возможно, кривовато, но отрисовывало хорошо.


 
Dimaxx ©   (2003-07-28 01:14) [3]

Огромное спасибо, SPeller! Буду мучить код. Кстати, у версии TotalCommander 5.5 уже класс TMyPanel, а не TMyListBox.


 
SPeller ©   (2003-07-28 12:14) [4]

Это где? Я плагин этот под 5.5 писал! Это надписи разные, или ещё чего-нить там - ради бога, пускай TMyPanel, а вот список файлов - TMyListBox, и таким и останется.


 
Dimaxx ©   (2003-07-28 23:21) [5]

Не, я ничего против не имею, просто он обозвал, наверное, этот класс TMyPanel. ;-)


 
mdw ©   (2003-07-29 11:01) [6]

Короче, там есть и TMyListBox - это список к файлов, это то о чем и речь идет. И есть TMyPanel - их там до фига.


 
Dimaxx ©   (2003-07-30 23:35) [7]

Вроде не тупой, а не понимаю до конца. Прошу разъяснить описания состояний TDrawState. Хотя бы кратко - что для чего возникает.



Страницы: 1 вся ветка

Текущий архив: 2004.04.11;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.032 c
1-1082643041
hawkins
2004-04-22 18:10
2004.04.11
Подскажите, как у ListBox узнать ширину рамки?


4-1078858366
TankMan
2004-03-09 21:52
2004.04.11
Как закрасить MainMenu?


1-1080135232
-Sergey-
2004-03-24 16:33
2004.04.11
PowerPoint в OleContainer. Как показать не первый слайд?


1-1082562776
Insert
2004-04-21 19:52
2004.04.11
Запуск readme


1-1082381323
Феликс М.
2004-04-19 17:28
2004.04.11
Печать как из Ворда