#include "TradeQueueFrame.h" #include "MyNetworkApi.h" #include #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); Bind(wxEVT_SIZE, &TradeQueueFrame::OnSize, this); scrolledWindow = new wxScrolledWindow(this, wxID_ANY); listControl = new TradeQueueListControl(scrolledWindow, wxID_ANY, wxDefaultPosition,wxSize(-1, size.GetHeight()-35)); dealBigMoneyListControl = new TradeQueueListControl(scrolledWindow, wxID_ANY, wxDefaultPosition, wxSize(-1, size.GetHeight() - 35), wxSize(75,22)); wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(dealBigMoneyListControl, 0, wxEXPAND | wxBottom, 10); sizer->Add(listControl, 1, wxEXPAND); //SetSizer(sizer); SetBackgroundColour(*wxBLACK); scrolledWindow->SetScrollbars(1, dealBigMoneyListControl->GetSize().GetHeight(), 0, 2); scrolledWindow->SetSizer(sizer); scrolledWindow->SetScrollRate(0, dealBigMoneyListControl->GetSize().GetHeight()); scrolledWindow->Scroll(0, 1); wxBoxSizer* rootSizer = new wxBoxSizer(wxVERTICAL); rootSizer->Add(scrolledWindow, 1, wxEXPAND); SetSizer(rootSizer); requestThread = new std::thread(requestTradeQueue, code, this); requestThread->detach(); std::thread* t1 = new std::thread(requestDealBigList, code, this); t1->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::OnSize(wxSizeEvent& event) { event.Skip(); wxSize size = GetClientSize(); cout <<"´°¿Ú´óС£º"<< size.GetWidth()<<"-"<SetSize(size); dealBigMoneyListControl->SetSize(size); //resetScrollInfo(); } void TradeQueueFrame::resetScrollInfo() { int height = dealBigMoneyListControl->getContentHeight(); int pos = scrolledWindow->GetScrollPos(wxVERTICAL); scrolledWindow->AdjustScrollbars(); scrolledWindow->SetScrollbars(1, dealBigMoneyListControl->GetSize().GetHeight(), 0, 1); scrolledWindow->SetScrollRate(0, dealBigMoneyListControl->GetSize().GetHeight()); //scrolledWindow->Layout(); scrolledWindow->Scroll(0, pos); cout << "³É½»¶ÓÁеĸ߶ȣº" << listControl->GetClientRect().GetHeight() << endl; cout << "scrollwindowµÄ¸ß¶È£º" << scrolledWindow->GetSize().GetHeight() << endl; Refresh(); } 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 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 })); } if (context != nullptr && context->listControl != nullptr) { context->listControl->setTradeQueue(queueList); context->latest_request_result = result; } } else { cout << "code!=0" << endl; } } cout << code << endl; } } catch (string st) { cout << "³ö´í"<< endl; } } count++; Sleep(100); } } void TradeQueueFrame::requestDealBigList(wxString code, TradeQueueFrame* context) { int count = 0; while (TRUE) { if (context->killed) { break; } if (count % 30 == 0) { count = 1; try { list moneyList; string result = MyNetworkApi::get_deal_big_money_list(code.ToStdString()); if (context->killed) { break; } 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++) { wxString money = array[i].GetString(); int type = 3; moneyList.push_back(TradeQueue({ money,type })); } if (context != nullptr && context->listControl != nullptr) { bool lengthChange = moneyList.size() != context->dealBigMoneyListControl->getDataCount(); context->dealBigMoneyListControl->setTradeQueue(moneyList); if (lengthChange) { context->resetScrollInfo(); } } } } } catch (string st) { } } count++; Sleep(100); } }