int CListCtrlEx::GetColumnCount() { CHeaderCtrl* pHeaderCtrl = GetHeaderCtrl(); if(pHeaderCtrl!=NULL) return pHeaderCtrl->GetItemCount(); else return 0; }
int CKInputDlg::add_col(CString heading) { CHeaderCtrl* pHeaderCtrl = m_resList.GetHeaderCtrl(); if (pHeaderCtrl != NULL) return m_resList.InsertColumn(pHeaderCtrl->GetItemCount(),heading ,LVCFMT_LEFT,KK_COL_WIDTH(heading.GetLength())); return 0; }
CComboBox* CSHListCtrl::ShowInPlaceComboBox(int nItem, int nSubitem,DWORD dwStyle) { // The returned pointer should not be saved // Make sure that the item is visible // My code start here if (!EnsureVisible(nItem, TRUE) ) return NULL; // Make sure that nCol is valid CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); if( nSubitem >= nColumnCount || GetColumnWidth(nSubitem) < 10 ) return NULL; // Get the column offset int offset = 0; for(int i = 0; i < nSubitem; i++) offset += GetColumnWidth(i); CRect rect; GetItemRect(nItem, &rect, LVIR_BOUNDS); // Now scroll if we need to expose the column CRect rcClient; GetClientRect(&rcClient); if(offset + rect.left < 0 || offset + rect.left > rcClient.right) { CSize size; size.cx = offset + rect.left; size.cy = 0; Scroll(size); rect.left -= size.cx; } rect.left += offset; rect.right = rect.left + GetColumnWidth( nSubitem ) ; int height = rect.bottom - rect.top; rect.bottom += 22 * height; if (rect.right > rcClient.right) rect.right = rcClient.right; dwStyle |= WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DISABLENOSCROLL; CComboBox* pList = new CSHInPlaceComboBox(nItem, nSubitem); pList->Create(dwStyle, rect, this, IDC_INPLACE_COMBOBOX); pList->SetItemHeight(-1, height); pList->SetHorizontalExtent(GetColumnWidth(nSubitem)); CString strWindowText = GetItemText(nItem, nSubitem); if(dwStyle & CBS_DROPDOWN && !(dwStyle & CBS_DROPDOWNLIST)) { CEdit* m_pEdit = new CEdit(); m_pEdit->SubclassWindow(pList->GetDlgItem(1001)->GetSafeHwnd()); m_pEdit->SetWindowText(strWindowText); m_pEdit->SetSel(0,-1); } return pList; // My code end here }
void CGridListCtrl::OnPaint() { // Make the gridlines easier to see than default light grey // First let the control do its default drawing. const MSG *pMsg = GetCurrentMessage(); DefWindowProc(pMsg->message, pMsg->wParam, pMsg->lParam); // Draw the lines only for LVS_REPORT mode if ((GetStyle() & LVS_TYPEMASK) == LVS_REPORT) { CClientDC dc(this); CPen NewPen(PS_SOLID, 0, m_RGBLineColour); CPen *pOldPen = dc.SelectObject(&NewPen); // Get the number of columns CHeaderCtrl *pHeader = (CHeaderCtrl *)GetDlgItem(m_HeaderCtrlID); int nColumnCount = pHeader->GetItemCount(); // The bottom of the header corresponds to the top of the line RECT rect; pHeader->GetClientRect(&rect); int top = rect.bottom; // Now get the client rect so we know the line length and when to stop GetClientRect(&rect); // The border of the column is offset by the horz scroll int borderx = 0 - GetScrollPos(SB_HORZ); for (int i = 0; i < nColumnCount; i++) { // Get the next border borderx += GetColumnWidth(pHeader->OrderToIndex(i)); // if next border is outside client area, break out if (borderx >= rect.right) break; // Draw the line. dc.MoveTo(borderx - 1, top); dc.LineTo(borderx - 1, rect.bottom); } // Draw the horizontal grid lines // First get the height if (!GetItemRect(0, &rect, LVIR_BOUNDS)) return; int height = rect.bottom - rect.top; GetClientRect(&rect); int width = rect.right; for (int i = 1; i <= GetCountPerPage(); i++) { dc.MoveTo(0, top + height * i); dc.LineTo(width, top + height * i); } dc.SelectObject(pOldPen); } }
// EditSubLabel - Start edit of a sub item label // Returns - Temporary pointer to the new edit control // nItem - The row index of the item to edit // nCol - The column of the sub item. CEdit* CVarListCtrl::EditSubLabel( int nItem, int nCol ) { // The returned pointer should not be saved // Make sure that the item is visible //if( !EnsureVisible( nItem, TRUE ) ) return NULL; // Make sure that nCol is valid CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); if( nCol >= nColumnCount || GetColumnWidth(nCol) < 5 ) return NULL; // Get the column offset int offset = 0; for( int i = 0; i < nCol; i++ ) offset += GetColumnWidth( i ); CRect rect; GetItemRect( nItem, &rect, LVIR_BOUNDS ); // Now scroll if we need to expose the column CRect rcClient; GetClientRect( &rcClient ); if( offset + rect.left < 0 || offset + rect.left > rcClient.right ) { CSize size; size.cx = offset + rect.left; size.cy = 0; Scroll( size ); rect.left -= size.cx; } // Get Column alignment LV_COLUMN lvcol; lvcol.mask = LVCF_FMT; GetColumn( nCol, &lvcol ); DWORD dwStyle ; if((lvcol.fmt&LVCFMT_JUSTIFYMASK) == LVCFMT_LEFT) dwStyle = ES_LEFT; else if((lvcol.fmt&LVCFMT_JUSTIFYMASK) == LVCFMT_RIGHT) dwStyle = ES_RIGHT; else dwStyle = ES_CENTER; rect.left += offset+4; rect.right = rect.left + GetColumnWidth( nCol ) - 3 ; if( rect.right > rcClient.right) rect.right = rcClient.right; dwStyle |= WS_BORDER|WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL; CEdit *pEdit = new CVarListEdit(nItem, nCol, GetItemText( nItem, nCol )); pEdit->Create( dwStyle, rect, this, 2020 ); return pEdit; }
void CSiriusView::OnDestroy() { HDITEM hdi; // store columns width CHeaderCtrl *pHdr = GetListCtrl().GetHeaderCtrl(); hdi.mask = HDI_WIDTH; pHdr->GetItem(0, &hdi); g_Settings.m_iListSrcAddr = hdi.cxy; pHdr->GetItem(2, &hdi); g_Settings.m_iListDestAddr = hdi.cxy; pHdr->GetItem(1, &hdi); g_Settings.m_iListSrcPort = hdi.cxy; pHdr->GetItem(3, &hdi); g_Settings.m_iListDestPort = hdi.cxy; pHdr->GetItem(4, &hdi); g_Settings.m_iListProto = hdi.cxy; pHdr->GetItem(5, &hdi); g_Settings.m_iListTraffic = hdi.cxy; pHdr->GetItem(6, &hdi); g_Settings.m_iListBS = hdi.cxy; pHdr->GetItem(7, &hdi); g_Settings.m_iListABS = hdi.cxy; if (g_bStarted) { OnCommandStop(); g_bStarted = FALSE; } CListView::OnDestroy(); }
void CListCtrlEx::ReadState(LPCSTR pszName) { CHeaderCtrl* pHdr = GetHeaderCtrl (); int *piWidthes; Initialize (); LPBYTE pbW, pbI; UINT uSizeI, uSizeW; CString strIndexes = pszName, strWidthes = pszName; strIndexes += 'I'; strWidthes += 'W'; if (_App.GetProfileBinary (_T ("Settings\\View\\ListViews"), strIndexes, &pbI, &uSizeI) && _App.GetProfileBinary (_T ("Settings\\View\\ListViews"), strWidthes, &pbW, &uSizeW) && uSizeI == m_cTotalCols * sizeof (int) && uSizeW == m_cTotalCols * sizeof (int)) { CopyMemory (m_aIndex, pbI, m_cTotalCols * sizeof (int)); piWidthes = (int*) pbW; int i = m_cTotalCols - 1; for (i = m_cTotalCols - 1; i >= 0; i--) if (m_aIndex [i] == -1) DeleteColumn (i); int aOrder [LISTEX_MAXCOLUMNS]; int iCorr = 0; for (i = 0; i < m_cTotalCols; i++) { if (m_aIndex [i] != -1) aOrder [m_aIndex [i]] = i - iCorr; else iCorr ++; } pHdr->SetOrderArray (GetHeaderCtrl ()->GetItemCount (), (int*) aOrder); RebuildAIndex (); for (i = 0; i < m_cTotalCols; i++) { if (piWidthes [i] > 0) SetColumnWidth (aOrder [m_aIndex [i]], piWidthes [i]); } delete [] pbW; delete [] pbI; } }
void CIrcNickListCtrl::Localize() { CHeaderCtrl* pHeaderCtrl = GetHeaderCtrl(); CString sResource; sResource = GetResString(IDS_STATUS); HDITEM hdi; hdi.pszText = const_cast<LPTSTR>((LPCTSTR)sResource); hdi.mask = HDI_TEXT; pHeaderCtrl->SetItem(1, &hdi); UpdateNickCount(); }
int CColListCtrl::SetComboBoxColumn( int nCol ) { CHeaderCtrl * pHeaderCtrl = GetHeaderCtrl(); if( pHeaderCtrl ) { ASSERT( nCol < pHeaderCtrl->GetItemCount() ); } m_nComboBoxColumn = nCol; return m_nComboBoxColumn; }
BOOL CSHListCtrl::PositionControl(CWnd * pWnd, int iItem, int iSubItem) { ASSERT( pWnd && pWnd->m_hWnd ); ASSERT( iItem >= 0 ); // Make sure that the item is visible if (!EnsureVisible(iItem, TRUE)) return NULL; // Make sure that nCol is valid CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); ASSERT(iSubItem >= 0 && iSubItem < nColumnCount); if (iSubItem >= nColumnCount || // We have to take into account that the header may be reordered GetColumnWidth(Header_OrderToIndex( pHeader->m_hWnd, iSubItem)) < 5) { return 0; } // Get the header order array to sum the column widths up to the selected cell. int *orderarray = new int[nColumnCount]; Header_GetOrderArray(pHeader->m_hWnd, nColumnCount, orderarray); int offset = 0; int i; for (i = 0; orderarray[i] != iSubItem; i++) offset += GetColumnWidth(orderarray[i]); int colwidth = GetColumnWidth(iSubItem); delete[] orderarray; CRect rect; GetItemRect(iItem, &rect, LVIR_BOUNDS); // Scroll if we need to expose the column CRect rcClient; GetClientRect(&rcClient); if (offset + rect.left < 0 || offset + colwidth + rect.left > rcClient.right) { CSize size; size.cx = offset + rect.left; size.cy = 0; Scroll( size ); rect.left -= size.cx; } rect.left += offset + 4; rect.right = rect.left + colwidth - 3; // The right end of the control should not go past the edge // of the grid control. if (rect.right > rcClient.right) rect.right = rcClient.right; pWnd->MoveWindow(&rect); return 1; }
// 设置/获取某列Header的参数 void CLogViewDlg::SetHeaderParam(int nIndex, LPARAM lParam) { CHeaderCtrl* pHeader = m_LogList.GetHeaderCtrl(); if(pHeader != NULL) { HDITEM hdItem = {0}; hdItem.mask = HDI_LPARAM; hdItem.lParam = lParam; pHeader->SetItem(nIndex, &hdItem); } }
void InsertMenu(CListCtrl& list, CMenu* pMenu, UINT nIndex, // Menu id to remplace CImageList* pImageList) { CHeaderCtrl *pHeader = list.GetHeaderCtrl(); int nbCol = pHeader->GetItemCount(); int nAfter = -1, id; char buffer[maxTitleLength]; HDITEM hi; if (pImageList == NULL) pImageList = pHeader->GetImageList(); hi.mask = HDI_FORMAT|HDI_IMAGE|HDI_LPARAM|HDI_TEXT; hi.pszText = buffer; hi.cchTextMax = maxTitleLength; while (--nbCol >= 0) { pHeader->GetItem(nbCol, &hi); if (hi.lParam == 0) continue; // there is a sort possible column id = nIndex + nbCol; if (nAfter < 0) { if (!pMenu->ModifyMenu(nIndex, MF_BYCOMMAND|MF_STRING, id, buffer)) return; } else { pMenu->InsertMenu(nAfter, MF_BYCOMMAND|MF_STRING, id, buffer); } if (hi.iImage && pImageList) { static CBitmap bm, *pOldBm; IMAGEINFO ii; CDC dcMem; // fill a bitmap with the sort image pImageList->GetImageInfo(hi.iImage, &ii); int w = ii.rcImage.right - ii.rcImage.left; int h = ii.rcImage.bottom - ii.rcImage.top; dcMem.CreateCompatibleDC(NULL); if (bm.m_hObject) bm.DeleteObject(); bm.CreateCompatibleBitmap(&dcMem, w, h); pOldBm = dcMem.SelectObject(&bm); dcMem.FillSolidRect(0, 0, w, h, 0xFFFFFF); pImageList->Draw(&dcMem, hi.iImage, CPoint(0,0), ILD_NORMAL); dcMem.SelectObject(pOldBm); // display the sort icon pMenu->SetMenuItemBitmaps(id, MF_BYCOMMAND, &bm, &bm); } nAfter = id; } }
//*************************************************************** void CColorListCtrl::OnPaint() { // First let the control do its default drawing. const MSG *msg = GetCurrentMessage(); DefWindowProc( msg->message, msg->wParam, msg->lParam ); if (!m_fullColumnLines) return; // Draw the lines only for LVS_REPORT mode if( (GetStyle() & LVS_TYPEMASK) == LVS_REPORT ) { // Get the number of columns CClientDC dc(this ); CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); // The bottom of the header corresponds to the top of the line RECT rect; pHeader->GetClientRect( &rect ); int top = rect.bottom; // Now get the client rect so we know the line length and // when to stop GetClientRect( &rect ); // The border of the column is offset by the horz scroll int borderx = 0 - GetScrollPos( SB_HORZ ); CPen *pOldPen; CPen pen; CGdiObject *pOldBrush; pen.CreatePen( PS_DOT, 0, GetColorRef(DEF_DESELTEXT) ); pOldPen =dc.SelectObject(&pen); pOldBrush=dc.SelectStockObject(NULL_BRUSH); for( int i = 0; i < nColumnCount; i++ ) { // Get the next border borderx += GetColumnWidth( i ); // if next border is outside client area, break out if( borderx >= rect.right ) break; // Draw the line. dc.MoveTo( borderx-1, top); dc.LineTo( borderx-1, rect.bottom ); } dc.SelectObject(pOldPen); dc.SelectObject(pOldBrush); } // Do not call CListCtrl::OnPaint() for painting messages }
LPARAM CLogViewDlg::GetHeaderParam(int nIndex) { CHeaderCtrl* pHeader = m_LogList.GetHeaderCtrl(); if(pHeader != NULL) { HDITEM hdItem = {0}; hdItem.mask = HDI_LPARAM; pHeader->GetItem(nIndex, &hdItem); return hdItem.lParam; } return 0; }
void CNBBindListViewCtrl::OnPaint(HDC /*wParam*/) { CRect rtCol, rtHeader, rtSubItem; CHeaderCtrl header = GetHeader(); header.GetWindowRect( rtHeader ); ScreenToClient( rtHeader ); header.GetItemRect( 0, rtCol) ; rtCol.OffsetRect( rtHeader.TopLeft() ); while ( !m_vtRowHeader.empty() ) { CCustomStaticCtrl *pWnd = m_vtRowHeader.front(); m_vtRowHeader.pop_front(); pWnd->DestroyWindow(); delete pWnd; } // For vertical scroll. if ( GetItemCount() > 0 ) { GetSubItemRect(0, 0, LVIR_BOUNDS, rtSubItem); } else { rtSubItem.top = rtCol.bottom; } for ( UINT i=0; i < m_nMaxCount; i++ ) { CCustomStaticCtrl *pWnd; CStatic staticCtrl; pWnd = new CCustomStaticCtrl; CRect rtItem; static int nHeight = 14; rtItem.left = rtCol.left; rtItem.right = rtCol.right-2; rtItem.top = rtSubItem.top + i * nHeight; rtItem.bottom = rtItem.top + nHeight-1; if ( rtItem.top < rtCol.bottom ) continue; WTL::CString strTitle; strTitle.Format(_T("%d"), i); staticCtrl.Create( m_hWnd, rtItem, strTitle, WS_CHILD | SS_CENTER | WS_DISABLED); staticCtrl.ShowWindow( SW_SHOW ); pWnd->SubclassWindow( staticCtrl.m_hWnd ); m_vtRowHeader.push_back( pWnd ); } DefWindowProc(); }
void CTblInfoView::SetSelResults(const char *pszRet) { //update local cache m_map_req_resp[m_strQueryReq] = pszRet; //make sure m_strCurTbl matches the results. //so, OP_SUBMITTING is added static CMainFrame* pMainFrame = reinterpret_cast<CMainFrame*>(AfxGetMainWnd()); static CListCtrl &ctrl = GetListCtrl(); CHeaderCtrl *pHeader = ctrl.GetHeaderCtrl(); int nCount = pHeader->GetItemCount(); ctrl.DeleteAllItems(); CString strCols = pszRet; CString strSub = _T(""); int nItem = 0; int nSubItem = 0; int nIndex = 0; LVITEM lv; lv.mask = LVIF_TEXT; for (int i = 0; ; i++) { if (!AfxExtractSubString(strSub, strCols, i, '|') || 0 == strSub.GetLength()) { break; } nItem = i / nCount; nSubItem = i % nCount; lv.iItem = nIndex;//0; //nItem; lv.iSubItem = nSubItem; lv.pszText = strSub.GetBuffer(0); if (0 == nSubItem) { nIndex = ctrl.InsertItem(&lv); } else { ctrl.SetItem(&lv); } } m_Operation = OP_NONE; }
void CClientListCtrl::Localize() { CHeaderCtrl* pHeaderCtrl = GetHeaderCtrl(); HDITEM hdi; hdi.mask = HDI_TEXT; if(pHeaderCtrl->GetItemCount() != 0) { CString strRes; strRes = GetResString(IDS_QL_USERNAME); hdi.pszText = strRes.GetBuffer(); pHeaderCtrl->SetItem(0, &hdi); strRes.ReleaseBuffer(); strRes = GetResString(IDS_CL_UPLOADSTATUS); hdi.pszText = strRes.GetBuffer(); pHeaderCtrl->SetItem(1, &hdi); strRes.ReleaseBuffer(); strRes = GetResString(IDS_CL_TRANSFUP); hdi.pszText = strRes.GetBuffer(); pHeaderCtrl->SetItem(2, &hdi); strRes.ReleaseBuffer(); strRes = GetResString(IDS_CL_DOWNLSTATUS); hdi.pszText = strRes.GetBuffer(); pHeaderCtrl->SetItem(3, &hdi); strRes.ReleaseBuffer(); strRes = GetResString(IDS_CL_TRANSFDOWN); hdi.pszText = strRes.GetBuffer(); pHeaderCtrl->SetItem(4, &hdi); strRes.ReleaseBuffer(); strRes=GetResString(IDS_CD_CSOFT); hdi.pszText = strRes.GetBuffer(); pHeaderCtrl->SetItem(5, &hdi); strRes.ReleaseBuffer(); strRes = GetResString(IDS_CONNECTED); hdi.pszText = strRes.GetBuffer(); pHeaderCtrl->SetItem(6, &hdi); strRes.ReleaseBuffer(); strRes=GetResString(IDS_CD_UHASH);strRes.Remove(':'); hdi.pszText = strRes.GetBuffer(); pHeaderCtrl->SetItem(7, &hdi); strRes.ReleaseBuffer(); } }
int CListCtrlA::CellRectFromPoint(CPoint & point, RECT * cellrect, int * col) const{ int colnum; // Make sure that the ListView is in LVS_REPORT if( (GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT ) return -1; // Get the top and bottom row visible int row = GetTopIndex(); int bottom = row + GetCountPerPage(); if( bottom > GetItemCount() ) bottom = GetItemCount(); // Get the number of columns CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); // Loop through the visible rows for( ;row <=bottom;row++) { // Get bounding rect of item and check whether point falls in it. CRect rect; GetItemRect( row, &rect, LVIR_BOUNDS ); if( rect.PtInRect(point) ) { // Now find the column for( colnum = 0; colnum < nColumnCount; colnum++ ) { int colwidth = GetColumnWidth(colnum); if( point.x >= rect.left && point.x <= (rect.left + colwidth ) ) { RECT rectClient; GetClientRect( &rectClient ); if( col ) *col = colnum; rect.right = rect.left + colwidth; // Make sure that the right extent does not exceed // the client area if( rect.right > rectClient.right ) rect.right = rectClient.right; *cellrect = rect; return row; } rect.left += colwidth; } } } return -1; }
void CMyListCtrl::PreSubclassWindow() { // TODO: Add your specialized code here and/or call the base class // TODO: 在此添加专用代码和/或调用基类 ModifyStyle(0,LVS_OWNERDRAWFIXED); CListCtrl::PreSubclassWindow(); this->SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); CHeaderCtrl *pHeader = GetHeaderCtrl(); m_Head.SubclassWindow(pHeader->GetSafeHwnd()); CListCtrl::PreSubclassWindow(); }
void CMainFrame::OnContextMenu(HWND /*hWnd*/, CPoint pos) { int selectedItemData; // get selectedItemData CRect rect; CPoint posInView; HTREEITEM hItemSelected; // if clicked on tree, we need to change selection if (m_viewTreeList.GetWindowRect( rect ) && rect.PtInRect(pos) ) { CTreeViewCtrlEx ctrlTree = m_viewTreeList.GetTreeControl(); CHeaderCtrl ctrlHeader = m_viewTreeList.GetHeaderControl(); CRect rectHeader; ctrlHeader.GetClientRect(rectHeader); // clicked point is inside the tree control // Change screen coordinates to client coordinates posInView = pos - rect.TopLeft(); posInView.y -= rectHeader.Height(); if(hItemSelected = ctrlTree.HitTest(posInView, NULL)) { ctrlTree.SelectItem(hItemSelected); } } CNBDevice *pDevice = m_viewTreeList.GetSelectedDevice(); if(!pDevice) return; CMenu menu; CMenuHandle subMenu; menu.LoadMenu(IDR_MAINFRAME); subMenu = menu.GetSubMenu(1); // Tool subMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, pos.x, pos.y, m_hWnd ); return; }
void CTxMsgListView::OnColumnclickLstcMsgDetails(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; // If it is first column if( pNMListView->iSubItem == 0 ) { // Get the status from Image Index BOOL bToBeChecked = FALSE; // Change header Control Image Index CHeaderCtrl* pHeader = m_omLctrMsgList.GetHeaderCtrl(); if( pHeader != nullptr ) { // Get Current Image Index HDITEM hditem; hditem.mask = HDI_IMAGE | HDI_FORMAT; if( pHeader->GetItem(0, &hditem ) == TRUE ) { // Image Index To be Set int nNewImageIndex = 0; // Toggle Image Index if( hditem.iImage == 0 ) { bToBeChecked = TRUE; nNewImageIndex = 1; } // Update Image Index hditem.fmt |= HDF_IMAGE; hditem.iImage = nNewImageIndex; pHeader->SetItem(0, &hditem ); // Update Message Check Value vSetMessageCheckValue( bToBeChecked ); CTxFunctionsView* pView = (CTxFunctionsView*) pomGetFunctionsViewPointer(); if( pView != nullptr ) { if(pView->m_CheckBoxAutoUpdate.GetCheck() == BST_CHECKED) { pView->vAccessButtonApply(); this->SetFocus(); } } } } } *pResult = 0; }
/******************************************************************************* Function Name : DrawItem Input(s) : lpDis - Pointer to Display Structure Output : Functionality : This will be callee by the framework to draw list control items Member of : CMessageList Author(s) : Ratnadip Choudhury Date Created : 02/12/2004 Modifications : Raja N Modified the code to support any number of columns. Original code was to support only two columns. Raja N on 14.12.2004 Review comments implemented. Removed hardcoded value. *******************************************************************************/ void CMessageList::DrawItem(LPDRAWITEMSTRUCT lpDis) { // Get the column Count CHeaderCtrl* pHeader = GetHeaderCtrl(); int nColCount = pHeader->GetItemCount(); const int nOffset = 2; // Initialise to default values COLORREF TxtColour = (COLORREF)GetItemData(lpDis->itemID); HBRUSH hBkBrush = m_hWhiteBrush; // Select Blue brush and white pen if this item is selected if ((lpDis->itemState & ODS_SELECTED) && (lpDis->itemState & ODS_FOCUS)) { TxtColour = WHITE_COLOR; hBkBrush = m_hBlueBrush; } // Set Text color and fill background ::SetTextColor(lpDis->hDC, TxtColour); ::FillRect(lpDis->hDC, &(lpDis->rcItem), hBkBrush); // Draw Item and subitems CRect omSubItemRect; for( int nIndex = 0; nIndex < nColCount; nIndex++ ) { // Get Item boundary GetSubItemRect( lpDis->itemID, nIndex, LVIR_BOUNDS, omSubItemRect); // Correct right magin if( nIndex != nColCount - 1 ) { CRect omNextSubItemRect; GetSubItemRect( lpDis->itemID, nIndex + 1, LVIR_BOUNDS, omNextSubItemRect); omSubItemRect.right = omNextSubItemRect.left; } // Give some offset from the border omSubItemRect.left += nOffset; // Draw Message Name m_omStrInARow = GetItemText(lpDis->itemID, nIndex); ::DrawText( lpDis->hDC, m_omStrInARow, m_omStrInARow.GetLength(), &omSubItemRect, DT_LEFT); } }
// {group:View Classes} // // Name: // cvCTestView::DropItemOnList // // Description: // Called when an item is to be dropped on the listctrl. A new entry // in the list control is made and the original item is deleted. // void cvCTestView::DropItemOnList() { //GET THE DROP INDEX m_ptDropPoint.y += 10; m_nDropIndex = GetListCtrl().HitTest(m_ptDropPoint); if (m_nDropIndex < 0) m_nDropIndex = GetListCtrl().GetItemCount(); //GET INFORMATION ON THE DRAGGED ITEM BY SETTING AN LV_ITEM STRUCTURE //AND THEN CALLING GetItem TO FILL IT IN TCHAR szLabel[256]; LV_ITEM lvi; ZeroMemory(&lvi, sizeof(LV_ITEM)); lvi.mask = LVIF_TEXT | LVIF_PARAM; lvi.pszText = szLabel; lvi.iItem = m_nDragIndex; lvi.cchTextMax = 255; GetListCtrl().GetItem(&lvi); _bstr_t bstrDescription; CLSID clsid; if (lvi.lParam != NULL) { bstrDescription = ((cvCDragDropItem*) lvi.lParam)->GetDescription(); clsid = ((cvCDragDropItem*) lvi.lParam)->GetCLSID(); } // Perform the insert operation here InsertItem(m_nDropIndex, _bstr_t(lvi.pszText), bstrDescription, clsid); // Fill in the attributes for the item to be inserted CHeaderCtrl* pHeader = (CHeaderCtrl*)GetListCtrl().GetDlgItem(0); ASSERT(pHeader != NULL); if (pHeader != NULL) { int nColumnCount = pHeader->GetItemCount(); lvi.mask = LVIF_TEXT; lvi.iItem = m_nDropIndex; // Increment index if we are dragging an item above itself if (m_nDragIndex > m_nDropIndex) m_nDragIndex++; // Delete the source item GetListCtrl().DeleteItem(m_nDragIndex); } }
int COutlookDemoView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CListView::OnCreate(lpCreateStruct) == -1) return -1; const int nImageWidth = 12; m_ImagesHeader.Create(IDB_HEADER_IMAGES, nImageWidth, 0, RGB(255, 0, 255)); CBitmap bmp; if (bmp.LoadBitmap(IDB_LIST_IMAGES)) { m_ImagesList.Create(16, 16, ILC_COLOR24 | ILC_MASK, 0, 0); m_ImagesList.Add(&bmp, RGB(255, 0, 255)); } CListCtrl& wndList = GetListCtrl(); wndList.SetExtendedStyle(LVS_EX_FULLROWSELECT); wndList.SetImageList(&m_ImagesList, LVSIL_SMALL); wndList.InsertColumn(0, _T("From"), LVCFMT_LEFT, 100); wndList.InsertColumn(1, _T("Subject"), LVCFMT_LEFT, 200); CHeaderCtrl* pHeaderCtrl = (CHeaderCtrl*) wndList.GetDlgItem(0); ASSERT_VALID(pHeaderCtrl); pHeaderCtrl->SetImageList(&m_ImagesHeader); LVCOLUMN lvColumn; memset(&lvColumn, 0, sizeof(LVCOLUMN)); lvColumn.mask = LVCF_IMAGE | LVCF_WIDTH; lvColumn.fmt = LVCFMT_COL_HAS_IMAGES; lvColumn.cx = nImageWidth * 2 + 4; lvColumn.iImage = 0; wndList.InsertColumn(2, &lvColumn); lvColumn.iImage = 1; wndList.InsertColumn(3, &lvColumn); lvColumn.iImage = 2; wndList.InsertColumn(4, &lvColumn); static int nColumsOrder [] = { 2, 3, 4, 0, 1 }; wndList.SetColumnOrderArray(sizeof(nColumsOrder) / sizeof(int), nColumsOrder); return 0; }
//自动设置Head的宽度 void CMyListCtrl::AutoSize() { SetRedraw(FALSE); CHeaderCtrl* pHeaderCtrl = GetHeaderCtrl(); for (int i = 0; i < pHeaderCtrl->GetItemCount(); i++) { SetColumnWidth(i, LVSCW_AUTOSIZE); int nWidth1 = GetColumnWidth(i); SetColumnWidth(i, LVSCW_AUTOSIZE_USEHEADER); int nWidth2 = GetColumnWidth(i); SetColumnWidth(i, max(nWidth1, nWidth2)); } SetRedraw(TRUE); }
void CFriendListCtrl::Localize() { CHeaderCtrl* pHeaderCtrl = GetHeaderCtrl(); HDITEM hdi; hdi.mask = HDI_TEXT; CString strRes; strRes = GetResString(IDS_QL_USERNAME); hdi.pszText = const_cast<LPTSTR>((LPCTSTR)strRes); pHeaderCtrl->SetItem(0, &hdi); int iItems = GetItemCount(); for (int i = 0; i < iItems; i++) UpdateFriend(i, (CFriend*)GetItemData(i)); }
CString GetColumnTitle(CListCtrl &list, int iSubItem, LPCTSTR pszTitle) { CHeaderCtrl *pHeader = list.GetHeaderCtrl(); char buffer[maxTitleLength] = {0, }; HDITEM hi; hi.mask = HDI_FORMAT|HDI_TEXT; hi.pszText = buffer; hi.cchTextMax = maxTitleLength; if (pHeader->GetItem(iSubItem, &hi) && pszTitle) { hi.pszText = LPTSTR(pszTitle); pHeader->SetItem(iSubItem, &hi); } return CString(buffer); }
bool CPWListCtrl::IsNotesColumnPresent() { CHeaderCtrl *pHeader = GetHeaderCtrl(); if (pHeader == NULL) return false; HDITEM hdi; hdi.mask = HDI_LPARAM; for (int icol = 0; icol < pHeader->GetItemCount(); icol++) { pHeader->GetItem(icol, &hdi); if (hdi.lParam == CItemData::NOTES) return true; } return false; }
void CVarListCtrl::OnSize(UINT nType, int cx, int cy) { CListCtrl::OnSize(nType, cx, cy); ShowScrollBar(SB_HORZ, FALSE); //PositionHeader(); CHeaderCtrl* pHeader = GetHeaderCtrl(); if (pHeader) { int nColumnCount = pHeader->GetItemCount(); if (nColumnCount > 0) SetColumnWidth(nColumnCount-1, LVSCW_AUTOSIZE_USEHEADER); } }
void CListCtrlEx::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult) { if(IsHighContrast()) { return; } LPNMLVCUSTOMDRAW lpLVCustomDraw = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR); switch(lpLVCustomDraw->nmcd.dwDrawStage) { case CDDS_ITEMPREPAINT: case CDDS_ITEMPREPAINT | CDDS_SUBITEM: if(lpLVCustomDraw->nmcd.dwItemSpec % 2 == 0) { lpLVCustomDraw->clrText = m_TextColor1; lpLVCustomDraw->clrTextBk = m_BkColor1; } else { lpLVCustomDraw->clrText = m_TextColor2; lpLVCustomDraw->clrTextBk = m_BkColor2; } break; case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM: { RECT rc; CBrush brush(m_LineColor); CHeaderCtrl* header = this->GetHeaderCtrl(); if(header != NULL) { int count = header->GetItemCount(); for(int i = 0; i < count; i++) { ListView_GetSubItemRect(m_hWnd, lpLVCustomDraw->nmcd.dwItemSpec, i, LVIR_LABEL, &rc); rc.left = rc.right - 1; FillRect(lpLVCustomDraw->nmcd.hdc, &rc, (HBRUSH) brush.GetSafeHandle()); } } } break; default: break; } *pResult = 0; *pResult |= CDRF_NOTIFYPOSTPAINT; *pResult |= CDRF_NOTIFYITEMDRAW; *pResult |= CDRF_NOTIFYSUBITEMDRAW; }