鱼C论坛

 找回密码
 立即注册
查看: 2213|回复: 6

[已解决]VS2010+C++写的炒股软件如何添加参数

[复制链接]
发表于 2019-7-4 17:56:58 | 显示全部楼层 |阅读模式
50鱼币
本帖最后由 stone1005 于 2019-7-4 18:00 编辑

原来的炒股软件需要根据顶背离和底背离的运算计算出确认值,并显示到软件界面中,请高手帮忙看下,具体如下:
原界面:
03.png
需要达到的效果:
04.png
鼠标移动到波形曲线上点击后也要显示确认值:
06.png
代码如下:
  1. // ViewGraph.cpp : 实现文件
  2. // 显示股指分析图

  3. #include "stdafx.h"
  4. #include "WisdomClient.h"
  5. #include "ViewGraph.h"
  6. #include "afxdialogex.h"
  7. #pragma comment(lib, "gdiplus.lib")

  8. // CViewGraph 对话框;

  9. IMPLEMENT_DYNAMIC(CViewGraph, CDialog)

  10. CViewGraph::CViewGraph(CWnd* pParent /*=NULL*/)
  11.         : CDialog(CViewGraph::IDD, pParent), mTextOffset(0), mDown(false), mUpMoveing(false), mDownMoveing(false), mDirtyData(false), mBmpW(-1000), mBmpH(0), mBmp(NULL), mBmp2(NULL), mShowMouseLine(false)
  12. {
  13.         AddHandlerWnd(this);
  14.         GdiplusStartup(&mGdiplusToken, &mGdiplusStartupInput, NULL);
  15. }

  16. CViewGraph::~CViewGraph()
  17. {
  18.         DelHandlerWnd(this);
  19.         GdiplusShutdown(mGdiplusToken);
  20. }

  21. void CViewGraph::DoDataExchange(CDataExchange* pDX)
  22. {
  23.         CDialog::DoDataExchange(pDX);
  24. }


  25. BEGIN_MESSAGE_MAP(CViewGraph, CDialog)
  26.         ON_WM_PAINT()
  27.         ON_WM_SIZE()
  28. END_MESSAGE_MAP()


  29. // CViewGraph 消息处理程序;

  30. BOOL CViewGraph::OnInitDialog()
  31. {
  32.         CDialog::OnInitDialog();

  33.         ping_time_ = 0;
  34.         msg_height_ = 436;

  35.         Gdiplus::Color curveColor[CHART_COUNT] = {
  36.                 Color(255, 255, 255),//白色
  37.                 Color(255, 255, 0), //黄色
  38.                 Color(62, 72, 205),//白色
  39.                 Color(255, 0, 255) //紫红色
  40.         };

  41.         lastPlaySoundTime = 0;
  42.         for (int32 i = 0; i < CHART_COUNT; ++i)
  43.         {
  44.                 mCurveChart[i].SetCurveStyle(curveColor[i], Color(255, 255, 255));
  45.         }

  46.         mCurveChart[0].SetDrawLine(true, false);

  47.         RECT rec;
  48.         GetParent()->GetClientRect(&rec);
  49.         MoveWindow(&rec);

  50.         ::SetTimer(m_hWnd, 10, 1000 / 30, NULL);

  51.         ::SetTimer(m_hWnd, 11, 1000, NULL);

  52.         return TRUE;  // return TRUE unless you set the focus to a control
  53. }

  54. void CViewGraph::OnPaint()
  55. {
  56.         CPaintDC dc(this);

  57.         //onPaint();
  58. }

  59. void CViewGraph::onPaint()
  60. {
  61.         RectF rectf;
  62.         CString strTmp;

  63.         RECT rec = {0};
  64.         GetClientRect(&rec);

  65.         CDC dcMemory;
  66.         CDC* pDc = GetWindowDC();

  67.         dcMemory.CreateCompatibleDC(pDc);

  68.         FontFamily fontFamily(L"Arial");
  69.         {
  70.                 if ( mBmp == NULL || mBmpW != rec.right || mBmpH != rec.bottom)
  71.                 {
  72.                         delete mBmp;
  73.                         delete mBmp2;

  74.                         mBmp = new CBitmap();
  75.                         mBmp2 = new CBitmap();

  76.                         mBmp->CreateCompatibleBitmap(pDc, rec.right, rec.bottom);
  77.                         mBmp2->CreateCompatibleBitmap(pDc, rec.right, rec.bottom);

  78.                         mBmpW = rec.right;
  79.                         mBmpH = rec.bottom;
  80.                 }

  81.                 dcMemory.SelectObject(mBmp);

  82.                 if ( mDirtyData == true || mShowMouseLine == true )
  83.                 {
  84.                         mDirtyData = false;

  85.                         Graphics g(dcMemory.m_hDC);

  86.                         SolidBrush backBrush(Color(0, 0, 0));

  87.                         //清除背景;
  88.                         g.FillRectangle(&backBrush, 0, 0, rec.right, rec.bottom);

  89.                         tm t;
  90.                         time_t tt = time(NULL);
  91.                         localtime_s(&t, &tt);

  92.                         //画时间刻度;
  93.                         RectF rectf;
  94.                         SolidBrush brush_255_255_255(Color(255, 255, 255));
  95.                         double cellWidth = mCurveChart[0].GetCellWidth();
  96.                         Gdiplus::Font font_12(&fontFamily, 12, FontStyleRegular, UnitPixel);
  97.                         //strTmp.Format(_T("%02d/%02d %02d:%02d"), t.tm_mon + 1, t.tm_mday, 9, 30);
  98.                         //g.DrawString(strTmp.GetBuffer(), -1, &font_12, PointF(-1, rec.bottom - GRAPH_BOTTOM + 4), &brush_255_255_255);

  99.                         //计算时间点字符串的宽度和高度;
  100.                         //strTmp.Format(_T("00:00"));
  101.                         //g.MeasureString(strTmp.GetBuffer(), -1, &font_12, PointF(0, 0), &rectf);

  102.                         double timeSpace = (rec.right - LEFT_DISTANCE - MESSAGE_WIDTH) / 2 / 4;

  103.                         ////上午;
  104.                         //for (int i = 0; i < 4; i++)
  105.                         //{
  106.                         //        strTmp.Format(_T("%02d:%02d"), 10 + (i / 2 ), i % 2 == 0 ? 0 : 30);
  107.                         //        g.DrawString(strTmp.GetBuffer(), -1, &font_12, PointF(LEFT_DISTANCE + timeSpace * (i + 1) - rectf.Width / 2, rec.bottom - GRAPH_BOTTOM + 4), &brush_255_255_255);
  108.                         //}
  109.                         ////下午;
  110.                         //for (int i = 1; i < 5; i++)
  111.                         //{
  112.                         //        strTmp.Format(_T("%02d:%02d"), 13 + (i / 2 ), i % 2 == 0 ? 0 : 30);
  113.                         //        g.DrawString(strTmp.GetBuffer(), -1, &font_12, PointF(LEFT_DISTANCE + timeSpace * (3 + i + 1) - rectf.Width / 2, rec.bottom - GRAPH_BOTTOM + 4), &brush_255_255_255);
  114.                         //}

  115.                         //画出曲线;
  116.                         for (int32 i = 0; i < CHART_COUNT; ++i)
  117.                         {
  118.                                 mCurveChart[i].Paint(g, mCurveChart[0]);
  119.                         }

  120.                         ////画出中线;
  121.                         //{
  122.                         //        Pen splitPen(Color(255, 50, 50), 1);

  123.                         //        int32 splitPosX = LEFT_DISTANCE + timeSpace * 4;// + 4;

  124.                         //        g.DrawLine(&splitPen, splitPosX, 0, splitPosX, rec.bottom - GRAPH_BOTTOM + 2);
  125.                         //}

  126.                         //显示指标文字;
  127.                         {
  128.                                 POINT pos;
  129.                                 GetCursorPos(&pos);
  130.                                 ScreenToClient(&pos);

  131.                                 int32 index = mCurveChart[0].GetLastIndex1();

  132.                        
  133.                                
  134.                                 if ( index != -1 )
  135.                                 {
  136.                                         //SolidBrush brush2(Color(255, 253, 79));
  137.                                         if (mShowMouseLine)
  138.                                         {
  139.                                                 int32 nIndex = mCurveChart[0].GetIndex((int32)pos.x);
  140.                                                 int32 nLastIndex = mCurveChart[0].GetLastIndex1();

  141.                                                 if (nIndex > -1 && nIndex <= nLastIndex)
  142.                                                 {
  143.                                                         index = nIndex;
  144.                                                 }
  145.                                         }

  146.                                         strTmp.Format(_T("股指期货:%.1f"), mCurveChart[0].GetRecordData1(index));

  147.                                         g.DrawString(strTmp.GetBuffer(), -1, &font_12, PointF(mCurveChart[0].GetX() + LEFT_DISTANCE, mCurveChart[0].GetY()+ 2), mCurveChart[0].GetLineBrush1());

  148.                                        

  149.                                         if (index != 0)
  150.                                         {
  151.                                                 strTmp.Format(_T("力度:%.3f%s"), mCurveChart[0].GetRecordData2(index), index <= 0 ? _T("↑") : (mCurveChart[1].GetRecordData2(index) > mCurveChart[1].GetRecordData2(index - 1) ? _T("↑") : _T("↓")));
  152.                                                 g.DrawString(strTmp.GetBuffer(), -1, &font_12, PointF(mCurveChart[0].GetX() + LEFT_DISTANCE + 180, mCurveChart[0].GetY()+ 2), mCurveChart[0].GetLineBrush2());
  153.                                                 //xiugai
  154.                                            //g.DrawString("-300", -1, &font_12, PointF(mCurveChart[0].GetX() + LEFT_DISTANCE + 220, mCurveChart[0].GetY()+ 2),mCurveChart[0].GetLineBrush2());
  155.                                         }
  156.                                 }

  157.                                 index = mCurveChart[1].GetLastIndex1();
  158.                                 if ( index != -1 )
  159.                                 {
  160.                                         //SolidBrush brush2(Color(255, 255, 255));
  161.                                         if (mShowMouseLine)
  162.                                         {
  163.                                                 int32 nIndex = mCurveChart[0].GetIndex((int32)pos.x);
  164.                                                 int32 nLastIndex = mCurveChart[0].GetLastIndex1();

  165.                                                 if (nIndex > -1 && nIndex <= nLastIndex)
  166.                                                 {
  167.                                                         index = nIndex;
  168.                                                 }
  169.                                         }

  170.                                         strTmp.Format(_T("指标一:%.0f"), mCurveChart[1].GetRecordData1(index));
  171.                                        
  172.                                         g.DrawString(strTmp.GetBuffer(), -1, &font_12, PointF(mCurveChart[1].GetX() + LEFT_DISTANCE, mCurveChart[1].GetY()+ 2), mCurveChart[1].GetLineBrush1());

  173.                                         //index = mCurveChart[1].GetLastIndex2();
  174.                                         if ( index != 0 )
  175.                                         {
  176.                                                 //SolidBrush brush3(Color(200, 37, 200));
  177.                                                 strTmp.Format(_T("力度:%.3f%s"), mCurveChart[1].GetRecordData2(index), index <= 0 ? _T("↑") : (mCurveChart[1].GetRecordData2(index) > mCurveChart[1].GetRecordData2(index - 1) ? _T("↑") : _T("↓")));
  178.                                                 g.DrawString(strTmp.GetBuffer(), -1, &font_12, PointF(mCurveChart[1].GetX() + LEFT_DISTANCE + 180, mCurveChart[1].GetY()+ 2), mCurveChart[1].GetLineBrush2());
  179.                                         }
  180.                                 }

  181.                                 index = mCurveChart[2].GetLastIndex1();
  182.                                 if ( index != -1 )
  183.                                 {
  184.                                         //SolidBrush brush2(Color(255, 255, 255));
  185.                                         if (mShowMouseLine)
  186.                                         {
  187.                                                 int32 nIndex = mCurveChart[0].GetIndex((int32)pos.x);
  188.                                                 int32 nLastIndex = mCurveChart[0].GetLastIndex1();

  189.                                                 if (nIndex > -1 && nIndex <= nLastIndex)
  190.                                                 {
  191.                                                         index = nIndex;
  192.                                                 }
  193.                                         }

  194.                                         strTmp.Format(_T("指标二:%.0f"), mCurveChart[2].GetRecordData1(index));
  195.                                         g.DrawString(strTmp.GetBuffer(), -1, &font_12, PointF(mCurveChart[2].GetX() + LEFT_DISTANCE, mCurveChart[2].GetY()+ 2), mCurveChart[2].GetLineBrush1());

  196.                                         //index = mCurveChart[2].GetLastIndex2();
  197.                                         if ( index != -1 )
  198.                                         {
  199.                                                 //SolidBrush brush3(Color(200, 37, 200));
  200.                                                 strTmp.Format(_T("力度:%.3f%s"), mCurveChart[2].GetRecordData2(index), index <= 0 ? _T("↑") : (mCurveChart[2].GetRecordData2(index) > mCurveChart[2].GetRecordData2(index - 1) ? _T("↑") : _T("↓")));
  201.                                                 g.DrawString(strTmp.GetBuffer(), -1, &font_12, PointF(mCurveChart[2].GetX() + LEFT_DISTANCE + 180, mCurveChart[2].GetY()+ 2), mCurveChart[2].GetLineBrush2());
  202.                                         }
  203.                                 }

  204.                                 index = mCurveChart[3].GetLastIndex1();
  205.                                 if ( index != -1 )
  206.                                 {
  207.                                         //SolidBrush brush2(Color(255, 255, 255));
  208.                                         if (mShowMouseLine)
  209.                                         {
  210.                                                 int32 nIndex = mCurveChart[0].GetIndex((int32)pos.x);
  211.                                                 int32 nLastIndex = mCurveChart[0].GetLastIndex1();

  212.                                                 if (nIndex > -1 && nIndex <= nLastIndex)
  213.                                                 {
  214.                                                         index = nIndex;
  215.                                                 }
  216.                                         }

  217.                                         strTmp.Format(_T("指标三:%.0f"), mCurveChart[3].GetRecordData1(index));
  218.                                         g.DrawString(strTmp.GetBuffer(), -1, &font_12, PointF(mCurveChart[3].GetX() + LEFT_DISTANCE, mCurveChart[3].GetY()+ 2), mCurveChart[3].GetLineBrush1());

  219.                                         //index = mCurveChart[3].GetLastIndex2();
  220.                                         if ( index != -1 )
  221.                                         {
  222.                                                 //SolidBrush brush3(Color(200, 37, 200));
  223.                                                 strTmp.Format(_T("力度:%.3f%s"), mCurveChart[3].GetRecordData2(index), index <= 0 ? _T("↑") : (mCurveChart[3].GetRecordData2(index) > mCurveChart[3].GetRecordData2(index - 1) ? _T("↑") : _T("↓")));
  224.                                                 g.DrawString(strTmp.GetBuffer(), -1, &font_12, PointF(mCurveChart[3].GetX() + LEFT_DISTANCE + 180, mCurveChart[3].GetY()+ 2), mCurveChart[3].GetLineBrush2());
  225.                                         }
  226.                                 }
  227.                         }



  228.                         //专家点评;
  229.                         {
  230.                                 SolidBrush brush255_255_255(Color(255, 255, 255));
  231.                                 SolidBrush brush255_50_50(Color(255, 25, 25));
  232.                                 SolidBrush brush255_0_255(Color(255, 0, 255));
  233.                                 Gdiplus::Font font(&fontFamily, 24, FontStyleBold, UnitPixel);
  234.                                 Gdiplus::Font font2(&fontFamily, 12, FontStyleRegular, UnitPixel);
  235.                                
  236.                                 RectF rectf;
  237.                                 strTmp.Format(_T("专家点评"));
  238.                                 g.MeasureString(strTmp.GetBuffer(), -1, &font, PointF(0, 0), &rectf);//计算时间点字符串的宽度和高度;
  239.                                 g.DrawString(L"专家点评", -1, &font, PointF(rec.right - MESSAGE_WIDTH + (MESSAGE_WIDTH - rectf.Width) / 2, 15 ), &brush255_255_255);

  240.                                 Pen pen255_0_0(Color(255, 0, 0), 3);
  241.                                 strTmp.Format(_T("专家意见,仅供参考"));
  242.                                 g.MeasureString(strTmp.GetBuffer(), -1, &font2, PointF(0, 0), &rectf);//计算时间点字符串的宽度和高度;
  243.                                 g.DrawString(L"专家意见,仅供参考", -1, &font2, PointF(rec.right - MESSAGE_WIDTH + (MESSAGE_WIDTH - rectf.Width) / 2, 42), &brush255_0_255);

  244.                                 g.DrawLine(&pen255_0_0, rec.right - MESSAGE_WIDTH, 60, rec.right, 60);

  245.                                 mUpMoveing = mDownMoveing = false;

  246.                                 //150,437;
  247.                                 int n = 0;
  248.                                 int nCount = 0;
  249.                                
  250.                                 //FOR_LIST_CONST(wstring, it, mBroadcastMsg)
  251.                                 for (list<wstring>::reverse_iterator it = mBroadcastMsg.rbegin(); it != mBroadcastMsg.rend(); ++it)
  252.                                 {
  253.                                         n++;

  254.                                         RectF rectf;

  255.                                         const wstring& msg = *it;

  256.                                         list<wstring> strlist;

  257.                                         wchar_t buff[1024] = {0};

  258.                                         int nOffset = 0;

  259.                                         int nLen = 1;

  260.                                         for (int i = 0; i < msg.length(); i++)
  261.                                         {
  262.                                                 g.MeasureString(msg.c_str() + nOffset, nLen, &font2, PointF(0, 0), &rectf);

  263.                                                 if ( rectf.Width > (MESSAGE_WIDTH - 15) )
  264.                                                 {
  265.                                                         memset(buff, 0, sizeof(buff));

  266.                                                         memcpy_s(buff, sizeof(buff), msg.c_str() + nOffset, nLen * sizeof(wchar_t));

  267.                                                         strlist.push_back(buff);

  268.                                                         nOffset += nLen;

  269.                                                         nLen = 1;
  270.                                                 }
  271.                                                 else
  272.                                                 {
  273.                                                         nLen++;
  274.                                                 }
  275.                                         }

  276.                                         if ( nLen != 0 )
  277.                                         {
  278.                                                 memset(buff, 0, sizeof(buff));

  279.                                                 memcpy_s(buff, sizeof(buff), msg.c_str() + nOffset, (msg.length() - nOffset) * sizeof(wchar_t));

  280.                                                 strlist.push_back(buff);

  281.                                                 nLen = 0;
  282.                                         }


  283.                                         CString str;

  284.                                         //画文字;
  285.                                         int idx = 0;
  286.                                         FOR_LIST_CONST(wstring, it2, strlist)
  287.                                         {
  288.                                                 wstring text = *it2;

  289.                                                 if (idx == 0)
  290.                                                 {//画消息开头后的日期;
  291.                                                         int index = text.find_first_of('\n');
  292.                                                         wstring wtemp = text.substr(0, index);
  293.                                                         text = text.substr(text.find_first_of('\n') + 1);
  294.                                                         if ( (MESSAGE_TOP + nCount - mTextOffset) >= MESSAGE_TOP && (MESSAGE_TOP + nCount - mTextOffset) <= MESSAGE_TOP + msg_height_ )
  295.                                                         {
  296.                                                                 g.MeasureString(wtemp.c_str(), wtemp.length(), &font2, PointF(0, 0), &rectf);
  297.                                                                 g.DrawString(wtemp.c_str(), wtemp.length(), &font2, PointF(  rec.right - MESSAGE_WIDTH + 5, MESSAGE_TOP + nCount - mTextOffset ), &brush255_255_255);
  298.                                                         }
  299.                                                         else
  300.                                                         {
  301.                                                                 if ( (MESSAGE_TOP + nCount - mTextOffset) < MESSAGE_TOP && n == 1 )
  302.                                                                 {
  303.                                                                         mDownMoveing = true;
  304.                                                                 }

  305.                                                                 if ( (MESSAGE_TOP + nCount - mTextOffset) > MESSAGE_TOP + msg_height_ )
  306.                                                                 {
  307.                                                                         mUpMoveing = true;
  308.                                                                 }
  309.                                                         }
  310.                                                         nCount += rectf.Height;
  311.                                                 }

  312.                                                 if ( (MESSAGE_TOP + nCount - mTextOffset) >= MESSAGE_TOP && (MESSAGE_TOP + nCount - mTextOffset) <= MESSAGE_TOP + msg_height_ )
  313.                                                 {
  314.                                                         g.DrawString(text.c_str(), text.length(), &font2, PointF(  rec.right - MESSAGE_WIDTH + 5, MESSAGE_TOP + nCount - mTextOffset ), &brush255_50_50);
  315.                                                 }
  316.                                                 else
  317.                                                 {
  318.                                                         if ( (MESSAGE_TOP + nCount - mTextOffset) < MESSAGE_TOP && n == 1 )
  319.                                                         {
  320.                                                                 mDownMoveing = true;
  321.                                                         }

  322.                                                         if ( (MESSAGE_TOP + nCount - mTextOffset) > MESSAGE_TOP + msg_height_ )
  323.                                                         {
  324.                                                                 mUpMoveing = true;
  325.                                                         }
  326.                                                 }
  327.                                                 g.MeasureString(text.c_str(), text.length(), &font2, PointF(0, 0), &rectf);
  328.                                                 nCount += rectf.Height;

  329.                                                 idx++;
  330.                                         }

  331.                                         nCount += 12;
  332.                                 }
  333.                         }
  334.                 }
  335.         }

  336.         //画十字交叉线;
  337.         if (mShowMouseLine == true)
  338.         {
  339.                 POINT pos;
  340.                 GetCursorPos(&pos);
  341.                 ScreenToClient(&pos);

  342.                 if ( pos.x >= LEFT_DISTANCE && pos.x <= (mCurveChart[0].GetX() + mCurveChart[0].GetWidth()))
  343.                 {
  344.                         CDC dcMemory2;
  345.                         dcMemory2.CreateCompatibleDC(pDc);
  346.                         CBitmap Bmp2;
  347.                         Bmp2.CreateCompatibleBitmap(pDc, rec.right, rec.bottom);
  348.                         dcMemory2.SelectObject(&Bmp2);
  349.                         dcMemory2.BitBlt(0, 0, rec.right, rec.bottom, &dcMemory, 0, 0, SRCCOPY);
  350.                         Graphics g(dcMemory2.m_hDC);
  351.                         SolidBrush brush(Color(255, 255, 255));
  352.                         SolidBrush brush2(Color(255, 20, 20));
  353.                         Gdiplus::Font font(&fontFamily, 24, FontStyleBold, UnitPixel);
  354.                         Gdiplus::Font font2(&fontFamily, 12, FontStyleRegular, UnitPixel);
  355.                         Pen pen1(Color(0x50, 0x50, 0x50), 1);
  356.                         Pen penpos(Color(255, 255, 255), 5);

  357.                         //画鼠标跟随线;
  358.                         g.DrawLine(&pen1, LEFT_DISTANCE + 1, pos.y, mCurveChart[0].GetX() + mCurveChart[0].GetWidth() - 1, pos.y);//横向;
  359.                         g.DrawLine(&pen1, pos.x, 1, pos.x, rec.bottom - GRAPH_BOTTOM + 2);//纵向;

  360.                         int32 nIndex = mCurveChart[0].GetIndex((int32)pos.x);
  361.                         int32 nLastIndex = mCurveChart[0].GetLastIndex1();

  362.                         if (nIndex > -1 && nIndex <= nLastIndex)
  363.                         {
  364.                                 for (int32 i = 0; i < CHART_COUNT; ++i)
  365.                                 {
  366.                                         int32 offsetPos = FLOAT_POINT_RADIUS / 2;
  367.                                         //画出鼠标位置对应曲线上的点;
  368.                                         g.FillEllipse(mCurveChart[i].GetLineBrush1(), mCurveChart[i].GetPosX1(nIndex) - offsetPos + 1, mCurveChart[i].GetPosY1(nIndex) - offsetPos, FLOAT_POINT_RADIUS, FLOAT_POINT_RADIUS);
  369.                                         //画出曲线点上的数据;
  370. //                                         strTmp.Format(_T("%.0f"), mCurveChart[i].GetRecordData1(nIndex));
  371. //                                         g.DrawString(strTmp.GetBuffer(), -1, &font2, PointF(mCurveChart[i].GetPosX1(nIndex) + offsetPos + 1, mCurveChart[i].GetPosY1(nIndex) + offsetPos), mCurveChart[i].GetLineBrush1());

  372.                                         if (i != 0)
  373.                                         {
  374.                                                 //画出鼠标位置对应曲线上的点;
  375.                                                 g.FillEllipse(mCurveChart[i].GetLineBrush2(), mCurveChart[i].GetPosX2(nIndex) - offsetPos + 1, mCurveChart[i].GetPosY2(nIndex) - offsetPos, FLOAT_POINT_RADIUS, FLOAT_POINT_RADIUS);
  376.                                                 //画出曲线点上的数据;
  377. //                                                 strTmp.Format(_T("%.0f"), mCurveChart[i].GetRecordData2(nIndex));
  378. //                                                 g.MeasureString(strTmp.GetBuffer(), -1, &font2, PointF(0, 0), &rectf);
  379. //                                                 g.DrawString(strTmp.GetBuffer(), -1, &font2, PointF(mCurveChart[i].GetPosX2(nIndex) + offsetPos - 1 - rectf.Width, mCurveChart[i].GetPosY2(nIndex) + offsetPos), mCurveChart[i].GetLineBrush2());
  380.                                         }
  381.                                 }

  382.                                 GetCursorPos(&pos);
  383.                                 ScreenToClient(&pos);
  384.                                 SolidBrush brushRectangle(Color(128, 230, 50, 50));
  385.                                 Pen penRectangle(Color(150, 20, 20), 1);
  386.                                 g.FillRectangle(&brushRectangle, pos.x + 11, pos.y + 11, 37, 14);
  387.                                 g.DrawRectangle(&penRectangle, pos.x + 11, pos.y + 11, 36, 14);
  388.                                 strTmp.Format(_T("%02d:%02d"), mCurveChart[0].GetRecordHour1(nIndex), mCurveChart[0].GetRecordMinute1(nIndex));
  389.                                 g.DrawString(strTmp.GetBuffer(), -1, &font2, PointF(pos.x + 10 + 1, pos.y + 10 + 1), &brush);
  390.                         }

  391.                         pDc->BitBlt(0, 0, rec.right, rec.bottom, &dcMemory2, 0, 0, SRCCOPY);
  392.                 }
  393.                 else
  394.                 {
  395.                         pDc->BitBlt(0, 0, rec.right, rec.bottom, &dcMemory, 0, 0, SRCCOPY);
  396.                 }
  397.         }
  398.         else
  399.         {
  400.                 pDc->BitBlt(0, 0, rec.right, rec.bottom, &dcMemory, 0, 0, SRCCOPY);
  401.         }

  402.         ReleaseDC(pDc);
  403. }

  404. LRESULT CViewGraph::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  405. {
  406.         if ( message == RECEIVE_PACKET_MSG )
  407.         {
  408.                 switch(wParam)
  409.                 {
  410.                 case RES_UPDATE_RECORD:
  411.                         {
  412.                                 mDirtyData = true;

  413.                                 ResUpdateRecord* pResUpdateRecord = (ResUpdateRecord*)lParam;

  414.                                 RecordData data;
  415.                                 data.index        =        pResUpdateRecord->ridx;
  416.                                 data.hour        =        pResUpdateRecord->hour;
  417.                                 data.minute        =        pResUpdateRecord->minute;
  418.                                 data.data        =        pResUpdateRecord->data;

  419.                                 switch(pResUpdateRecord->index)
  420.                                 {
  421.                                 case 0:
  422.                                         mCurveChart[0].UpdateRecord1(data);
  423.                                         break;
  424.                                 case 1:
  425.                                         mCurveChart[1].UpdateRecord1(data);
  426.                                         break;
  427.                                 case 2:
  428.                                         mCurveChart[1].UpdateRecord2(data);
  429.                                         break;
  430.                                 case 3:
  431.                                         mCurveChart[2].UpdateRecord1(data);
  432.                                         break;
  433.                                 case 4:
  434.                                         mCurveChart[2].UpdateRecord2(data);
  435.                                         break;
  436.                                 case 5:
  437.                                         mCurveChart[3].UpdateRecord1(data);
  438.                                         break;
  439.                                 case 6:
  440.                                         mCurveChart[3].UpdateRecord2(data);
  441.                                         break;
  442.                                 case 7:
  443.                                         mCurveChart[0].UpdateRecord2(data);
  444.                                         break;
  445.                                 default:
  446.                                         break;
  447.                                 }
  448.                         }
  449.                         break;
  450.                 case RES_CLEAR_YESTODAY:
  451.                         {
  452.                                 mDirtyData = true;

  453.                                 mBroadcastMsg.clear();

  454.                                 for (int32 i = 0; i < CHART_COUNT; ++i)
  455.                                 {
  456.                                         mCurveChart[i].ClearRecord();
  457.                                 }
  458.                         }
  459.                         break;
  460.                 case RES_BROADCAST_MSG:
  461.                         {
  462.                                 mDirtyData = true;

  463.                                 ResBroadcastMsg* pResBroadcastMsg = (ResBroadcastMsg*)lParam;
  464.                                 mBroadcastMsg.push_back( Encoding::ToWstring(pResBroadcastMsg->msg) );

  465.                                 time_t currenttime = time(NULL);
  466.                                 if (lastPlaySoundTime != currenttime)
  467.                                 {
  468.                                         lastPlaySoundTime = currenttime;
  469.                                         PlaySound(MAKEINTRESOURCE(IDR_WAVE1),AfxGetResourceHandle(), SND_ASYNC|SND_RESOURCE|SND_NODEFAULT);
  470.                                 }
  471.                         }
  472.                         break;
  473.                 case RES_PING:
  474.                         {
  475.                                 ping_time_ = 0;
  476.                         }
  477.                         break;
  478.                 }
  479.         }

  480.         return CDialog::WindowProc(message, wParam, lParam);
  481. }

  482. BOOL CViewGraph::PreTranslateMessage(MSG* pMsg)
  483. {
  484.         switch(pMsg->message)
  485.         {
  486.         case WM_LBUTTONDOWN:
  487.                 {
  488.                         mDown = true;
  489.                         mDownPos.x = GET_X_LPARAM(pMsg->lParam);
  490.                         mDownPos.y = GET_Y_LPARAM(pMsg->lParam);
  491.                 }
  492.                 break;
  493.         case WM_LBUTTONUP:
  494.                 {
  495.                         if ( mDown == true )
  496.                         {
  497.                                 mDirtyData = true;
  498.                                 mShowMouseLine = !mShowMouseLine;
  499.                         }

  500.                         mDown = false;
  501.                 }
  502.                 break;
  503.         case WM_MOUSEMOVE:
  504.                 {
  505.                         if ( mDown == true )
  506.                         {
  507.                                 POINT pos;
  508.                                 pos.x = GET_X_LPARAM(pMsg->lParam);
  509.                                 pos.y = GET_Y_LPARAM(pMsg->lParam);

  510.                                 if ( mDownMoveing && mDownPos.y < pos.y )
  511.                                         mTextOffset += mDownPos.y - pos.y;
  512.                                 else if ( mUpMoveing  && mDownPos.y > pos.y )
  513.                                         mTextOffset += mDownPos.y - pos.y;

  514.                                 mDownPos = pos;

  515.                                 mDirtyData = true;
  516.                         }
  517.                 }
  518.                 break;
  519.         case WM_TIMER:
  520.                 {
  521.                         if ( pMsg->wParam == 10 )
  522.                         {
  523.                                 onPaint();
  524.                         }
  525.                         else if (pMsg->wParam == 11 && IsConnected())
  526.                         {
  527.                                 uint64 ms = util::GetTickMillionSeconds();
  528.                                 if (ping_time_ > 0)
  529.                                 {
  530.                                         if ((ms - ping_time_) > 9500)
  531.                                         {
  532.                                                 KillTimer(11);
  533.                                                 SocketMgr::get_singleton().CloseListenOrConnect(CONNECT_TYPE_SERVER);
  534.                                                 return CDialog::PreTranslateMessage(pMsg);
  535.                                         }
  536.                                 }
  537.                                 else
  538.                                 {
  539.                                         ping_time_ = ms;
  540.                                 }

  541.                                 ReqPing* pReqPing = (ReqPing*)ReqPing::CreatePacket();
  542.                                 ToServer(pReqPing);
  543.                         }
  544.                 }
  545.                 break;
  546.         }

  547.         return CDialog::PreTranslateMessage(pMsg);
  548. }


  549. void CViewGraph::OnSize(UINT nType, int cx, int cy)
  550. {
  551.         CDialog::OnSize(nType, cx, cy);
  552.         RECT rec;
  553.         GetParent()->GetClientRect(&rec);
  554.         int32 chartWidth = rec.right - MESSAGE_WIDTH;
  555.         int32 chartHeight = (rec.bottom - GRAPH_BOTTOM) / CHART_COUNT;
  556.         msg_height_ = rec.bottom - MESSAGE_TOP - MESSAGE_BOTTOM;
  557.         for (int32 i = 0; i < CHART_COUNT; ++i)
  558.         {
  559.                 if (i == 0)
  560.                 {
  561.                         mCurveChart[i].MoveChart(0, chartHeight * i, chartWidth, chartHeight);
  562.                 }
  563.                 else
  564.                 {
  565.                         mCurveChart[i].MoveChart(0, chartHeight * i + CHART_SPACE * i, chartWidth, chartHeight);
  566.                 }
  567.         }
  568.         mDirtyData = true;
  569.         onPaint();
  570. }

  571. void CViewGraph::OnOK()
  572. {

  573. }

  574. void CViewGraph::OnCancel()
  575. {

  576. }
复制代码
最佳答案
2019-7-4 17:56:59
修改过了。请查收。

最佳答案

查看完整内容

修改过了。请查收。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-7-4 17:56:59 | 显示全部楼层    本楼为最佳答案   
修改过了。请查收。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-7-4 19:26:14 | 显示全部楼层
大哥,这个真不会。看都没看懂。。。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-7-5 11:32:48 | 显示全部楼层
去些VC论坛问吧
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-7-6 15:44:20 | 显示全部楼层
高手,,,
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-7-11 15:09:55 | 显示全部楼层
你把完整的一套代码文件发过来我看。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-7-11 15:12:43 | 显示全部楼层
maofei0602 发表于 2019-7-11 15:09
你把完整的一套代码文件发过来我看。

OK
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-16 05:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表