ToolTipHeaderCtrl.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:3k
源码类别:
P2P编程
开发平台:
Visual C++
- // ToolTipHeaderCtrl.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "ToolTipHeaderCtrl.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CToolTipHeaderCtrl
- CToolTipHeaderCtrl::CToolTipHeaderCtrl()
- {
- }
- CToolTipHeaderCtrl::~CToolTipHeaderCtrl()
- {
- }
- BEGIN_MESSAGE_MAP(CToolTipHeaderCtrl, CHeaderCtrl)
- //{{AFX_MSG_MAP(CToolTipHeaderCtrl)
- ON_WM_MOVE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CToolTipHeaderCtrl message handlers
- //This function called form DataTipListCtrl's InsertColumn() overriden function.
- int CToolTipHeaderCtrl::AddToolTip(int nCol, LPCTSTR lpszTip)
- {
- RECT rcColumn;
- GetItemRect(nCol, &rcColumn);
- CRect rectTool = rcColumn;
- return m_Tooltip.AddTool(this, lpszTip, (LPCRECT)rectTool, nCol+1);
- }
- // This function called when scrolling or column resizing.
- void CToolTipHeaderCtrl::RecalcToolRect()
- {
- // This prevent debug assertion fail on last WM_MOVE on app close.
- if(!::IsWindow(m_Tooltip.m_hWnd))
- return;
- CDC *pDC = GetDC();
- CFont *pOldFont = (CFont*)pDC->SelectObject(GetFont());
- HDITEM hdCol;
- hdCol.mask = HDI_WIDTH | HDI_FORMAT;
- RECT rcColumn;
- GetClientRect(&rcColumn);
- // Get scroll position
- int nHScrollPos = GetParent()->GetScrollPos(SB_HORZ);
- rcColumn.left -= nHScrollPos;
- rcColumn.right -= nHScrollPos;
- RECT rcList;
- GetParent()->GetClientRect(&rcList);
- CRect rectTool;
- int numcol = GetItemCount();
- for(int col=0; col<numcol; col++)
- {
- // Get column string extent
- GetItem(col, &hdCol);
- rcColumn.right = rcColumn.left + LOWORD(hdCol.cxy);
- // Calculate ToolTip hover rectangle
- rectTool = rcColumn;
- /*
- if(cxText > rectTool.Width()-12)
- {
- if(rectTool.Width() > 24)
- {
- rectTool.left += 8;
- rectTool.right -= 8;
- }
- }
- else if(rcText.left < 0)
- {
- rectTool = rcColumn;
- if(rectTool.Width() > 24)
- rectTool.right -= 8;
- }
- else if(rcText.right > rcList.right)
- {
- rectTool = rcColumn;
- if(rectTool.Width() > 24)
- rectTool.left += 8;
- }
- else
- rectTool.SetRectEmpty();
- //*/
- rectTool.OffsetRect(nHScrollPos, 0);
- m_Tooltip.SetToolRect(this, col+1, &rectTool);
- rcColumn.left = rcColumn.right;
- }
- pDC->SelectObject(pOldFont);
- ReleaseDC(pDC);
- }
- void CToolTipHeaderCtrl::PreSubclassWindow()
- {
- // TODO: Add your specialized code here and/or call the base class
- m_Tooltip.Create(this);
- m_Tooltip.Activate(TRUE);
- int iret = m_Tooltip.SetMaxTipWidth(500);
- iret = m_Tooltip.GetMaxTipWidth();
- CHeaderCtrl::PreSubclassWindow();
- }
- BOOL CToolTipHeaderCtrl::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: Add your specialized code here and/or call the base class
- m_Tooltip.RelayEvent(pMsg);
- return CHeaderCtrl::PreTranslateMessage(pMsg);
- }
- void CToolTipHeaderCtrl::OnMove(int x, int y)
- {
- CHeaderCtrl::OnMove(x, y);
- // TODO: Add your message handler code here
- RecalcToolRect();
- }