Display Update Speed for Dialog Boxes

Environment: Visual C++ 6

I've been searching for a simple answer to a problem. I wanted to increase the display update rate for a dialog box. This (modeless) dialog includes a progress bar, and it displays a percentage number and another number indicating progress (initially in edit boxes). When I'd disable the display update functions (m_progress.SetPos() and dlg->UpdateData(FALSE), the function generating these numbers would complete in half the time. I tried using a DC and the TextOut() function (rather than updating the edit boxes), but that didn't speed things up either. Until I looked at the myriad of windows messages sent when I used UpdateData(FALSE) I didn't realize the origin of the wasted time. It's all due to the "repainting" of the main app window (frame). Since I'm (relatively) inexperienced with MFC, I'm delighted to find such a simple solution. When you display the dialog box hide the main window (if you don't require it's use at that time). I don't use the UpdateData(FALSE) function, but I still see the information on the screen, and the progress bar updates as expected (in a negligible amount of time). I'm sure some of you may see holes in my theory, but this works fine for my app.



BOOL CMyDialog::OnInitDialog()
{
 CDialog::OnInitDialog();

 CWnd* temp_main_wnd = AfxGetMainWnd();

 temp_main_wnd->ShowWindow(SW_HIDE);
}


void CMyOperation::GetDataAndDisplay()
{
 unsigned int  m_percent = 0;
 unsigned int  m_other_data = 0;

 int x = 200;
 int y = 200;

 CMyDialog* dlg;

 CDC* TempDC = NULL;
 CDC  LocalDC;

 dlg = new CMyDialog;
 dlg->Create(IDD_MY_DIALOG, NULL);
 dlg->ShowWindow(SW_SHOWNORMAL);

 TempDC = dlg->GetDC();

 LocalDC.m_hAttribDC = TempDC->m_hAttribDC;
 LocalDC.m_hDC = TempDC->m_hDC;

 ...
 ...

 // When it's time to update the display...

 dlg->m_progress.SetPos(m_percent);

 LocalDC.TextOut(x, y, m_percent);
 LocalDC.TextOut(x, y + 50, m_other_data);

 ...
 ...
}

void CMyDialog::OnCancel()
{
 CWnd* temp_main_wnd = AfxGetMainWnd();

 temp_main_wnd->ShowWindow(SW_SHOW);

 CDialog::OnCancel();
}	


Comments

  • Solution from Jeff Prosise

    Posted by Legacy on 02/02/2004 12:00am

    Originally posted by: Anatoly Smelkov

    Take at look at the MSJ article of Feb., 1997:
    http://www.microsoft.com/msj/0297/wicked/wicked0297.aspx

    Reply
  • reducing flicker/speeding update

    Posted by Legacy on 01/08/2002 12:00am

    Originally posted by: paul marston

    Try setting the properties to clip child/sibling!

    even easier!!!

    Reply
  • Another approach

    Posted by Legacy on 08/08/2001 12:00am

    Originally posted by: Yurikus

    You don't have to call UpdateData everytime you need to change a text of the static control (%'s in your case). All you need to do is the following:
    
    

    Suppose we have a pointer to an instance of your dialog (pDlg), a static control with an ID (IDC_STATIC_PERCENT) and a string with text (sPercent)

    1. Drop a static control into you dialog
    2. Use pDlg->SetDlgItemText(IDC_STATIC_PERCENT, sPercent);

    Done!

    Reply
  • Very simple way to update window/dialog display

    Posted by Legacy on 10/25/2000 12:00am

    Originally posted by: Hakan Erdun

    You can use UpdateWindow( ); No need anything else.

    /*
    CWindow::UpdateWindow
    This method updates the client area.

    Syntax:
    BOOL UpdateWindow( );
    */

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Mobile devices, social business apps, and business analytics are converging with the Cloud to create the most substantial changes in technology since the Internet revolution. Businesses have to change the way they think and operate, and with rising budgets for technology, they need someone to provide the services that will keep them competitive in this environment. Learn more about the important technology trends you need to stay on top of to ensure your business doesn't get left behind.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds