/*************************************************** OnToolHitTest The framework calls this member function to determine whether a point is in the bounding rectangle of the specified tool. If the point is in the rectangle, it retrieves information about the tool. Params: point - please see MSDN for more information on the parameters. pTI Returns: If 1, the tooltip control was found; If -1, the tooltip control was not found. *****************************************************/ int CUGGrid::OnToolHitTest( CPoint point, TOOLINFO* pTI ) const { int col; long row; static int lastCol = -2; static long lastRow = -2; if(m_ctrl->GetCellFromPoint(point.x,point.y,&col,&row) == UG_SUCCESS) { if(col != lastCol || row != lastRow) { lastCol = col; lastRow = row; CancelToolTips(); return -1; } pTI->uFlags = TTF_NOTBUTTON | TTF_ALWAYSTIP |TTF_IDISHWND ; pTI->uId = (UINT_PTR)m_hWnd; pTI->hwnd = (HWND)m_hWnd; pTI->lpszText = LPSTR_TEXTCALLBACK; return 1; } return -1; }
// In this example, tool tips were set up to // pop up when the user moves the mouse // over this edit control. // If the mouse is moved to the upper left-hand // corner, the tool tip would disappear because of // calling CancelToolTips. void CMyEdit::OnMouseMove(UINT nFlags, CPoint point) { CRect corner(0, 0, 10, 10); if (corner.PtInRect(point)) CancelToolTips(); CEdit::OnMouseMove(nFlags, point); }
// v7.2 - update 02 - 64-bit - changed from int to UGINTRET - see UG64Bit.h UGINTRET CUGCnrBtn::OnToolHitTest( CPoint point, TOOLINFO *pTI ) const { UNREFERENCED_PARAMETER(point); int col = -1, row = -1; CRect rect; static int lastCol = -2; static int lastRow = -2; if(col != lastCol || row != lastRow) { lastCol = col; lastRow = row; CancelToolTips(); return -1; } // v7.2 - update 03 - added TTF_TRANSPARENT flag. This prevents a // recursive flicker of large tooltips that are forced to // encroach on the mouse position. Reported by Kuerscht pTI->uFlags = TTF_TRANSPARENT | TTF_NOTBUTTON | TTF_ALWAYSTIP |TTF_IDISHWND ; pTI->uId = (UINT_PTR)m_hWnd; pTI->hwnd = (HWND)m_hWnd; pTI->lpszText = LPSTR_TEXTCALLBACK; return 1; }
// v7.2 - update 02 - 64-bit - changed from int to UGINTRET - see UG64Bit.h UGINTRET CUGTopHdg::OnToolHitTest( CPoint point, TOOLINFO *pTI ) const { int col, row; CRect rect; static int lastCol = -2; static int lastRow = -2; if( m_ctrl->m_CUGTopHdg->GetCellFromPoint( &point, &col, &row, &rect ) == UG_SUCCESS) { if(col != lastCol || row != lastRow) { lastCol = col; lastRow = row; CancelToolTips(); return -1; } // v7.2 - update 03 - added TTF_TRANSPARENT flag. This prevents a // recursive flicker of large tooltips that are forced to // encroach on the mouse position. Reported by Kuerscht pTI->uFlags = TTF_TRANSPARENT | TTF_NOTBUTTON | TTF_ALWAYSTIP |TTF_IDISHWND ; pTI->uId = (UINT_PTR)m_hWnd; pTI->hwnd = (HWND)m_hWnd; pTI->lpszText = LPSTR_TEXTCALLBACK; return 1; } return -1; }
BOOL CWnd::_EnableToolTips(BOOL bEnable, UINT nFlag) { ASSERT(nFlag == WF_TOOLTIPS || nFlag == WF_TRACKINGTOOLTIPS); AFX_MODULE_THREAD_STATE* pModuleThreadState = AfxGetModuleThreadState(); CToolTipCtrl* pToolTip = pModuleThreadState->m_pToolTip; if (!bEnable) { // nothing to do if tooltips not enabled if (!(m_nFlags & nFlag)) return TRUE; // cancel tooltip if this window is active if (pModuleThreadState->m_pLastHit == this) CancelToolTips(TRUE); // remove "dead-area" toolbar if (pToolTip->GetSafeHwnd() != NULL) { TOOLINFO ti; memset(&ti, 0, sizeof(TOOLINFO)); ti.cbSize = sizeof(AFX_OLDTOOLINFO); ti.uFlags = TTF_IDISHWND; ti.hwnd = m_hWnd; ti.uId = (UINT_PTR)m_hWnd; pToolTip->SendMessage(TTM_DELTOOL, 0, (LPARAM)&ti); } // success m_nFlags &= ~nFlag; return TRUE; } // if already enabled for tooltips, nothing to do if (!(m_nFlags & nFlag)) { // success AFX_MODULE_STATE* pModuleState = _AFX_CMDTARGET_GETSTATE(); pModuleState->m_pfnFilterToolTipMessage = &CWnd::_FilterToolTipMessage; m_nFlags |= nFlag; } return TRUE; }
int CTRiASView::OnToolHitTest (CPoint point, TOOLINFO* pTI) const { // VERIFY(CView::OnToolHitTest(point, pTI) == -1); if (-1 != CView::OnToolHitTest(point, pTI)) // ChildWindows, die die MFC nicht kennt, verderben alles return -1; if (DEXI_isDrawing() || DEXI_isPrinting() #if defined(_USE_WHEELMOUSE) || m_fIsPanning #endif // _USE_WHEELMOUSE ) return -1; // während des Zeichnens nichts machen int iTool = DEX_GetActiveTool(); if (NUMARROW != iTool && NUMZOOM != iTool && NUMLUPE != iTool) return -1; // nur für Selektionswerkzeug u.ä. { // Testen, ob Objekteigenschaft überhaupt gebraucht wird WObjectProperty ObjProp; HRESULT hr = DEX_GetActObjProp (ObjProp.ppv()); if (FAILED(hr) || !ObjProp) return -1; } // Punktobjekt muß gültig sein if (!m_ptToolTest.IsValid()) { ASSERT(m_ptToolTest.IsValid()); return -1; } LONG lPrevObject = m_lToolTipObject; m_lToolTipObject = 0L; // aktives Objekt rücksetzen CRect rc; GetClientRect(rc); // Y-Koordinate kippen // Koordinaten in DB-Koordinaten umsetzen CPoint pt; pt.x = point.x; pt.y = rc.bottom - rc.top - point.y; DCtoOCEx (pt, &m_ptToolTest); // Device --> Objekt FINDOBJECT FO; CObjRectMaxPriority obj; INITSTRUCT(FO, FINDOBJECT); FO.Pt = pt; FO.iFOMode = FOPunkt|FOKante|FOFlaeche|FOText; FO.eFcn = (FINDOBJECTPROC)FindObjectsForToolTip; FO.pData = (void *)&obj; if (!DEX_FindObjectsFromPoint(FO) || 0L == obj.IsValid()) return -1; // irgend ein Fehler oder nichts gefunden // das Objekt mit der höchsten ZeichenPriorität verwenden m_lToolTipObject = obj.ObjNr(); m_rcToolTipObject = obj.ObjRect(); // wenn ein neues Objekt geliefert wurde, alten Tooltip ausblenden if (lPrevObject != m_lToolTipObject) CancelToolTips(TRUE); // if there were any area's that are not hits, then we could return -1 // immiediately, but in this example, every grid square fires. pTI->rect.left = m_rcToolTipObject.left; pTI->rect.right = m_rcToolTipObject.right; pTI->rect.bottom = rc.bottom - rc.top - m_rcToolTipObject.bottom; pTI->rect.top = rc.bottom - rc.top - m_rcToolTipObject.top; // if using callbacks - store enough info in a static variable so // we can produce the text later on a TTN_NEEDTEXT notification. pTI->lpszText = LPSTR_TEXTCALLBACK; AccessToolHit() = point; // set up the rest of the flags. Not all of these are required, but it seems // safer to supply them. pTI->hwnd = m_hWnd; // window where TTN_NEEDTEXT will be sent. pTI->uFlags = 0; //TTF_ALWAYSTIP ; pTI->cbSize = sizeof TOOLINFO; pTI->uId = (UINT)(m_lToolTipObject | ~0x7fffffffL); // dummy id, so we can tell it's not a standard command // if you want standard tooltip processing, you should // put the command id here // need a return value that is different for every grid square. return int(m_lToolTipObject); }