admin
2023-01-16 9190340264f947b7978072aad4b0d9660f9f891f
app/appDlg.cpp
@@ -294,13 +294,29 @@
            }
         }
         autoMsgStatic.SetWindowTextW(_T("等待打开副屏1..."));
         THSActionUtil::openSecondScreen();
         for (int i = 0; i < 5; i++) {
            HWND second = THSActionUtil::getSecondWindow();
            if (second > 0) {
               break;
            }
            THSActionUtil::openSecondScreen();
            Sleep(1000);
         }
         autoMsgStatic.SetWindowTextW(_T("副屏1已打开..."));
         Sleep(1000);
         // 开启 涨停识别
         autoMsgStatic.SetWindowTextW(_T("启动涨停识别中..."));
         CappDlg::OnBnClickedButton12();
         autoMsgStatic.SetWindowTextW(_T("启动涨停启动成功"));
           // 开启委托识别
           // 开启交易成功识别
      }
   }
   else {
@@ -464,7 +480,7 @@
}
void  CappDlg::OnL2DataCallback(int index, string code, long captureTime, long processTime, list<TradeData> dataList, void* context) {
void  CappDlg::OnL2DataCallback(int index, string code, long captureTime, long processTime, list<TradeData*> dataList, void* context) {
   //转为json
   CappDlg* app = (CappDlg*)context;
   //cout << "回调:" << std::this_thread::get_id() << ":" << index << endl;
@@ -472,6 +488,10 @@
   bool check = btn->GetCheck();
   if (check) {
      string data = JsonUtil::loadL2Data(app->clientNum, index, code, captureTime, processTime, dataList);
      for (list<TradeData*>::iterator el = dataList.begin(); el != dataList.end();++el) {
         delete (*el);
      }
      dataList.clear();
      clock_t time_start = clock();
      try {
         app->socketManager->sendMsg(index, data.c_str());
@@ -1385,7 +1405,7 @@
   if (p.length() <= 0) {
      return;
   }
   list<TradeData> result = capture->captureLevel2TradeData(cv::imread(p), 0);
   list<TradeData*> result = capture->captureLevel2TradeData(cv::imread(p), 0);
   time = clock() - time;
   Clevel2DataDlg::level2Data = { time, result };
@@ -1414,7 +1434,7 @@
   if (p.length() <= 0) {
      return;
   }
   list<TradeData> result = capture->captureLevel2TradeData(cv::imread(p), 0);
   list<TradeData*> result = capture->captureLevel2TradeData(cv::imread(p), 0);
   time = clock() - time;
   Clevel2DataDlg::level2Data = { time, result };
@@ -1756,6 +1776,67 @@
void CappDlg::OnBnClickedButtonTradeDelegate()
{
   //打开同花顺远航版的委托界面
   HWND win = 0;
   if (win <= 0) {
      //判断是否已经打开了同花顺远航版
      for (int i = 0; i < 10; i++)
      {
         win = THSActionUtil::getTradeSimpleDelegateWindow();
         if (win <= 0)
         {
            list<HWND> wlist = Win32Util::searchWindow("同花顺远航版");
            if (wlist.size() > 0) {
               HWND mainWin = *(wlist.begin());
               //按F12
               Win32Util::sendMessage(mainWin, WM_KEYDOWN, VK_F12, 0);
               Win32Util::sendMessage(mainWin, WM_KEYUP, VK_F12, 0);
               //等待反应
               Sleep(500);
            }
            else {
               //等待远航版打开
               Sleep(1000);
            }
         }
         else {
            break;
         }
      }
   }
   //如果已经打开了远航版的交易,就需要点击当日委托
   try {
     HWND menuWin = TradeListCapture::getSimpleTradeLeftMenu(win);
     if (menuWin > 0) {
      cv::Mat img =  CaptureUtil::capture(menuWin);
      string result = JsonUtil::loadOcrData(clientNum, img, "当日委托");
      result = socketManager->sendMsg(result.c_str());
      Json::Value root = JsonUtil::parseJson(result);
      if (root["code"] == 0) {
        //图像识别成功
         Json::Value datas = root["data"]["datas"];
         Json::Value ps = datas[0]["position"];
         //position格式:[[0,13],[12,13],[12,15],[0,15]]
         //获取中心点
         int x = (ps[0][0].asInt() + ps[1][0].asInt()) / 2;
         int y= (ps[0][1].asInt() + ps[2][1].asInt()) / 2;
         RECT rect;
         Win32Util::getWindowRect(menuWin,&rect);
         x = rect.left + x;
         y = rect.top + y;
         //点击
         Win32Util::click(x,y,10);
      }
     }
   }
   catch (...) {
   }
@@ -1787,7 +1868,6 @@
         AfxMessageBox(msg);
         return;
      }
      tradeListCapture->startTradeDelegate();
      delegateBtn.SetWindowTextW(_T("暂停委托识别任务"));
   }
@@ -1799,46 +1879,26 @@
//测试按钮
void CappDlg::OnBnClickedButtonTest()
{
   int index = 0;
   std::list<TradeData> dataList;
   for (int i = 0; i < 10; i++) {
      TradeData data = TradeData();
      //7.32
      data.time = "09:30:00";
      data.price = "26.84";
      data.operateType = OPERATE_BUY;
      data.limitPrice = LIMIT_PRICE_UP;
      data.num = 5000 + i;
      dataList.push_back(data);
   cv::Mat mat = cv::imread("C:\\Users\\Administrator\\Desktop\\ocr\\trade\\Snipaste_2023-01-13_18-23-34_gray.png", cv::IMREAD_GRAYSCALE);
   Json::Value array;
   int len = mat.rows * mat.cols;
   for (int i = 0; i < len; i++) {
      array[i] = mat.data[i];
   }
   for (int i = 10; i < 11; i++) {
      TradeData data = TradeData();
      //7.32
      data.time = "09:30:00";
      data.price = "26.84";
      data.operateType = OPERATE_BUY_CANCEL;
      data.limitPrice = LIMIT_PRICE_UP;
      data.num = 5000 + i;
      dataList.push_back(data);
   }
   string data = JsonUtil::loadL2Data(clientNum, 0, "002338", 0, 0, dataList);
   clock_t time_start = clock();
   Json::Value data;
   data["data"] = array;
   data["width"] = mat.cols;
   data["height"] = mat.rows;
   data["key"] = "当日委托" ;
   Json::Value root;
   root["data"] = data;
   root["type"] = 100;
   string result = JsonUtil::jsonValue2String(root);
   try {
      socketManager->sendMsg(index, data.c_str());
      socketManager->sendMsg(result.c_str());
   }
   catch (string st) {
      //重新连接服务器
      socketManager->resetClient(index);
      socketManager->Connect(index);
   }
}
void CappDlg::OnBnClickedCheck5()