Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have SDI based MFC project, in which I created a dialog by placing code in MainFrame class. The form dialog has a readonly edit box where I want to display data continuously received from serial port. I have the following code in the view class:

void CSerialCommView::OnDraw(CDC* /*pDC*/)
{
	CDC MemDC;
	CSerialCommDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
	 return;
	CString mystr=SerialPortContinuousRead(); ===> works fine
	mystr += "\r\n";

	CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
	CEdit* DispBox=(CEdit*)pFrame->m_wndDlgBar.GetDlgItem(IDC_DISPLAY_BOX); 
	DispBox->SetWindowTextW(mystr);
}


When I have break points in this function it updates the data in edit box, otherwise I can't see the data. Any help appreciated, thanks
Posted
Updated 15-May-10 22:18pm
v2

I don't know if this helps but when I want to update a dialog box with 'real time' data I normally setup a timer to read and display the latest value.

I'm not sure if that's is what you are asking, so I hope that helps. :)
 
Share this answer
 
Hi Alison,

I have added timer to update Edit box. The following code i have in the timer function.

void CSerialCommView::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
  CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
  CEdit* DispBox=(CEdit*)pFrame->m_wndDlgBar.GetDlgItem(IDC_DISPLAY_BOX); 
  dispstr+=mydatastr+_T("\n");
  DispBox->SetWindowTextW(dispstr);
  DispBox->LineScroll(DispBox->GetLineCount());
  Invalidate(true);
 CView::OnTimer(nIDEvent);
}


The problem is,the dialog flickers because of
Invalidate(true)
.

Is there any other method which will just update without flickering problem. :omg:
Thanks.
 
Share this answer
 
Instead of calling Invalidate() after you set the text, try this:
CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
CEdit* DispBox=(CEdit*)pFrame->m_wndDlgBar.GetDlgItem(IDC_DISPLAY_BOX);
DispBox->SetWindowTextW(mystr);
DispBox->UpdateWindow();

That will cause only the edit control to update - not the entire window.

Hope that helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900