no message

This commit is contained in:
zcy 2022-01-11 01:07:59 +08:00
parent 253dc96394
commit 8a1cc7a1c8
7 changed files with 36 additions and 7 deletions

View File

@ -35,7 +35,7 @@ int gTcpServerCnt = 0;
int gTcpClientCnt = 0;
LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
wprintf(L"recv message 0x%x\r\n", uMsg);
//wprintf(L"recv message 0x%x\r\n", uMsg);
if (uMsg == WM_ADD_UART_CLOSE) {
wprintf(L"close %s\r\n", ((wstring*)wParam)->c_str());

View File

@ -88,6 +88,7 @@ void MainThread::Init()
#endif
auto dpiManager = ui::DpiManager::GetInstance();
dpiManager->SetAdaptDPI();
// 创建一个默认带有阴影的居中窗口
BasicForm* window = new BasicForm();

View File

@ -17,13 +17,14 @@ TcpServerFrom::TcpServerFrom(ui::Window* hwnd, string url, uint32_t port, TcpSer
m_server = p;
m_url = url;
m_port = port;
mFlagSelectClient = true;
TcpServerLibevent::OnAccept handler = std::bind(&TcpServerFrom::OnNewConnAccept, this,std::placeholders::_1 );
m_server->SetNewConnectionHandle(handler);
TcpServerLibevent::OnDisconnect handler2 = std::bind(&TcpServerFrom::OnDisConnected,
this, std::placeholders::_1);
m_server->SetConnectionLeaveHandle(handler2);
}
@ -50,16 +51,30 @@ void TcpServerFrom::Init()
m_combo_1 = dynamic_cast<ui::Combo*>(FindSubControl(L"clients"));
m_button_3 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_do_lua"));
m_button_3->AttachClick([this](ui::EventArgs*ev) {
std::cout <<"m_button_3 " << wstring2string(this->m_combo_1->GetText())<<std::endl;
return true;
});
wchar_t p[200] = L"";
wsprintf(p,L"监听地址: %s 端口: %d 在线连接数目: %d",string2wstring(m_url).c_str(),
m_port,
m_server->ConnectionCount());
m_label_1->SetText(p);
auto element = new ui::ListContainerElement;
element->SetClass(L"listitem");
element->SetFixedHeight(30);
element->SetBkColor(L"white");
element->SetTextPadding({ 6,0,6,0 });
element->SetText(L"È«²¿Á¬½Ó");
m_combo_1->Add(element);
}
void TcpServerFrom::OnNewConnAccept(ConnectionLibevent*p)
void TcpServerFrom::OnNewConnAccept(ConnectionLibevent* p)
{
std::cout << "TcpServerFrom OnNewConnAccept addr " << p->IpAddress()<<p->SocketFd()<<std::endl;
std::cout << "TcpServerFrom OnNewConnAccept addr " << p->IpAddress() << p->SocketFd() << std::endl;
updateStatus();
auto element = new ui::ListContainerElement;
@ -68,6 +83,8 @@ void TcpServerFrom::Init()
element->SetBkColor(L"white");
element->SetTextPadding({ 6,0,6,0 });
element->SetText(std::to_wstring(p->SocketFd()));
mClients[p->SocketFd()] = p;
m_combo_1->Add(element);
return;
}
@ -75,8 +92,8 @@ void TcpServerFrom::Init()
void TcpServerFrom::OnDisConnected(ConnectionLibevent* cli)
{
std::cout << "TcpServerFrom Disconnected" << cli->IpAddress() << " fd " << cli->SocketFd() << std::endl;
updateStatus();
mClients.erase(cli->SocketFd());
}
void TcpServerFrom::updateStatus()

View File

@ -6,7 +6,7 @@
// duilib
#include "duilib/UIlib.h"
#include "tcp_server_libevent.h"
#include <map>
class TcpServerFrom :
@ -23,7 +23,6 @@ protected:
private:
void updateStatus();
TcpServerLibevent* m_server;
std::string m_url;
uint32_t m_port;
@ -41,6 +40,8 @@ private:
ui::Label* m_label_2;
ui::Combo* m_combo_1;
ui::Button* m_button_3;
std::map<uint32_t, ConnectionLibevent*> mClients;
bool mFlagSelectClient;
};

View File

@ -1,6 +1,7 @@
#include "uart_process.h"
#include "utils.h"
#include "msgdef.h"
#include "utils.h"
UartForm::UartForm(ui::Window* hwnd,std::wstring name,
uint32_t baurate,

View File

@ -31,6 +31,13 @@ std::string wstring2string(std::wstring wstr)
return result;
}
int32_t wstring2int32(std::wstring wstr)
{
auto str = wstring2string(wstr);
int ret = atoi(str.c_str());
return ret;
}
std::string GenerateGuid()

View File

@ -6,5 +6,7 @@
std::wstring string2wstring(std::string str);
std::string wstring2string(std::wstring wstr);
int32_t wstring2int32(std::wstring );
std::string GenerateGuid();