admin
2024-05-17 03654f19baa454b990c052c43e2393a1c53c2c81
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
#include "TradeQueueFrame.h"
#include "MyNetworkApi.h"
#include <thread>
#include "MyConfigUtil.h"
#include "../common_nopch/Win32Util.h"
 
 
TradeQueueFrame::TradeQueueFrame(const wxString& title, wxString code, wxPoint position, wxSize size) :wxFrame(NULL, wxID_ANY, title, position, size) {
    SetWindowStyle(GetWindowStyle() | wxSTAY_ON_TOP);
    //SetTransparent(225);
    this->killed = false;
    Bind(wxEVT_CLOSE_WINDOW, &TradeQueueFrame::OnClose, this);
    listControl = new TradeQueueListControl(this, wxID_ANY);
    wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
    sizer->Add(listControl, 1, wxEXPAND);
    SetSizer(sizer);
    SetBackgroundColour(*wxBLACK);
 
    requestThread = new std::thread(requestTradeQueue, code, this);
    requestThread->detach();
}
 
TradeQueueFrame::~TradeQueueFrame()
{
    cout << "TradeQueueFrame Îö¹¹º¯Êý" << endl;
    this->killed = true;
}
 
void TradeQueueFrame::OnClose(wxCloseEvent& event)
{
    this->killed = true;
    cout << "¹Ø±Õ´°¿Ú£º" << this << endl;
 
    delete listControl;
    delete requestThread;
    // ±£´æµ±Ç°µÄ³ß´çÓëλÖÃ
    MyConfigUtil::setTradeQueueWindowPos(GetPosition(), GetSize());
    // Õý³£¹Ø±Õ
    event.Skip();
}
 
void TradeQueueFrame::requestTradeQueue(wxString code, TradeQueueFrame* context)
{
    int count = 0;
    while (TRUE) {
 
        if (context->killed) {
            break;
        }
 
        if (count % 30 == 0) {
            count = 1;
 
 
 
 
            cout << "ÇëÇóµÄ´úÂ룺" << code << " ÄÚÈݵØÖ·£º" << &context << "killed:" << context->killed << endl;
 
            try {
                list<TradeQueue> queueList;
                string result = MyNetworkApi::get_trade_queue(code.ToStdString());
                if (context->killed) {
                    break;
                }
                if (context->latest_request_result != result) {
 
                    auto doc = JsonUtil::parseUTF16(result);
                    if (doc.IsObject()) {
                        if (doc[L"code"].GetInt() == 0) {
                            auto array = doc[L"data"].GetArray();
                            for (int i = 0; i < array.Size(); i++) {
                                int num = array[i][0].GetInt();
                                int type = array[i][1].GetInt();
                                queueList.push_back(TradeQueue({ to_string(num),type }));
                            }
                        }
                    }
                    cout << code << endl;
                    if (context != nullptr && context->listControl != nullptr)
                    {
                        context->listControl->setTradeQueue(queueList);
                        context->latest_request_result = result;
                    }
                }
            }
            catch (string st) {
 
            }
        }
        count++;
        Sleep(100);
    }
 
}