Controls are flickering in MFC CView(MDI)
-
Dear Friends, Am developing a client server application. Am using MFC MDI. It has multiple class. One class is showing live values so i used Editbox and CListCtrl control. I was create these control in
onCreate()
function. It shows live in
onDraw()
function
GetDlgItem(IDC_EDITBOX)->SetWindowText(sLiveValues);
it is also updating a value but it is getting flicker. If i use
InvalidateRect()
function it is not flickering but not update any value. So i need to update live value in any control like EditBox,CListCtrl without flicker. How to avoid flickering. Please help me.
-
Dear Friends, Am developing a client server application. Am using MFC MDI. It has multiple class. One class is showing live values so i used Editbox and CListCtrl control. I was create these control in
onCreate()
function. It shows live in
onDraw()
function
GetDlgItem(IDC_EDITBOX)->SetWindowText(sLiveValues);
it is also updating a value but it is getting flicker. If i use
InvalidateRect()
function it is not flickering but not update any value. So i need to update live value in any control like EditBox,CListCtrl without flicker. How to avoid flickering. Please help me.
If I understand you correctly, you are calling SetWindowText() from onDraw(). This is a problem, because SetWindowText() invokes drawing of the control. So your apllication is permanently redrawing its GUI. I would suggest that you store the values in the receiving function in a thread-safe way (look for CRITICAL_SECTION in the documentation). Then create a timer (look for SetTimer()) and in the timer function again in a thread-safe way copy the data to a local variable and display the copy with SetWindowText(). The OnTimer function could look something like this:
void YourDialog::OnTimer(UINT nIDEvent)
{
if (nIDEvent == YourTimerId)
{
EnterCriticalSection(&yourCriticalSection);
CString values = sLiveValues;
LeaveCriticalSection(&yourCriticalSection);
GetDlgItem(IDC_EDITBOX)->SetWindowText(values);
}
}You can run the timer in any interval convenient for your users.
The good thing about pessimism is, that you are always either right or pleasently surprised.