写一个程序举例说明MFC如何响应鼠标事件?
源代码发我邮箱就最好了,我的邮箱是justin_junlong@yahoo.com.cn 展开
我把关键代码给你贴上,你要是还要源码就留下个邮箱!
void CSDI_StatusBar_1View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString str;
CMainFrame *pMainFrm=(CMainFrame *)AfxGetApp()->m_pMainWnd;
CStatusBar *statusBar=&pMainFrm->m_wndStatusBar;
int y=150-(int)(sin(point.x*3.1516/180)*100);
if(statusBar && fabs(point.y-y)<2.0)
{
str.Format("%d,%d",point.x,point.y);
}
else
{
str.Format("非线上的点");
}
CClientDC dc(this);
CSize sz=dc.GetTextExtent(str);
statusBar->SetPaneInfo(statusBar->CommandToIndex(ID_INDICATOR_COURSOR),ID_INDICATOR_COURSOR,SBPS_NORMAL,sz.cx);
statusBar->SetPaneText(statusBar->CommandToIndex(ID_INDICATOR_COURSOR),str,TRUE);
CView::OnMouseMove(nFlags, point);
}
void CSDI_StatusBar_1View::OnDraw(CDC* pDC)
{
CSDI_StatusBar_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CPoint point[800];
double Y[800];
for(int i=0;i<800;i++)
{
point[i].x=i;
Y[i]=sin(point[i].x*3.1416/180);
point[i].y=(int)(150-Y[i]*100);
}
for(i=0;i<799;i++)
{
pDC->MoveTo(point[i]);
pDC->LineTo(point[i+1]);
}
}
还需要改一下状态栏的窗格才行!