In my VC MFC develop expericence, I always find that it is really poor of the Ctrls that microsoft provided, but we have no much project budget to bug a beautiful third-ctrl. So sometimes we need do some work to modify the standard Control. For the purpose of reuse, I have my library database, though lots of them come from internet, and I just did little work. but I still very pleasure to share with your guys.
Click here to download.
?
At first, I want introduce XListCtrl to you.
This control was developed by Hans Dietrich , you can click here to view his web page. You can find this beautiful and powerful feature list, before that, let's have a look this beautiful picture:
At first, Let me show picture.
Keep all features from hans' xlistctrl.
1, Modify the edit feature, add OK, Cancel button, It will be more friendly to user.
2, Add change the font's style: italic
How to Use:
??? ON_REGISTERED_MESSAGE(WM_XLISTCTRL_EDIT_BTNOK_CLICKED,?OnRenameClicked)
????ON_REGISTERED_MESSAGE(WM_XLISTCTRL_EDIT_BTNEDIT_CLICKED,?OnRenameEditClicked)
??? ON_REGISTERED_MESSAGE(WM_XLISTCTRL_HEADER_CHECKBOX_CLICKED, OnHeaderChecked)
Implement these message function.
That' OK.
?
At first, I want introduce XListCtrl to you.
This control was developed by Hans Dietrich , you can click here to view his web page. You can find this beautiful and powerful feature list, before that, let's have a look this beautiful picture:
- First column is specified with checkboxes
- The second column shows subitem with bold text
- The second column shows subitem with different background color
- The third column contains progress bar in row 2
- The fourth column also contains checkboxes
- The fifth column shows subitem with different background color
- The sixth column shows subitem with different text and background colors
- The second column shows combobox
- The sixth row is disabled
- The fifth column shows edit control
At first, Let me show picture.
Keep all features from hans' xlistctrl.
1, Modify the edit feature, add OK, Cancel button, It will be more friendly to user.
2, Add change the font's style: italic
How to Use:
- Initial List:
<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->
CRect?rect;
????xlist.GetWindowRect( & rect);
???? int ?w? = ?rect.Width()? - ? 2 ;
???? int ?colwidths[ 6 ]? = ?{? 3 ,? 26 ,? 8 ,? 19 ,? 6 ,? 15 ?};???? // ?sixty-fourths
???? int ?cols? = ? 0 ;
????TCHAR? * ????lpszHeaders[]? = ?{?_T( "" ),
??????????????????????????????_T( " File?Name " ),
??????????????????????????????_T( " Speed(kb/s) " ),
??????????????????????????????_T( " Progress " ),
??????????????????????????????_T( " Time?Left " ),
??????????????????????????????NULL?};
???? int ?i;
???? int ?total_cx? = ? 0 ;
????LV_COLUMN?lvcolumn;
????memset( & lvcolumn,? 0 ,? sizeof (lvcolumn));
???? // ?add?columns
???? for ?(i? = ? 0 ;?;?i ++ )
????{
???????? if ?(lpszHeaders[i]? == ?NULL)
???????????? break ;
????????lvcolumn.mask? = ?LVCF_FMT? | ?LVCF_SUBITEM? | ?LVCF_TEXT? | ?LVCF_WIDTH;
????????lvcolumn.fmt? = ?(i? == ? 1 ? || ?i? == ? 5 )? ? ?LVCFMT_LEFT?:?LVCFMT_CENTER;
????????lvcolumn.pszText? = ?lpszHeaders[i];
????????lvcolumn.iSubItem? = ?i;
????????lvcolumn.cx? = ?(lpszHeaders[i + 1 ]? == ?NULL)? ? ?w? - ?total_cx? - ? 2 ?:?(w? * ?colwidths[i])? / ? 64 ;
????????total_cx? += ?lvcolumn.cx;
????????xlist.InsertColumn(i,? & lvcolumn);
????}
????cols? = ?i;? // total?columns
????
???? // ?iterate?through?header?items?and?attach?the?image?list
????HDITEM?hditem;
???? for ?(i? = ? 0 ;?i? < ?xlist.m_HeaderCtrl.GetItemCount();?i ++ )
????{
????????hditem.mask? = ?HDI_IMAGE? | ?HDI_FORMAT;
????????xlist.m_HeaderCtrl.GetItem(i,? & hditem);
????????hditem.fmt? |= ??HDF_IMAGE;
???????? if ?(i? == ? 0 )?
????????{
????????????hditem.iImage? = ?XHEADERCTRL_UNCHECKED_IMAGE;
????????????hditem.fmt? = ?HDF_CENTER;
????????}
???????? else
????????????hditem.iImage? = ?XHEADERCTRL_NO_IMAGE;
????????xlist.m_HeaderCtrl.SetItem(i,? & hditem);
????}
??? // add edit button picture
????HBITMAP?hBitmapOK? = ?LoadBitmap(AfxGetInstanceHandle(),??MAKEINTRESOURCE(IDB_EDIT_BTNOK));??
????HBITMAP?hBitmapCancel? = ?LoadBitmap(AfxGetInstanceHandle(),??MAKEINTRESOURCE(IDB_EDIT_BTNCANCEL));??
????m_xlist.SetEditBtnIcon(hBitmapOK,?hBitmapCancel);
????xlist.GetWindowRect( & rect);
???? int ?w? = ?rect.Width()? - ? 2 ;
???? int ?colwidths[ 6 ]? = ?{? 3 ,? 26 ,? 8 ,? 19 ,? 6 ,? 15 ?};???? // ?sixty-fourths
???? int ?cols? = ? 0 ;
????TCHAR? * ????lpszHeaders[]? = ?{?_T( "" ),
??????????????????????????????_T( " File?Name " ),
??????????????????????????????_T( " Speed(kb/s) " ),
??????????????????????????????_T( " Progress " ),
??????????????????????????????_T( " Time?Left " ),
??????????????????????????????NULL?};
???? int ?i;
???? int ?total_cx? = ? 0 ;
????LV_COLUMN?lvcolumn;
????memset( & lvcolumn,? 0 ,? sizeof (lvcolumn));
???? // ?add?columns
???? for ?(i? = ? 0 ;?;?i ++ )
????{
???????? if ?(lpszHeaders[i]? == ?NULL)
???????????? break ;
????????lvcolumn.mask? = ?LVCF_FMT? | ?LVCF_SUBITEM? | ?LVCF_TEXT? | ?LVCF_WIDTH;
????????lvcolumn.fmt? = ?(i? == ? 1 ? || ?i? == ? 5 )? ? ?LVCFMT_LEFT?:?LVCFMT_CENTER;
????????lvcolumn.pszText? = ?lpszHeaders[i];
????????lvcolumn.iSubItem? = ?i;
????????lvcolumn.cx? = ?(lpszHeaders[i + 1 ]? == ?NULL)? ? ?w? - ?total_cx? - ? 2 ?:?(w? * ?colwidths[i])? / ? 64 ;
????????total_cx? += ?lvcolumn.cx;
????????xlist.InsertColumn(i,? & lvcolumn);
????}
????cols? = ?i;? // total?columns
????
???? // ?iterate?through?header?items?and?attach?the?image?list
????HDITEM?hditem;
???? for ?(i? = ? 0 ;?i? < ?xlist.m_HeaderCtrl.GetItemCount();?i ++ )
????{
????????hditem.mask? = ?HDI_IMAGE? | ?HDI_FORMAT;
????????xlist.m_HeaderCtrl.GetItem(i,? & hditem);
????????hditem.fmt? |= ??HDF_IMAGE;
???????? if ?(i? == ? 0 )?
????????{
????????????hditem.iImage? = ?XHEADERCTRL_UNCHECKED_IMAGE;
????????????hditem.fmt? = ?HDF_CENTER;
????????}
???????? else
????????????hditem.iImage? = ?XHEADERCTRL_NO_IMAGE;
????????xlist.m_HeaderCtrl.SetItem(i,? & hditem);
????}
??? // add edit button picture
????HBITMAP?hBitmapOK? = ?LoadBitmap(AfxGetInstanceHandle(),??MAKEINTRESOURCE(IDB_EDIT_BTNOK));??
????HBITMAP?hBitmapCancel? = ?LoadBitmap(AfxGetInstanceHandle(),??MAKEINTRESOURCE(IDB_EDIT_BTNCANCEL));??
????m_xlist.SetEditBtnIcon(hBitmapOK,?hBitmapCancel);
- Add a new line:
<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->
??? ??? ??? LVITEM?itemData;
????????????itemData.iSubItem? = ? 0 ;
????????????itemData.iItem? = ? 0 ;
????????????itemData.mask? = ?LVIF_TEXT;
????????????itemData.pszText? = ?_T( "" );
????????????itemData.lParam? = ?(LPARAM)pJob;
????????????CString?szTmp;
????????????nItem? = ?m_xlist.InsertItem( & itemData);
????????????m_xlist.SetCheckbox(?nItem,? 0 ,?FALSE?);
????????????m_xlist.SetItemText(?nItem,? 1 ,?pJob -> m_szNewDocName.GetLength()? == ? 0 ? ? ?pJob -> m_szFileName?:?pJob -> m_szNewDocName);???????? // doc?name
????????????m_xlist.SetEditButton(?nItem,? 1 );
????????????m_xlist.SetItemText(?nItem,? 3 ,?_T( "" ));???????????????????? // progress?bar
????????????pJob -> GetLeftTimeString(szTmp);
????????????m_xlist.SetItemText(?nItem,? 4 ,?szTmp?);???????????????????? // time?left?estimate
????????????szTmp.Format(? " %.2lf " ,?pJob -> CountSpeed() / 1024 ?);?
????????????m_xlist.SetItemText(?nItem,? 2 ,?szTmp?);???????????????????? // transfer?speed?average
????????????itemData.iSubItem? = ? 0 ;
????????????itemData.iItem? = ? 0 ;
????????????itemData.mask? = ?LVIF_TEXT;
????????????itemData.pszText? = ?_T( "" );
????????????itemData.lParam? = ?(LPARAM)pJob;
????????????CString?szTmp;
????????????nItem? = ?m_xlist.InsertItem( & itemData);
????????????m_xlist.SetCheckbox(?nItem,? 0 ,?FALSE?);
????????????m_xlist.SetItemText(?nItem,? 1 ,?pJob -> m_szNewDocName.GetLength()? == ? 0 ? ? ?pJob -> m_szFileName?:?pJob -> m_szNewDocName);???????? // doc?name
????????????m_xlist.SetEditButton(?nItem,? 1 );
????????????m_xlist.SetItemText(?nItem,? 3 ,?_T( "" ));???????????????????? // progress?bar
????????????pJob -> GetLeftTimeString(szTmp);
????????????m_xlist.SetItemText(?nItem,? 4 ,?szTmp?);???????????????????? // time?left?estimate
????????????szTmp.Format(? " %.2lf " ,?pJob -> CountSpeed() / 1024 ?);?
????????????m_xlist.SetItemText(?nItem,? 2 ,?szTmp?);???????????????????? // transfer?speed?average
- Edit:
??? ON_REGISTERED_MESSAGE(WM_XLISTCTRL_EDIT_BTNOK_CLICKED,?OnRenameClicked)
????ON_REGISTERED_MESSAGE(WM_XLISTCTRL_EDIT_BTNEDIT_CLICKED,?OnRenameEditClicked)
??? ON_REGISTERED_MESSAGE(WM_XLISTCTRL_HEADER_CHECKBOX_CLICKED, OnHeaderChecked)
That' OK.
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
