listcttrlまとめ2
20.listcttrlのsubitem追加アイコン
m_list.SetExtendedStyle(LVS_EX_SUBITEMIMAGES); m_list.SetItem(..);//具体的なパラメータはmsdnを参照してください
21.CListCtrlにファイルを表示し、ファイルの種類に応じてアイコンを表示する
ネット上で見つけたコードは、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.listcttrlコンテンツがビッグデータ量更新を行う場合、点滅を避ける
m_list.SetRedraw(FALSE);//更新内容m_list.SetRedraw(TRUE); m_list.Invalidate(); m_list.UpdateWindow();または参照
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwnd.3a3a.setredraw.asp
23.listcttrlソート
Q250614:How To Sort Items in a CListCtrl in Report View http://support.microsoft.com/kb/250614/en-us
24.listcttrlでitemを選択したときにiconまたはbitmapを動的に変更
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.itemを追加した後、InsertColumn()を追加すると、カラム全体が移動する問題
Q151897: CListCtrl::InsertColumn() Causes Column Data to Shift http://support.microsoft.com/kb/151897/en-us
26.listcttrlの最初の列が常に左にある問題について
解決策:第1列を虚列とし、第2列から列とデータを挿入し、最後に第1列を削除します.具体的な説明はhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listview/structures/lvcolumn.asp
27.column headerのドラッグをロックする
http://msdn.microsoft.com/msdnmag/issues/03/06/CQA/
28.clistctrlの列を非表示にする方法
非表示にする列の幅を0にし、その列が非表示になったときに、上の27点目のロックcolumnのドラッグで実現することを検出します.
29.listctcttrlビッグデータ量操作を行う場合は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.itemが259文字しか表示できない問題について
解決策:itemにeditを置く必要があります.
31.listcttrlのcolumn headerのマウスの右クリックに応答する
Q125694: How To Find Out Which Listview Column Was Right-Clicked http://support.microsoft.com/kb/125694/en-us
32.Windowsエクスプローラに似た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.ListCtrlにおいてOnTimerが2回のみ応答する問題
Q200054:PRB: OnTimer() Is Not Called Repeatedly for a List Control http://support.microsoft.com/kb/200054/en-us
34.以下に、様々なカスタム機能を実現するためのlistcttrl派生クラスを示す.
(1)ドラッグ&ドロップhttp://www.codeproject.com/listctrl/dragtest.asp
CListCtrlとCTreeCtrlの間でドラッグ&ドロップhttp://support.microsoft.com/kb/148738/en-us(2)多機能listcttrlはsubitem編集可能、アイコン、radiobutton、checkbox、文字列変更色のクラスhttp://www.codeproject.com/listctrl/quicklist.aspソート対応、subitem編集可能、subitemアイコン、subitem変更色のクラスhttp://www.codeproject.com/listctrl/ReportControl.asp
(3)subitemにハイパーリンク表示http://www.codeproject.com/listctrl/CListCtrlLink.asp
(4)subitemのtooltipヒントhttp://www.codeproject.com/listctrl/ctooltiplistctrl.asp
(5)subitemに進捗バーが表示されるhttp://www.codeproject.com/listctrl/ProgressListControl.asphttp://www.codeproject.com/listctrl/napster.asphttp://www.codeguru.com/Cpp/controls/listview/article.php/c4187/
(6)subitemの色と背景色を動的に変えるhttp://www.codeproject.com/listctrl/highlightlistctrl.asphttp://www.codeguru.com/Cpp/controls/listbox/colorlistboxes/article.php/c4757/(7)クラスvbプロパティダイアログhttp://www.codeproject.com/listctrl/propertylistctrl.asphttp://www.codeguru.com/Cpp/controls/listview/propertylists/article.php/c995/http://www.codeguru.com/Cpp/controls/listview/propertylists/article.php/c1041/(8)subitem(ハイライトされたitemのみ)を選択http://www.codeproject.com/listctrl/SubItemSel.asphttp://www.codeproject.com/listctrl/ListSubItSel.asp(9)行高変更http://www.codeproject.com/listctrl/changerowheight.asp(10)行色変更http://www.codeproject.com/listctrl/coloredlistctrl.asp(11)編集可能subitemのlistcttrlhttp://www.codeproject.com/listctrl/nirs2000.asphttp://www.codeproject.com/listctrl/editing_subitems_in_listcontrol.asp(12)subitem編集可能、combobox挿入、行色変更、subitemのtooltipプロンプトhttp://www.codeproject.com/listctrl/reusablelistcontrol.asp(13)ヘッダで複数行文字列許可http://www.codeproject.com/listctrl/headerctrlex.asp(14)combox挿入http://www.codeguru.com/Cpp/controls/listview/editingitemsandsubitem/article.php/c979/(15)背景画像を追加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)適応幅のlistcttrlhttp://www.codeproject.com/useritems/AutosizeListCtrl.asp
(17)ListCtrlハイライト時の色変更(デフォルトは青)処理
m_list.SetExtendedStyle(LVS_EX_SUBITEMIMAGES); m_list.SetItem(..);//具体的なパラメータはmsdnを参照してください
21.CListCtrlにファイルを表示し、ファイルの種類に応じてアイコンを表示する
ネット上で見つけたコードは、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.listcttrlコンテンツがビッグデータ量更新を行う場合、点滅を避ける
m_list.SetRedraw(FALSE);//更新内容m_list.SetRedraw(TRUE); m_list.Invalidate(); m_list.UpdateWindow();または参照
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwnd.3a3a.setredraw.asp
23.listcttrlソート
Q250614:How To Sort Items in a CListCtrl in Report View http://support.microsoft.com/kb/250614/en-us
24.listcttrlでitemを選択したときにiconまたはbitmapを動的に変更
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.itemを追加した後、InsertColumn()を追加すると、カラム全体が移動する問題
Q151897: CListCtrl::InsertColumn() Causes Column Data to Shift http://support.microsoft.com/kb/151897/en-us
26.listcttrlの最初の列が常に左にある問題について
解決策:第1列を虚列とし、第2列から列とデータを挿入し、最後に第1列を削除します.具体的な説明はhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listview/structures/lvcolumn.asp
27.column headerのドラッグをロックする
http://msdn.microsoft.com/msdnmag/issues/03/06/CQA/
28.clistctrlの列を非表示にする方法
非表示にする列の幅を0にし、その列が非表示になったときに、上の27点目のロックcolumnのドラッグで実現することを検出します.
29.listctcttrlビッグデータ量操作を行う場合は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.itemが259文字しか表示できない問題について
解決策:itemにeditを置く必要があります.
31.listcttrlのcolumn headerのマウスの右クリックに応答する
Q125694: How To Find Out Which Listview Column Was Right-Clicked http://support.microsoft.com/kb/125694/en-us
32.Windowsエクスプローラに似た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.ListCtrlにおいてOnTimerが2回のみ応答する問題
Q200054:PRB: OnTimer() Is Not Called Repeatedly for a List Control http://support.microsoft.com/kb/200054/en-us
34.以下に、様々なカスタム機能を実現するためのlistcttrl派生クラスを示す.
(1)ドラッグ&ドロップhttp://www.codeproject.com/listctrl/dragtest.asp
CListCtrlとCTreeCtrlの間でドラッグ&ドロップhttp://support.microsoft.com/kb/148738/en-us(2)多機能listcttrlはsubitem編集可能、アイコン、radiobutton、checkbox、文字列変更色のクラスhttp://www.codeproject.com/listctrl/quicklist.aspソート対応、subitem編集可能、subitemアイコン、subitem変更色のクラスhttp://www.codeproject.com/listctrl/ReportControl.asp
(3)subitemにハイパーリンク表示http://www.codeproject.com/listctrl/CListCtrlLink.asp
(4)subitemのtooltipヒントhttp://www.codeproject.com/listctrl/ctooltiplistctrl.asp
(5)subitemに進捗バーが表示されるhttp://www.codeproject.com/listctrl/ProgressListControl.asphttp://www.codeproject.com/listctrl/napster.asphttp://www.codeguru.com/Cpp/controls/listview/article.php/c4187/
(6)subitemの色と背景色を動的に変えるhttp://www.codeproject.com/listctrl/highlightlistctrl.asphttp://www.codeguru.com/Cpp/controls/listbox/colorlistboxes/article.php/c4757/(7)クラスvbプロパティダイアログhttp://www.codeproject.com/listctrl/propertylistctrl.asphttp://www.codeguru.com/Cpp/controls/listview/propertylists/article.php/c995/http://www.codeguru.com/Cpp/controls/listview/propertylists/article.php/c1041/(8)subitem(ハイライトされたitemのみ)を選択http://www.codeproject.com/listctrl/SubItemSel.asphttp://www.codeproject.com/listctrl/ListSubItSel.asp(9)行高変更http://www.codeproject.com/listctrl/changerowheight.asp(10)行色変更http://www.codeproject.com/listctrl/coloredlistctrl.asp(11)編集可能subitemのlistcttrlhttp://www.codeproject.com/listctrl/nirs2000.asphttp://www.codeproject.com/listctrl/editing_subitems_in_listcontrol.asp(12)subitem編集可能、combobox挿入、行色変更、subitemのtooltipプロンプトhttp://www.codeproject.com/listctrl/reusablelistcontrol.asp(13)ヘッダで複数行文字列許可http://www.codeproject.com/listctrl/headerctrlex.asp(14)combox挿入http://www.codeguru.com/Cpp/controls/listview/editingitemsandsubitem/article.php/c979/(15)背景画像を追加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)適応幅のlistcttrlhttp://www.codeproject.com/useritems/AutosizeListCtrl.asp
(17)ListCtrlハイライト時の色変更(デフォルトは青)処理
NM_CUSTOMDRAW
http://www.codeproject.com/listctrl/lvcustomdraw.asp
(18) header
http://www.pocketpcdn.com/articles/hdr_color.html