100 lines
2.8 KiB
C++
100 lines
2.8 KiB
C++
#include "websocket_client_form.h"
|
|
#include "utils.h"
|
|
|
|
WebsocketClientForm::WebsocketClientForm(ui::Window* hwnd, string url, WebsocketClient* p)
|
|
{
|
|
if (nullptr != hwnd) {
|
|
this->SetWindow(hwnd, nullptr, false);
|
|
}
|
|
mWebsocketClient = p;
|
|
|
|
}
|
|
|
|
WebsocketClientForm::~WebsocketClientForm()
|
|
{
|
|
|
|
}
|
|
|
|
void WebsocketClientForm::Init()
|
|
{
|
|
ui::ChildBox::Init();
|
|
m_label_1 = dynamic_cast<ui::Label*>(FindSubControl(L"server_info"));
|
|
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_uart_send_edit = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_send_edit"));
|
|
m_btn_send_data = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
|
|
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"));
|
|
m_btn_save_lua = dynamic_cast<ui::Button*>(FindSubControl(L"btn_save_lua"));
|
|
m_btn_close_form = dynamic_cast<ui::Button*>(FindSubControl(L"btn_close_uart"));
|
|
|
|
if (nullptr != m_label_1) {
|
|
if (mWebsocketClient->State() == WebsocketClient::CONNECTED) {
|
|
m_label_1->SetText(std::wstring() + L"服务端: " +
|
|
string2wstring(mWebsocketClient->Url()) + L"连接成功");
|
|
}
|
|
else {
|
|
m_label_1->SetText(std::wstring() + L"服务端: " +
|
|
string2wstring(mWebsocketClient->Url()) + L"连接失败");
|
|
}
|
|
}
|
|
if (nullptr != m_btn_close_form)
|
|
m_btn_close_form->AttachClick([this](const ui::EventArgs* ev) {
|
|
wstring* name = new wstring(this->GetName());
|
|
::PostMessage(this->GetWindow()->GetHWND(),
|
|
WM_ADD_WEBSOCKET_CLIENT_CLOSE, (WPARAM)name, 0);
|
|
return true;
|
|
}
|
|
);
|
|
|
|
if(nullptr != m_btn_save_lua)
|
|
m_btn_save_lua->AttachClick(
|
|
[this](ui::EventArgs* ev){
|
|
|
|
return true;
|
|
}
|
|
);
|
|
|
|
if (nullptr != m_btn_send_data) {
|
|
m_btn_send_data->AttachClick([this](const ui::EventArgs* ev) {
|
|
|
|
return true;
|
|
});
|
|
}
|
|
}
|
|
|
|
LuaDelegate* WebsocketClientForm::LuaVM()
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
void WebsocketClientForm::ShowDataInEdit(const char*src)
|
|
{
|
|
m_rich_edit_1->AppendText(string2wstring(std::string(src)),false);
|
|
}
|
|
|
|
void WebsocketClientForm::OnConnected(WebsocketClient* ws)
|
|
{
|
|
if (nullptr != m_label_1) {
|
|
if (mWebsocketClient->State() == WebsocketClient::CONNECTED) {
|
|
m_label_1->SetText(std::wstring() + L"服务端: " +
|
|
string2wstring(mWebsocketClient->Url()) + L"连接成功");
|
|
}
|
|
else {
|
|
m_label_1->SetText(std::wstring() + L"服务端: " +
|
|
string2wstring(mWebsocketClient->Url()) + L"连接失败");
|
|
}
|
|
}
|
|
}
|
|
|
|
void WebsocketClientForm::OnDisConnected(WebsocketClient* ws, WebsocketClient::CloseReason)
|
|
{
|
|
std::cout << "OnDisConnected" << std::endl;
|
|
}
|
|
|
|
void WebsocketClientForm::OnReadHandler(WebsocketClient* ws, std::string message)
|
|
{
|
|
std::cout << "recv data from hanlder" << message.c_str();
|
|
}
|