/* RecalcHeaderTips() */ void CListViewEx::RecalcHeaderTips(void) { // update the tooltip info CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); RECT rect; pHeader->GetClientRect(&rect); RECT rctooltip; rctooltip.top = 0; rctooltip.bottom = rect.bottom; rctooltip.left = 0;// - GetScrollPos(SB_HORZ); CToolInfo toolinfo; toolinfo.cbSize = sizeof(toolinfo); // cycle through the tooltipinfo for each column int numcol = pHeader->GetItemCount(); //for(int col = 0; col <= numcol; col++ ) for(int col = 0; col < numcol; col++ ) { m_ToolTipCtrl.GetToolInfo(toolinfo,pHeader,col+1); rctooltip.right = rctooltip.left + GetListCtrl().GetColumnWidth(col); toolinfo.rect = rctooltip; m_ToolTipCtrl.SetToolInfo (&toolinfo); rctooltip.left += GetListCtrl().GetColumnWidth(col); } }
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); } }
//*************************************************************** 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 }
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; }
BOOL CPWListCtrl::OnEraseBkgnd(CDC* pDC) { if (m_bFilterActive && app.GetMainDlg()->GetNumPassedFiltering() == 0) { int nSavedDC = pDC->SaveDC(); //save the current DC state // Set up variables COLORREF clrText = RGB(168, 0, 0); COLORREF clrBack = ::GetSysColor(COLOR_WINDOW); //system background color CBrush cbBack(clrBack); CRect rc; GetClientRect(&rc); //get client area of the ListCtrl // If there is a header, we need to account for the space it occupies CHeaderCtrl* pHC = GetHeaderCtrl(); if (pHC != NULL) { CRect rcH; pHC->GetClientRect(&rcH); rc.top += rcH.bottom; } // Here is the string we want to display (or you can use a StringTable entry) const CString cs_emptytext(MAKEINTRESOURCE(IDS_NOITEMSPASSEDFILTERING)); // Now we actually display the text // set the text color pDC->SetTextColor(clrText); // set the background color pDC->SetBkColor(clrBack); // fill the client area rect pDC->FillRect(&rc, &cbBack); // select a font pDC->SelectStockObject(ANSI_VAR_FONT); // and draw the text pDC->DrawText(cs_emptytext, -1, rc, DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP); // Restore dc pDC->RestoreDC(nSavedDC); ReleaseDC(pDC); } else { // If there are items in the ListCtrl, we need to call the base class function CListCtrl::OnEraseBkgnd(pDC); } return TRUE; }
BOOL CSHListCtrl::AddHeaderToolTip(int nCol, LPCTSTR sTip ) { const int TOOLTIP_LENGTH = 80; char buf[TOOLTIP_LENGTH+1]; CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); if( nCol >= nColumnCount) return FALSE; if( (GetStyle() & LVS_TYPEMASK) != LVS_REPORT ) return FALSE; // Get the header height RECT rect; pHeader->GetClientRect( &rect ); int height = rect.bottom; RECT rctooltip; rctooltip.top = 0; rctooltip.bottom = rect.bottom; // Now get the left and right border of the column rctooltip.left = 0 - GetScrollPos( SB_HORZ ); for( int i = 0; i < nCol; i++ ) rctooltip.left += GetColumnWidth( i ); rctooltip.right = rctooltip.left + GetColumnWidth( nCol ); if( sTip == NULL ) { // Get column heading LV_COLUMN lvcolumn; lvcolumn.mask = LVCF_TEXT; lvcolumn.pszText = buf; lvcolumn.cchTextMax = TOOLTIP_LENGTH; if( !GetColumn( nCol, &lvcolumn ) ) return FALSE; } m_tooltip.AddTool( GetDlgItem(0), sTip ? sTip : buf, &rctooltip, nCol+1 ); return TRUE; }
/* AddHeaderToolTip() */ BOOL CListViewEx::AddHeaderToolTip(int nCol,LPCTSTR pTooltipText/*=NULL*/) { char buf[TOOLTIP_TEXT_LENGTH+1] = {0}; // controlla il numero della colonna CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); if(nCol >= pHeader->GetItemCount()) return(FALSE); // deve trovarsi in modalita' report if((GetStyle() & LVS_TYPEMASK)!=LVS_REPORT) return(FALSE); // get the header height RECT rect; pHeader->GetClientRect(&rect); RECT rctooltip; rctooltip.top = 0; rctooltip.bottom = rect.bottom; // now get the left and right border of the column rctooltip.left = 0;// - GetScrollPos(SB_HORZ); for(int i = 0; i < nCol; i++) rctooltip.left += GetListCtrl().GetColumnWidth(i); rctooltip.right = rctooltip.left + GetListCtrl().GetColumnWidth(nCol); // se non viene specificato un testo, utilizza il nome della colonna if(!pTooltipText) { LV_COLUMN lvcolumn = {0}; lvcolumn.mask = LVCF_TEXT; lvcolumn.pszText = buf; lvcolumn.cchTextMax = TOOLTIP_TEXT_LENGTH; if(!GetListCtrl().GetColumn(nCol,&lvcolumn)) return(FALSE); } // elimina e reinserisce perche' il tooltip puo' venir (re)impostato varie volte m_ToolTipCtrl.DelTool(GetDlgItem(0),nCol+1); m_ToolTipCtrl.AddTool(GetDlgItem(0),pTooltipText ? pTooltipText : buf,&rctooltip,nCol+1); return(TRUE); }
void CDragDropListCtrl::OnMouseMove(UINT nFlags, CPoint point) { if (m_pDragImage) { // Must be dragging, as there is a drag image. // Move the drag image. CPoint ptDragImage(point); ClientToScreen(&ptDragImage); m_pDragImage->DragMove(ptDragImage); // Leave dragging so we can update potential drop target selection. m_pDragImage->DragLeave(CWnd::GetDesktopWindow()); // Force x coordinate to always be in list control - only interested in y coordinate. // In effect the list control has captured all horizontal mouse movement. static const int nXOffset = 8; CRect rect; GetWindowRect(rect); CWnd* pDropWnd = CWnd::WindowFromPoint(CPoint(rect.left + nXOffset, ptDragImage.y)); // Get the window under the drop point. if (pDropWnd == this) { // Still in list control so select item under mouse as potential drop target. point.x = nXOffset; // Ensures x coordinate is always valid. UpdateSelection(HitTest(point)); } CRect rectClient; GetClientRect(rectClient); CPoint ptClientDragImage(ptDragImage); ScreenToClient(&ptClientDragImage); // Client rect includes header height, so ignore it, i.e., // moving the mouse over the header (and higher) will result in a scroll up. CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); if (pHeader) { CRect rectHeader; pHeader->GetClientRect(rectHeader); rectClient.top += rectHeader.Height(); } if (ptClientDragImage.y < rectClient.top) { // Mouse is above the list control - scroll up. SetScrollTimer(scrollUp); } else if (ptClientDragImage.y > rectClient.bottom) { // Mouse is below the list control - scroll down. SetScrollTimer(scrollDown); } else { KillScrollTimer(); } // Resume dragging. m_pDragImage->DragEnter(CWnd::GetDesktopWindow(), ptDragImage); } else { KillScrollTimer(); } CListCtrl::OnMouseMove(nFlags, point); }
void CMainFrame::OnContextMenu(HWND /*hWnd*/, CPoint pos) { if(m_bRefreshing) return; ENTER_CRITICAL_SECTION(&m_csThreadRefreshStatus); 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(NULL == (hItemSelected = ctrlTree.HitTest(posInView, NULL))) { LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus); return; } ctrlTree.SelectItem(hItemSelected); } selectedItemData = m_viewTreeList.GetSelectedItemData(); // Display context menu CMenu menu; CMenuHandle subMenu; CDiskObjectPtr obj = m_mapObject[selectedItemData]; ATLASSERT( obj.get() != NULL ); menu.LoadMenu( MAKEINTRESOURCE(IDR_CONTEXT_MENU) ); subMenu = menu.GetSubMenu(0); CObjectUIHandler::GetUIHandler(obj)->InsertMenu(obj, subMenu); ATLTRACE(_T("Menu Count : %d"), subMenu.GetMenuItemCount()); subMenu.RemoveMenu(IDM_AGGR_PROPERTY, MF_BYCOMMAND); // subMenu.RemoveMenu(MF_BYPOSITION, subMenu.GetMenuItemCount()); subMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, pos.x, pos.y, m_hWnd ); LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus); return; }