15,980
社区成员




void CPieHasTTDlg::InitTT(UINT radius,CPoint center)
{
m_PieRadius=radius;
m_PieCenter=center;
//
m_TT.Create(this);
// pie
CRect rc1(m_PieCenter.x-m_PieRadius,m_PieCenter.y-m_PieRadius,
m_PieCenter.x+m_PieRadius,m_PieCenter.y+m_PieRadius);
m_TT.AddTool(this,LPSTR_TEXTCALLBACK,&rc1,1);
// horz line
CRect rc2(0,398,255*3,402);
m_TT.AddTool(this,LPSTR_TEXTCALLBACK,&rc2,2);
// oblique line 斜线
CRect rc3(0,0,160,160);
m_TT.AddTool(this,LPSTR_TEXTCALLBACK,&rc3,3);
//
m_TT.Activate(TRUE);
}
3 hit test
void CPieHasTTDlg::MyToolHitTest()
{
static int nLastID=0;
int nCurrentID=-1;
CPoint mouse;
GetCursorPos(&mouse);
ScreenToClient(&mouse);
// horz line test
CRect rc(0,398,255*3,402);
if(rc.PtInRect(mouse))
{
nCurrentID = mouse.x/3;
if(nLastID != nCurrentID)
{
//afxDump << nCurrentID << "::" << nLastID << "\n";
nLastID = nCurrentID;
m_TT.Update();
}
return;
}
// oblique line test
CRect rc1(10,10,160,160);
if(rc1.PtInRect(mouse))
{
nCurrentID = mouse.x;
if(nLastID != nCurrentID)
{
//afxDump << nCurrentID << "::" << nLastID << "\n";
nLastID = nCurrentID;
m_TT.Update();
}
return;
}
// pie test
double dx=mouse.x-m_PieCenter.x;
double dy=mouse.y-m_PieCenter.y;
if(sqrt(dx*dx+dy*dy)<=m_PieRadius)
{
double angle=atan(fabs(dy)/fabs(dx))*DEG;// < 0 y axis up
if (dy<0 && dx>0) angle=atan(fabs(dy)/fabs(dx))*DEG;
else if (dy<0 && dx<0) angle=90+atan(fabs(dx)/fabs(dy))*DEG;
else if (dy>0 && dx<0) angle=180+atan(fabs(dy)/fabs(dx))*DEG;
else angle=270+atan(fabs(dx)/fabs(dy))*DEG;
//
nCurrentID = int(angle/30.0);
if(nLastID != nCurrentID)
{
// afxDump << nCurrentID << "::" << nLastID << "\n";
nLastID = nCurrentID;
m_TT.Update();
}
}
}
4 hit test 调用
void CPieHasTTDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
MyToolHitTest();
CDialog::OnMouseMove(nFlags, point);
}
5 event map
afx_msg BOOL OnToolTipText(UINT /*id*/, NMHDR * pNMHDR, LRESULT * pResult);
//
ON_NOTIFY_EX(TTN_NEEDTEXT,0,OnToolTipText)
6 tip text
//
BOOL CPieHasTTDlg::OnToolTipText(UINT /*id*/, NMHDR * pNMHDR, LRESULT * pResult)
{
TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pNMHDR;
UINT nID = pNMHDR->idFrom;
char TipNow[80];
CPoint mouse;
GetCursorPos(&mouse);
ScreenToClient(&mouse);
// idFrom is actually the HWND of the 1000=IDC_TREE
if(nID==1)
{// pie
double dx=mouse.x-m_PieCenter.x;
double dy=mouse.y-m_PieCenter.y;
if(sqrt(dx*dx+dy*dy)<=m_PieRadius)
{
double angle=atan(fabs(dy)/fabs(dx))*DEG;// < 0 y axis up
if (dy<0 && dx>0) angle=atan(fabs(dy)/fabs(dx))*DEG;
else if (dy<0 && dx<0) angle=90+atan(fabs(dx)/fabs(dy))*DEG;
else if (dy>0 && dx<0) angle=180+atan(fabs(dy)/fabs(dx))*DEG;
else angle=270+atan(fabs(dx)/fabs(dy))*DEG;
//
sprintf(TipNow,"Inside Pie: %d",int(angle/30.0));
//afxDump << TipNow << "\n";
pTTT->lpszText = TipNow;
}
return TRUE;// ! for win7
}
else if(nID==2)
{// horz line
sprintf(TipNow,"mouseX: %d",mouse.x/3);
// afxDump << TipNow << "\n";
pTTT->lpszText = TipNow;
return TRUE;// ! for win7
}
else if(nID==3)
{// obligue line
CDC *pDC = GetDC();
COLORREF color=pDC->GetPixel(mouse.x,mouse.y);
ReleaseDC(pDC);
if(color==RGB(0,0,255))// blue
{
sprintf(TipNow,"X: %d,Y: %d",mouse.x,mouse.y);
// afxDump << TipNow << "\n";
pTTT->lpszText = TipNow;
return TRUE;// ! for win7
}
}
//
return FALSE;// we didn't handle the message,
}
7 event relay
BOOL CPieHasTTDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if((IsWindow(m_hWnd)) && (pMsg->message==WM_MOUSEMOVE))
m_TT.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
你只要 oblique line 部分, 斜线颜色 请 改为绿 (现在是 蓝)