add tcp client

This commit is contained in:
zcy 2021-10-11 00:54:04 +08:00
parent d6045de076
commit d163878aef
4 changed files with 31 additions and 21 deletions

View File

@ -71,18 +71,21 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
TcpClientInfo* info = (TcpClientInfo*)wParam;
TcpClientLibevent* cli = (TcpClientLibevent*)lParam;
ui::TreeNode* node = new ui::TreeNode;
node->SetText(info->ip);
node->SetText(info->ip + L":" + std::to_wstring(info->socket_fd));
node->SetTextId(L"sdfsdfasd");
node->SetClass(L"listitem");
node->SetFixedHeight(20);
node->SetMargin({ 20, 0, 0, 0 });
mMonitor->GetRootNode()->GetChildNode(1)->AddChildNode(node);
if (mTcpClientForm.find(info->socket_fd) == mTcpClientForm.end()) {
auto form = new TcpClientForm(wstring2string(info->ip),info->port, cli);
form->SetChildLayoutXML(L"basic/tcp_form.xml");
form->SetName(info->ip);
if (mTcpClientForm.find(info->ip + L":"
+ std::to_wstring(info->socket_fd)) == mTcpClientForm.end())
{
auto form = new TcpClientForm(this,wstring2string(info->ip),info->port, cli);
form->SetChildLayoutXML(L"basic/uart_form.xml");
form->SetName(info->ip + L":" + std::to_wstring(info->socket_fd));
form->SetVisible(false);
mTcpClientForm[info->socket_fd] = form;
mTcpClientForm[info->ip + L":" + std::to_wstring(info->socket_fd)] = form;
if (!mRightSide->Add(form))
printf("erroer 1");
}
@ -90,9 +93,11 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (ui::EventType::kEventSelect == ev->Type) {
wprintf(L"%s\r\n", dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText().c_str());
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
//TcpClientForm* p = mTcpClientForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
/*
TcpClientForm* p = mTcpClientForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
if (p != nullptr) {
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
p->SetAutoDestroy(true);
if (mRightShow != nullptr) {
mRightShow->SetVisible(false);
@ -107,7 +112,7 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
mRightSide->SelectItem(p->GetName());
mRightShow = p;
}
}*/
}
}
return true;
});

View File

@ -57,7 +57,7 @@ private:
ui::TabBox *mRightSide;
ui::TreeView *mMonitor;
std::map<std::wstring,UartForm*> mUartForm;
std::map<uint32_t, TcpClientForm*> mTcpClientForm;
std::map<std::wstring, TcpClientForm*> mTcpClientForm;
ui::Control* mRightShow;
};

View File

@ -1,21 +1,26 @@
#include "tcp_client_form.h"
TcpClientForm::TcpClientForm(std::string url, uint32_t port, TcpClientLibevent* p)
TcpClientForm::TcpClientForm(ui::Window* hwnd,std::string url, uint32_t port, TcpClientLibevent* p)
{
mClient = p;
if (nullptr != hwnd) {
this->SetWindow(hwnd, nullptr, false);
}
}
void TcpClientForm::Init()
{
ui::Label* m_label_1 = dynamic_cast<ui::Label*>(FindSubControl(L"uart_info_label"));
ui::RichEdit* m_rich_edit_1 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_recv_eidt"));
ui::RichEdit* m_rich_edit_2 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"lua_script"));
ui::RichEdit* m_rich_edit_3 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_send_edit"));
ui::Button* m_button_1 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
ui::CheckBox* m_check_box_1 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_new_line"));
ui::CheckBox* m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
ui::CheckBox* m_check_box_3 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_send"));
ui::CheckBox* m_check_box_4 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_recv"));
ui::ChildBox::Init();
m_label_1 = dynamic_cast<ui::Label*>(FindSubControl(L"uart_info_label"));
m_rich_edit_1 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_recv_eidt"));
m_rich_edit_2 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"lua_script"));
m_rich_edit_3 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_send_edit"));
m_button_1 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
m_check_box_1 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_new_line"));
m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
m_check_box_3 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_send"));
m_check_box_4 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_recv"));
}

View File

@ -18,7 +18,7 @@ class TcpClientForm : public ui::ChildBox {
#pragma once
public:
TcpClientForm(string url, uint32_t port, TcpClientLibevent* p);
TcpClientForm(ui::Window* hwnd,string url, uint32_t port, TcpClientLibevent* p);
virtual void Init() override;
private: