chartwnd.cpp
来自「The application wizard has created this 」· C++ 代码 · 共 552 行 · 第 1/2 页
CPP
552 行
}
return NULL;
}
/************************************************************************************************/
/* */
/* Function: CChartWnd::_ExecuteDoubleClick() */
/* */
/* Purpose : sends a message and a data point to the parent if the point lies within the data */
/* point */
/* */
/* Inputs : CPoint& Point -> double click point */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 12JUN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 12JUN02 initial version */
/* */
/************************************************************************************************/
void CChartWnd::_ExecuteDoubleClick(UINT nFlags, CPoint& Point) {
CDataPoint* pDataPoint = _DataPointHitTest(Point);
if (pDataPoint)
GetParent()->SendMessage(WM_LBUTTONDBLCLK_DATA_POINT, (WPARAM)pDataPoint, NULL);
else {
CWnd* pWnd = GetParent();
if (pWnd) {
//convert the point coordinate to that of the parents
ClientToScreen(&Point);
pWnd->ScreenToClient(&Point);
LPARAM lParam(Point.y<<16);
lParam += Point.x;
pWnd->SendMessage(WM_LBUTTONDBLCLK, (WPARAM)nFlags, lParam);
}
}
return;
}
void CChartWnd::OnLButtonDblClk(UINT nFlags, CPoint point) {
_ExecuteDoubleClick(nFlags, point);
return;
}
void CChartWnd::OnLButtonDown(UINT nFlags, CPoint point) {
CChartWndBase::OnLButtonDown(nFlags, point);
if (TYPE_LINE==m_eChartType||TYPE_PIE==m_eChartType)
return;
if (MK_CONTROL&nFlags)
m_bRotate = TRUE;
return;
}
void CChartWnd::OnLButtonUp(UINT nFlags, CPoint point) {
CChartWndBase::OnLButtonUp(nFlags, point);
m_bRotate = FALSE;
return;
}
void CChartWnd::OnMouseMove(UINT nFlags, CPoint point) {
CChartWndBase::OnMouseMove(nFlags, point);
if (TYPE_STRIP_CHART==m_eChartType||
TYPE_STRIP_CHART_FILLED==m_eChartType)
return;
if (SHOW_POPUP_WINDOWS&m_eStyle&&!m_bRotate)
_DisplayPopupWindow(point);
else
m_PopupWindow.ShowWindow(SW_HIDE);
if (!(MK_CONTROL&nFlags)||!(MK_LBUTTON&nFlags))
m_bRotate = FALSE;
if (!m_bRotate)
return;
CRect Rect;
GetClientRect(&Rect);
double dHorSlope = 90./Rect.Width();
double dVerSlope = 90./Rect.Height();
if (TYPE_ROTATED_PIE==m_eChartType) {
SetPieChartHeight(dHorSlope*point.x);
SetPieChartElevation(dVerSlope*point.y);
}
else {
SetHorzRotation(dHorSlope*point.x);
SetVertRotation(dVerSlope*point.y);
}
GetParent()->SendMessage(CHART_UPDATE_WINDOW);
return;
}
/************************************************************************************************/
/* */
/* Function: CChartWnd::_DisplayPopupWindow() */
/* */
/* Purpose : shows/hides the popup window for a specific data item based on the location of */
/* the mouse pointer */
/* */
/* Inputs : CPoint& Point -> point of the mouse cursor */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 15MAY02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 15MAY02 initial version */
/* Scott Pelger 28JUN02 preventing the popup window from being clipped */
/* */
/************************************************************************************************/
void CChartWnd::_DisplayPopupWindow(CPoint& Point) {
CDataPoint* pDataPoint = _DataPointHitTest(Point);
if (pDataPoint) {
if (!m_PopupWindow.IsWindowVisible())
m_PopupWindow.ShowWindow(SW_SHOW);
if (m_pCurrentDataPoint!=pDataPoint) {
CRect Rect;
pDataPoint->m_PopupRegion.GetRgnBox(&Rect);
CString WindowText("MessageTextHere");
GetParent()->SendMessage(WM_GET_POPUP_TEXT, (WPARAM)pDataPoint, (LPARAM)&WindowText);
m_PopupWindow.SetWindowText(WindowText);
CRect WindowRect(0, 0, 0, 0);
m_PopupWindow.GetWindowRect(WindowRect);
if (!m_pCurrentDataPoint)
m_PopupWindow.ShowWindow(SW_SHOW);
int nX, nY;
static nD(0);
if (TYPE_PIE==m_eChartType||
TYPE_ROTATED_PIE==m_eChartType) {
//using WIN coordinates the m_PopupRegion point lies in a quadrant relative to the center
//point of the bounding rect for the pie chart. x >= 0 if the point lies directly above/below
//or to the right of the center point, y >= 0 if the point lies directly left/right or
//below the center point
CPoint Point = Rect.TopLeft();
if (Rect.left>0)
nX = Rect.left - WindowRect.Width();
else
nX = -Rect.left;
if (Rect.top>0)
nY = Rect.top - WindowRect.Height();
else
nY = -Rect.top;
}
else {
switch (m_eStyle&0x1F) {
case SHOW_POPUP_WINDOWS_TL :
nX = Rect.left;
nY = Rect.top;
break;
case SHOW_POPUP_WINDOWS_BL :
nX = Rect.left;
nY = Rect.bottom-WindowRect.Height();
break;
case SHOW_POPUP_WINDOWS_BR :
nX = Rect.right-WindowRect.Width();
nY = Rect.bottom-WindowRect.Height();
break;
case SHOW_POPUP_WINDOWS_TR :
nX = Rect.right-WindowRect.Width();
nY = Rect.top;
break;
default /*CENTERED*/ :
nX = Rect.CenterPoint().x-WindowRect.Width()/2;
nY = Rect.CenterPoint().y-WindowRect.Height()/2;
}
}
//don't allow the popup window to be clipped off the screen
GetClientRect(&Rect);
if (Rect.left>nX)
nX += 10+Rect.left-nX;
if (Rect.top>nY)
nY += 10+Rect.top-nY;
if (Rect.right<nX+WindowRect.Width())
nX -= 10+nX+WindowRect.Width()-Rect.right;
if (Rect.right<nY+WindowRect.Height())
nY -= 10+nY+WindowRect.Height()-Rect.bottom;
m_PopupWindow.MoveWindow(nX, nY, WindowRect.Width(), WindowRect.Height());
m_pCurrentDataPoint = pDataPoint;
}
}
else {
m_PopupWindow.ShowWindow(SW_HIDE);
m_pCurrentDataPoint = NULL;
}
return;
}
int CChartWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) {
if (CChartWndBase::OnCreate(lpCreateStruct) == -1)
return -1;
m_PopupWindow.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, ID_CHART+10);
m_PopupWindow.ShowWindow(SW_HIDE);
m_PopupWindow.SetWindowColor(RGB(255, 255, 198));
m_PopupWindow.SetFont(10, "Arial", 0);
return 0;
}
void CChartWnd::OnSize(UINT nType, int cx, int cy) {
CChartWndBase::OnSize(nType, cx, cy);
m_bScrolling = FALSE;
if (m_rcClientRect==CRect(0, 0, 0, 0))
return;
DrawChart();
return;
}
/************************************************************************************************/
/* */
/* Function: CChartWnd::SetChartType() */
/* */
/* Purpose : sets the type of the chart */
/* */
/* Inputs : enum CHART_TYPE eChartType -> chart type */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 15MAY02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 15MAY02 initial version */
/* */
/************************************************************************************************/
void CChartWnd::SetChartType(enum CHART_TYPE eChartType) {
m_eChartType = m_DataSeriesArray.SetChartType(eChartType);
if (TYPE_STRIP_CHART_FILLED==m_eChartType){
m_DataSeriesArray.PrepareStripChartForScrolling(&m_bScrolling, &m_bRefreshDisplayCompletely, &m_GraphBitmap);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?