Clistctrl tips (2)

Source: Internet
Author: User

21. display the file in clistctrl and display the icon according to the file type.

Code found online, share

Bool ctest6dlg: oninitdialog ()

{

Cdialog: oninitdialog ();



Himagelist himlsmall;

Himagelist himllarge;

Shfileinfo SFI;

Char csysdir [max_path];

Cstring strbuf;



Memset (csysdir, 0, max_path );



Getwindowsdirectory (csysdir, max_path );

Strbuf = csysdir;

Sprintf (csysdir, "% s", strbuf. Left (strbuf. Find ("\") + 1 ));



Himlsmall = (himagelist) shgetfileinfo (lpcstr) csysdir,

0,

& SFI,

Sizeof (shfileinfo ),

Shgfi_sysiconindex | shgfi_smallicon );



Himllarge = (himagelist) shgetfileinfo (lpcstr) csysdir,

0,

& SFI,

Sizeof (shfileinfo ),

Shgfi_sysiconindex | shgfi_largeicon );



If (himlsmall & himllarge)

{

: Sendmessage (m_list.m_hwnd, lvm_setimagelist,

(Wparam) lvsil_small, (lparam) himlsmall );

: Sendmessage (m_list.m_hwnd, lvm_setimagelist,

(Wparam) lvsil_normal, (lparam) himllarge );

}

Return true; // return true unless you set the focus to a control

}



Void ctest6dlg: addfiles (lpctstr lpszfilename, bool baddtodocument)

{

Int nicon = geticonindex (lpszfilename, false, false );

Cstring strsize;

Cfilefind FileFind;



// Get File Size

If (FileFind. findfile (lpszfilename ))

{

FileFind. findnextfile ();

Strsize. Format ("% d", FileFind. getlength ());

}

Else

Strsize = "0 ";



// Split path and filename

Cstring strfilename = lpszfilename;

Cstring strpath;



Int NPOs = strfilename. reversefind ('\\');

If (NPOs! =-1)

{

Strpath = strfilename. Left (NPOs );

Strfilename = strfilename. mid (NPOs + 1 );

}



// Insert to list

Int nitem = m_list.getitemcount ();

M_list.insertitem (nitem, strfilename, nicon );

M_list.setitemtext (nitem, 1, strsize );

M_list.setitemtext (nitem, 2, strfilename. Right (3 ));

M_list.setitemtext (nitem, 3, strpath );

}



Int ctest6dlg: geticonindex (lpctstr lpszpath, bool bisdir, bool bselected)

{

Shfileinfo SFI;

Memset (& SFI, 0, sizeof (SFI ));



If (bisdir)

{

Shgetfileinfo (lpszpath,

File_attribute_directory,

& SFI,

Sizeof (SFI ),

Shgfi_smallicon | shgfi_sysiconindex |

Shgfi_usefileattributes | (bselected? Shgfi_openicon: 0 ));

Return SFI. iicon;

}

Else

{

Shgetfileinfo (lpszpath,

File_attribute_normal,

& SFI,

Sizeof (SFI ),

Shgfi_smallicon | shgfi_sysiconindex |

Shgfi_usefileattributes | (bselected? Shgfi_openicon: 0 ));

Return SFI. iicon;

}

Return-1;

}

22. When the listctrl content is updated with a large amount of data, avoid blinking

M_list.setredraw (false );

// Update content

M_list.setredraw (true );

M_list.invalidate ();

M_list.updatewindow ();



Or refer

Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/vclib/html/_ mfc_cwnd.3a3a.setredraw.asp

23. sort by listctrl

Q250614: how to sort items in a clistctrl in report View
Http://support.microsoft.com/kb/250614/en-us

24. When an item is selected in listctrl, its icon or bitmap is dynamically changed.

Q141834: how to change the icon or the bitmap of A clistctrl item in Visual C ++
Http://support.microsoft.com/kb/141834/en-us

25. After the item is added and insertcolumn () is added, the entire column data is moved.

Q151897: clistctrl: insertcolumn () causes column data to shift
Http://support.microsoft.com/kb/151897/en-us

26. The problem that the first column of listctrl is always left

Solution: Use the first column as a virtual column, insert the column and data from the second column, and delete the first column.



For more information, see http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/shellcc/platform/commctls/listview/structures/lvcolumn. asp

27. Drag the column header to lock

Http://msdn.microsoft.com/msdnmag/issues/03/06/CQA/

28. How to hide the clistctrl Column

Set the width of the column to be hidden to 0, and then detect that when the column is hidden, use the drag of the lock column at the above 27th points to achieve

29. When using listctrl to perform operations on large data volumes, use virtual list

Http://www.microsoft.com/msj/archive/S2061.aspx
Http://www.codeguru.com/cpp/controls/listview/advanced/article.php/c4151/
Http://www.codeproject.com/listctrl/virtuallist.asp

30. Question about the display of item only 259 characters

Solution: put an edit on the item.

31. Right-click the response column header in listctrl

Q125694: how to find out which listview column was right-clicked
Http://support.microsoft.com/kb/125694/en-us

32. Similar to the Windows Resource Manager listview

Q234310: how to implement a listview control that is similar to Windows Explorer by using dirlv.exe
Http://support.microsoft.com/kb/234310/en-us

33. In listctrl, ontimer only responds to the problem twice.

Q200054:

PRB: ontimer () is not called repeatedly for a list control
Http://support.microsoft.com/kb/200054/en-us

34. The following are some listctrl Derived classes that implement various custom functions.

(1) drag and drop

Http://www.codeproject.com/listctrl/dragtest.asp

Drag and Drop between clistctrl and ctreectrl

Http://support.microsoft.com/kb/148738/en-us



(2) Multi-Function listctrl

Supports subitem editable, icons, radiobutton, checkbox, and character string color changing classes.

Http://www.codeproject.com/listctrl/quicklist.asp



Supports sorting, subitem editable, subitem icon, and subitem color changing classes

Http://www.codeproject.com/listctrl/ReportControl.asp

(3) display hyperlinks in Subitem

Http://www.codeproject.com/listctrl/CListCtrlLink.asp

(4) tooltip prompt for Subitem

Http://www.codeproject.com/listctrl/ctooltiplistctrl.asp

(5) display the progress bar in Subitem

Http://www.codeproject.com/listctrl/ProgressListControl.asp

Http://www.codeproject.com/listctrl/napster.asp

Http://www.codeguru.com/Cpp/controls/listview/article.php/c4187/

(6) dynamically change the color and background color of subitem

Http://www.codeproject.com/listctrl/highlightlistctrl.asp

Http://www.codeguru.com/Cpp/controls/listbox/colorlistboxes/article.php/c4757/


(7) VB Properties dialog box

Http://www.codeproject.com/listctrl/propertylistctrl.asp

Http://www.codeguru.com/Cpp/controls/listview/propertylists/article.php/c995/

Http://www.codeguru.com/Cpp/controls/listview/propertylists/article.php/c1041/



(8) Select Subitem (only highlight the selected item)

Http://www.codeproject.com/listctrl/SubItemSel.asp

Http://www.codeproject.com/listctrl/ListSubItSel.asp



(9) change the Row Height

Http://www.codeproject.com/listctrl/changerowheight.asp



(10) change the row color.

Http://www.codeproject.com/listctrl/coloredlistctrl.asp



(11) editable subitem listctrl

Http://www.codeproject.com/listctrl/nirs2000.asp

Http://www.codeproject.com/listctrl/editing_subitems_in_listcontrol.asp



(12) the subitem can be edited, The ComboBox is inserted, the row color is changed, and the tooltip of the subitem is prompted.

Http://www.codeproject.com/listctrl/reusablelistcontrol.asp



(13) Many line strings are allowed in the header

Http://www.codeproject.com/listctrl/headerctrlex.asp



(14) insert ComboBox

Http://www.codeguru.com/Cpp/controls/listview/editingitemsandsubitem/article.php/c979/



(15) Add a background image

Http://www.codeguru.com/Cpp/controls/listview/backgroundcolorandimage/article.php/c4173/

Http://www.codeguru.com/Cpp/controls/listview/backgroundcolorandimage/article.php/c983/

Http://www.vchelp.net/vchelp/archive.asp? Type_id = 9 & class_id = 1 & cata_id = 1 & article_id = 1088 & search_term =



(16) listctrl

Http://www.codeproject.com/useritems/AutosizeListCtrl.asp

(17) change the highlighted color of listctrl (Blue by default)

Processing NM_CUSTOMDRAW 

           http://www.codeproject.com/listctrl/lvcustomdraw.asp

(18) change the header color

Http://www.pocketpcdn.com/articles/hdr_color.html


Http://www.bc-cn.net/Article/kfyy/vc/jszl/200607/4212.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.