void CListCtrlComboBox::ShowEdit(int nItem,int nSubItem) { if (nItem < 0 || nSubItem < 0) return; if (m_pParentList == NULL) return ; CListCtrl *pCtrl = m_pParentList; CRect rect; m_pParentList = pCtrl; // m_pParentList->GetSubItemRect(nItem,nIndex,LVIR_LABEL,rcCtrl); // 列可见 CHeaderCtrl* pHeader = (CHeaderCtrl*)pCtrl->GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); if( nSubItem >= nColumnCount || pCtrl->GetColumnWidth(nSubItem) < 5 ) return ; // 列偏移 int offset = 0; for( int i = 0; i < nSubItem; i++ ) offset += pCtrl->GetColumnWidth( i ); pCtrl->GetItemRect( nItem, &rect, LVIR_BOUNDS ); rect.top -= 2; if (rect.top < 0) rect.top = 0; // 滚动列,便于操作 CRect rcClient; CSize size; pCtrl->GetClientRect( &rcClient ); // if( offset + rect.left < 0 || offset + rect.left > rcClient.right ) if( offset + rect.left < 0 ) { size.cx = offset + rect.left; size.cy = 0; pCtrl->Scroll( size ); rect.left -= size.cx; } else if(offset + rect.left > rcClient.right ) { size.cx = offset + rect.left; size.cy = 0; pCtrl->Scroll( size ); rect.left -= size.cx; } // 获取列的对齐方式 LV_COLUMN lvcol; lvcol.mask = LVCF_FMT; pCtrl->GetColumn( nSubItem, &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 + 1; if (nSubItem > 0) rect.right = rect.left + pCtrl->GetColumnWidth( nSubItem ); else rect.right = rect.left + pCtrl->GetColumnWidth( nSubItem ); if( rect.right > rcClient.right) rect.right = rcClient.right; rect.bottom = rect.top + 12 * rect.Height(); CString strItem = pCtrl->GetItemText(nItem,nSubItem); pCtrl->ClientToScreen(rect); GetParent()->ScreenToClient(rect); MoveWindow(rect); // SetWindowPos(NULL, rect.left,rect.top,rect.Width(),rect.Height(), SWP_SHOWWINDOW); // pCtrl->ClientToScreen(rcClient); // GetParent()->ScreenToClient(rcClient); // pCtrl->SetWindowPos(this, rcClient.left,rcClient.top,rcClient.Width(),rcClient.Height(), SWP_SHOWWINDOW); ShowWindow(SW_SHOW); SetWindowText(strItem); ::SetFocus(GetSafeHwnd()); SetItemHeight(-1,13); //设置对应选项 int nIndex = FindStringExact(0, strItem); if (nIndex < 0) nIndex = 0; SetCurSel(nIndex); m_nCurrentItem = nItem; m_nCurrentSubItem = nSubItem; }
// // ListControlHitTest() // // - helper function for using the custom tooltip control with a list control // int CMyToolTipWnd::ListControlHitTest(CPoint point, CListCtrl& listCtl, int nColumn) { // get client position listCtl.ScreenToClient(&point); // get the index of the line under the cursor int nIndex = -1; int nFirstVisible = listCtl.GetTopIndex(); int numVisible = listCtl.GetCountPerPage(); CRect itemRect; for(int i=nFirstVisible;i<nFirstVisible+numVisible;i++) { if (listCtl.GetItemRect(i, &itemRect, LVIR_BOUNDS)) { if (itemRect.PtInRect(point)) { nIndex = i; break; } } } // bail out if not on a line if (nIndex < 0) return -1; // else the line was found, so return if the column doesn't matter if (nColumn < 0) return nIndex; // else need to check if the cursor is on the right column BOOL bShow = FALSE; BOOL bInPosition = FALSE; // check if the cursor is within the specified col CRect targetRect; // listCtl.ClientToScreen(&itemRect); targetRect.left = itemRect.left; // NCR-FFS Changed i to j for(int j=0;j<nColumn;j++) targetRect.left += listCtl.GetColumnWidth(j); targetRect.right = targetRect.left + listCtl.GetColumnWidth(nColumn); if ((point.x >= targetRect.left) && (point.x <= targetRect.right)) { // point is in the proper column, so save the rect CRect rect; listCtl.GetItemRect(nIndex, &rect, LVIR_LABEL); m_location.x = rect.right; m_location.y = rect.top; // account for column padding m_location.x += 5; m_location.y -= 1; // return the line index listCtl.ClientToScreen(&m_location); return nIndex; } else { // not within the proper column return -1; } }