1.h
1 #pragmaOnce2 3 4 //Cmylistctrl5 6 classCmylistctrl: PublicCListCtrl7 {8 declare_dynamic (Cmylistctrl)9 Ten Public: One Cmylistctrl (); A Virtual~Cmylistctrl (); - -CString GetItemText (intNitem,intNsubitem)Const; the voidDrawItem (lpdrawitemstruct lpdrawitemstruct); - - protected: - Declare_message_map () +};
2.cpp
1 //MyListCtrl.cpp: Implementing Files2 //3 4#include"stdafx.h"5#include"YdTool.h"6#include"MyListCtrl.h"7 8 #ifdef _afx9 #ifdef _DEBUGTen #defineNew Debug_new One #undefThis_file A Static Const CharThis_file[] =__file__; - #endif - #endif the - //Cmylistctrl - - implement_dynamic (Cmylistctrl, CListCtrl) + - Cmylistctrl::cmylistctrl () + { A at } - -cmylistctrl::~Cmylistctrl () - { - } - in - Begin_message_map (Cmylistctrl, CListCtrl) to End_message_map () + - the * //Cmylistctrl message handlers $ Panax Notoginseng -CString Cmylistctrl::getitemtext (intNitem,intNsubitem)Const the { + ASSERT (:: IsWindow (M_hwnd)); A Lvitem LVI; thememset (&lvi,0,sizeof(Lvitem)); +Lvi.isubitem =Nsubitem; - CString str; $ intNlen =640; $ intnres; - Do - { theNlen *=2; -Lvi.cchtextmax =Nlen;WuyiLvi.psztext =Str. GetBufferSetLength (Nlen); theNres = (int):: SendMessage (M_hwnd, Lvm_getitemtext, (WPARAM) Nitem, -(LPARAM) &LVI); Wu} while(Nres >= nlen-1); - Str. ReleaseBuffer (); About returnstr; $ } - - voidCmylistctrl::D rawitem (lpdrawitemstruct lpdrawitemstruct) - { Acdc* PDC = Cdc::fromhandle (lpdrawitemstruct->HDC); +CRect RcItem (lpdrawitemstruct->rcItem); the intNitem = lpdrawitemstruct->ItemID; - colorref Clrtextsave, Clrbksave; $ Static_tchar szbuff[50000];//here is the length of the string you want to display, how long you want it to be the Lv_item LVI; theLvi.mask = Lvif_text | Lvif_state;//Lvif_image | theLvi.iitem =Nitem; theLvi.isubitem =0; -Lvi.psztext =Szbuff; inLvi.cchtextmax =sizeof(szbuff); theLvi.statemask =0xFFFF; theGetItem (&LVI); About theBOOL bselected = (Lvi.state &lvis_selected); the CRect rcalllabels; the GetItemRect (Nitem, Rcalllabels, lvir_bounds); + if(bselected) - { theClrtextsave = pdc->SetTextColor (:: GetSysColor (Color_highlighttext));BayiClrbksave = pdc->SetBkColor (:: GetSysColor (Color_highlight)); thePdc->fillrect (Rcalllabels, &CBrush (:: GetSysColor (Color_highlight))); the } - GetItemRect (Nitem, RcItem, Lvir_label); -Pdc->drawtext (Szbuff,-1, RcItem, Dt_left | Dt_singleline | Dt_noprefix | Dt_noclip |dt_vcenter); the the Lv_column LVC; theLvc.mask = Lvcf_fmt |Lvcf_width; the for(intNcolumn =1; GetColumn (Ncolumn, &LVC); ncolumn++) - { theRcitem.left =Rcitem.right; theRcitem.right + =lvc.cx; the 94 intNretlen =Clistctrl::getitemtext (Nitem, Ncolumn, theSzbuff,sizeof(Szbuff)); the if(Nretlen = =0) the Continue;98UINT njustify =Dt_left; About Switch(Lvc.fmt &lvcfmt_justifymask) - {101 CaseLvcfmt_right:102Njustify =Dt_right;103 Break;104 CaseLvcfmt_center: theNjustify =Dt_center;106 Break;107 default:108 Break;109}//when stepping, the string with a length of 30000 bytes inside the szbuff is correct, but after execution the output is found to be blank thePdc->drawtext (Szbuff,-1, RcItem,111njustify | Dt_singleline | Dt_noprefix | Dt_noclip |dt_vcenter); the }113 if(Lvi.state &lvis_focused) thePdc->DrawFocusRect (rcalllabels); the if(bselected) the {117Pdc->SetTextColor (clrtextsave);118Pdc->SetBkColor (clrbksave);119 } -}
Vcclistctrl displaying long string custom classes