#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);
|
}
|
|
}
|