#include "TradeQueueCaptureManager.h" #include "GPUtil.h" bool TradeQueueCaptureManager::inited; //const static int MAX_COUNT = 10; HWND TradeQueueCaptureManager::hwnds[MAX_COUNT]; TradeQueueCapture* TradeQueueCaptureManager::captures[MAX_COUNT]; CallbackFun_Trade_Queue_New TradeQueueCaptureManager::data_callback; bool TradeQueueCaptureManager::running; void* TradeQueueCaptureManager::context; bool TradeQueueCaptureManager::tradeTimeCapture; void TradeQueueCaptureManager::_run(int index) { while (TRUE) { if (!running) { Sleep(100); continue; } if (!inited) { Sleep(100); continue; } if (tradeTimeCapture) { if (!GPUtil::isTradeTime()) { Sleep(100); continue; } } try { TradeQueueResult result = captures[index]->recognition_buy_1_volumn(hwnds[index]); if (data_callback != NULL) { data_callback(index, result,context); } } catch (string st) { cout << index<<"£º"<< st << endl; } catch (...) { cout << index << "£º" << "δ֪Òì³£" << endl; } } } void TradeQueueCaptureManager::loadTradeWinsHWND() { //»ñȡͬ»¨Ë³×¨Òµ°æ list wlist = Win32Util::searchWindow("רҵ°æÏµ¥"); if (wlist.size() <= 0) { throw string("רҵ°æÏµ¥Î´´ò¿ª"); } HWND hwnd=NULL; for (list::iterator ele = wlist.begin();ele != wlist.end();ele++) { hwnd = *ele; if (Win32Util::isWindowShow(hwnd)) { break; } else { hwnd = NULL; } } if (!hwnd) { throw string("רҵ°æÏµ¥Î´ÏÔʾ"); } std::list hwndList; HWND child = NULL; do { child = FindWindowExA(hwnd, child, "#32770", NULL); if (!child) { break; } if (!Win32Util::isWindowShow(child)) { continue; } HWND temp= FindWindowExA(child, NULL, "Button", "³·µ¥"); if (temp) { hwndList.push_back(child); } } while (TRUE); if (hwndList.size() <= 0) { throw string("δÕÒµ½½»Ò×´°¿Ú"); } hwndList.sort(hwnd_compare); int index = 0; for (std::list::iterator ele = hwndList.begin();ele != hwndList.end();++ele) { hwnds[index] = *ele; index++; } } void TradeQueueCaptureManager::init(CallbackFun_Trade_Queue_New trade_queue_callback, void* contex) { inited = true; data_callback = trade_queue_callback; context = contex; for (int i = 0;i < MAX_COUNT;i++) { captures[i] = new TradeQueueCapture(); } running = false; for (int i = 0;i < MAX_COUNT;i++) { thread rt(&(TradeQueueCaptureManager::_run), i); rt.detach(); } //»ñȡͬ»¨Ë³´°¿Ú¾ä±ú try { refreshHWND(); } catch (string st) { throw st; } } void TradeQueueCaptureManager::refreshHWND() { loadTradeWinsHWND(); } void TradeQueueCaptureManager::start() { running = TRUE; } void TradeQueueCaptureManager::stop() { running = FALSE; } bool TradeQueueCaptureManager::isRunning() { return running; } bool TradeQueueCaptureManager::isInited() { return inited; }