diff --git a/examples/proto_debuger/base_form.cpp b/examples/proto_debuger/base_form.cpp index 5a9f984c..e75236c8 100644 --- a/examples/proto_debuger/base_form.cpp +++ b/examples/proto_debuger/base_form.cpp @@ -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(); diff --git a/examples/proto_debuger/base_form.h b/examples/proto_debuger/base_form.h index 6037d360..9b6718dc 100644 --- a/examples/proto_debuger/base_form.h +++ b/examples/proto_debuger/base_form.h @@ -54,8 +54,6 @@ private: NewMonitorForm* mMonitorNewSelect; ui::TabBox *mRightSide; ui::TreeView *mMonitor; - - std::map mUartForm; }; diff --git a/examples/proto_debuger/serial_port.h b/examples/proto_debuger/serial_port.h index b1915048..b6966028 100644 --- a/examples/proto_debuger/serial_port.h +++ b/examples/proto_debuger/serial_port.h @@ -5,6 +5,7 @@ using namespace std; +#define WM_ADD_UART_RECVDATA (WM_USER + 4) typedef struct{ wstring name; diff --git a/examples/proto_debuger/uart_process.cpp b/examples/proto_debuger/uart_process.cpp index 7654d819..b46f9525 100644 --- a/examples/proto_debuger/uart_process.cpp +++ b/examples/proto_debuger/uart_process.cpp @@ -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()); + } diff --git a/examples/proto_debuger/uart_process.h b/examples/proto_debuger/uart_process.h index 496782d4..a3af89cd 100644 --- a/examples/proto_debuger/uart_process.h +++ b/examples/proto_debuger/uart_process.h @@ -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;