no message

This commit is contained in:
zcy 2021-09-24 00:38:05 +08:00
parent fef52d423f
commit 17cff75119
5 changed files with 28 additions and 16 deletions

View File

@ -31,8 +31,15 @@ std::wstring BasicForm::GetWindowClassName() const
LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_ADD_UART_RECVDATA) {
printf("WM_ADD_UART_RECVDATA");
this->Paint();
for (auto itr = mUartForm.begin(); itr != mUartForm.end(); itr++) {
itr->second->OnUpdateUart();
}
}
if (uMsg == WM_USER_POS_CHANGED) {
}
if (uMsg == WM_ADD_UART_MONITOR) {
printf("add monitor");
@ -47,13 +54,12 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
mMonitor->GetRootNode()->GetChildNode(0)->AddChildNode(node);
if (mUartForm.find(p->name) == mUartForm.end()) {
auto form = new UartForm(this->m_hWnd,p->name, p->baurate,
auto form = new UartForm(this,p->name, p->baurate,
p->data_bits, p->stop_bits, p->verify, p->flow_control);
form->SetChildLayoutXML(L"basic/uart_form.xml");
form->SetVisible(false);
mUartForm[p->name] = form;
}
node->AttachAllEvents([this](ui::EventArgs* ev){
if (ui::EventType::kEventSelect == ev->Type) {
mRightSide->RemoveAll();

View File

@ -54,8 +54,6 @@ private:
NewMonitorForm* mMonitorNewSelect;
ui::TabBox *mRightSide;
ui::TreeView *mMonitor;
std::map<std::wstring,UartForm*> mUartForm;
};

View File

@ -5,6 +5,7 @@
using namespace std;
#define WM_ADD_UART_RECVDATA (WM_USER + 4)
typedef struct{
wstring name;

View File

@ -1,8 +1,5 @@
#include "uart_process.h"
#define WM_ADD_UART_RECVDATA (WM_USER + 4)
wstring string2wstring(string str)
{
wstring result;
@ -33,13 +30,13 @@ std::string wstring2string(std::wstring wstr)
return result;
}
UartForm::UartForm(HWND hwnd,std::wstring name,
UartForm::UartForm(ui::Window* hwnd,std::wstring name,
uint32_t baurate,
uint8_t data_bits, uint8_t stop_bits,
uint8_t verify, uint8_t flow_control):
m_thread_recv(nullptr)
m_thread_recv(nullptr),
mEditRecv(nullptr)
{
m_hwnd = hwnd;
m_name = name;
m_baurate = baurate;
m_data_bits = data_bits;
@ -58,16 +55,24 @@ UartForm::UartForm(HWND hwnd,std::wstring name,
while (this->m_runing) {
if (0 < SerialPort::ReadPort(PortNum, recv, 1024)) {
printf("recv data: %s", recv);
this->m_show_recv += wstring(L"123");
this->UpdateRecvEdit();
::PostMessage(m_hwnd, WM_ADD_UART_RECVDATA, 0, 0);
this->Invalidate();
this->m_show_recv += string2wstring(recv);
::PostMessage(this->GetWindow()->GetHWND(), WM_ADD_UART_RECVDATA, 0, 0);
}
else {
Sleep(30);
}
}
});
if (nullptr != hwnd) {
this->SetWindow(hwnd, nullptr, false);
}
}
void UartForm::OnUpdateUart()
{
if(mEditRecv != nullptr)
this->mEditRecv->SetText(this->m_show_recv.c_str());
}

View File

@ -17,12 +17,14 @@
class UartForm : public ui::ChildBox
{
public:
UartForm(HWND hwnd,std::wstring name, uint32_t baurate,
UartForm(ui::Window* window,std::wstring name, uint32_t baurate,
uint8_t data_bits,
uint8_t stop_bits,
uint8_t verify,
uint8_t flow_control);
void OnUpdateUart();
/// 重写父类方法,提供个性化功能,请参考父类声明
virtual void Init() override;