admin
2023-01-02 954ead41d9391bca28a3cc4f9592f73f25b3bbc8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#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<HWND> wlist = Win32Util::searchWindow("רҵ°æÏµ¥");
    if (wlist.size() <= 0) {
        throw string("רҵ°æÏµ¥Î´´ò¿ª");
    }
    HWND hwnd=NULL;
    for (list<HWND>::iterator ele = wlist.begin();ele != wlist.end();ele++) {
        hwnd = *ele;
        if (Win32Util::isWindowShow(hwnd)) {
            break;
        }
        else {
            hwnd = NULL;
        }
    }
 
    if (!hwnd) {
        throw string("רҵ°æÏµ¥Î´ÏÔʾ");
    }
 
    std::list<HWND> 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<HWND>::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;
}