@@ -892,6 +892,27 @@ void CSimpleNotePadDlg::FillFindText()
892892 m_find_replace_dlg.SetFindString (L" " );
893893}
894894
895+ UINT CSimpleNotePadDlg::TextChangeThreadCallback (LPVOID dwUser)
896+ {
897+ CSimpleNotePadDlg* pThis = dynamic_cast <CSimpleNotePadDlg*>(theApp.m_pMainWnd );
898+ while (true )
899+ {
900+ if (pThis->m_text_changed_thread_exit )
901+ break ;
902+
903+ // 响应编辑器文本变化
904+ if (pThis->m_text_changed )
905+ {
906+ pThis->m_view ->GetTextW (pThis->m_edit_wcs );
907+ pThis->UpdateStatusBarInfo ();
908+ pThis->SetTitle ();
909+ pThis->m_text_changed = false ;
910+ }
911+ Sleep (100 );
912+ }
913+ return 0 ;
914+ }
915+
895916// void CSimpleNotePadDlg::SaveAsHex()
896917// {
897918// //设置过滤器
@@ -1164,6 +1185,7 @@ BOOL CSimpleNotePadDlg::OnInitDialog()
11641185
11651186 SetTimer (TIMER_ID_MONITOR, 1000 , NULL );
11661187
1188+ m_text_change_thread = AfxBeginThread (TextChangeThreadCallback, nullptr );
11671189
11681190 return TRUE ; // 除非将焦点设置到控件,否则返回 TRUE
11691191}
@@ -1968,9 +1990,7 @@ BOOL CSimpleNotePadDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
19681990 UINT marsk = (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT | SC_PERFORMED_UNDO | SC_PERFORMED_REDO);
19691991 if ((notification->modificationType & marsk) != 0 )
19701992 {
1971- m_view->GetTextW (m_edit_wcs);
1972- UpdateStatusBarInfo ();
1973- SetTitle ();
1993+ m_text_changed = true ;
19741994 }
19751995 // 当删除了字符时
19761996 if (notification->modificationType == (SC_MOD_DELETETEXT | SC_PERFORMED_USER)
@@ -2283,6 +2303,10 @@ void CSimpleNotePadDlg::OnDestroy()
22832303 CBaseDialog::OnDestroy ();
22842304
22852305 // TODO: 在此处添加消息处理程序代码
2306+ m_text_changed_thread_exit = true ;
2307+ if (m_text_change_thread != nullptr )
2308+ WaitForSingleObject (m_text_change_thread->m_hThread , 2000 ); // 等待线程退出
2309+
22862310}
22872311
22882312
0 commit comments