?
Solved

SetDlgItemText( )  - faster update?

Posted on 1998-03-05
17
Medium Priority
?
806 Views
Last Modified: 2013-11-20
I have a dialog box app created in VC 5.0 that has, among
other things, an edit box 'IDC_SCREEN' and a button that is
mapped to fx 'OnTest()'. When I hit the button I update the
edit box by updateing a CString and then updateing the
box contents:
      m_strScreen+="\r\nStarting work";
      SetDlgItemText( IDC_SCREEN, m_strScreen);

Then I do some work that may take a while:
        BigProcess();

When I finish I update again:
      m_strScreen+="\r\nDone with work";
      SetDlgItemText( IDC_SCREEN, m_strScreen);

The problem is that the edit box does not get updated until
the OnTest function exits, thus putting both messages up at the same time. How can I update the edit box while I'm still in the OnTest function? I've tried using UpdateData after the first string addition my first message but this does not make any diffrence.
0
Comment
Question by:Grailman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +3
17 Comments
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1316778
Use CWnd::Invalidate():

   GetDlgItem( IDC_SCREEN ) -> Invalidate();

-=- James.

0
 
LVL 1

Author Comment

by:Grailman
ID: 1316779
I tried using invalidate right after my first message is set:

   m_strScreen+="\r\nStarting work";
   SetDlgItemText( IDC_SCREEN, m_strScreen);
   GetDlgItem(IDC_SCREEN)->Invalidate();

but it still won't update until the function finishes.
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1316780
No joke?

   What kind of hardware are you running on...  On most of the systems I work on, this works.  Do you have a slow graphics sub-system?

   Try Sleep()-ing (or possibly a quick message pump) in between the Invalidate and BigProcess() calls.

-=- James.
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 8

Expert Comment

by:MikeP090797
ID: 1316781
I think you forgot the UpdateWindow call
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1316782
I think you are right! :P

-=- James.
0
 

Expert Comment

by:sandip
ID: 1316783
Try folllowing code :
(I gurantee that it will work).
You should call UpdateWindow() after each call to SetDlgItemText();

void CYourClassDlg::OnTest()
{
      m_strScreen += "\r\n Starting Work";
      
      SetDlgItemText(IDC_SCREEN,m_strScreen);
      UpdateWindow();
      for(long i = 0; i < 100000000 ; i++)      
                        ;      
      m_strScreen += "\r\nWork Done";
      SetDlgItemText(IDC_SCREEN,m_strScreen);
      UpdateWindow();
}
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1316784
Wasn't that what I already said?
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1316785
Nuthin' like a little point snatchin' to make yer day... :P

-=- James.
0
 
LVL 1

Author Comment

by:Grailman
ID: 1316786
Alright I give up, let me in on the joke ok? I've tried this exact code with only UpdateWindow, only Invalidate, both Invalidate and UpdateWindow using UpdateWindow first and then using Invalidate first:

      m_strScreen+="\r\nScreen will be cleared";
      SetDlgItemText( IDC_SCREEN, m_strScreen);
      Sleep(5000);
      GetDlgItem( IDC_SCREEN ) -> Invalidate();
      UpdateWindow();
      m_strScreen = "";
      SetDlgItemText( IDC_SCREEN, m_strScreen);

It flat out will not update the window until the function exits. As for the hardware it's just a Compaq P133 w/ 32MB, Win95 4.00.950a and a cheap 14" Dell Ultrascan monitor. Oh and the VC version is 4 not 5 (forgot I was at work when I asked this). I can hit buttons w/ other messages and display them (of course) as fast as I can hit them.
0
 

Expert Comment

by:Beatachon
ID: 1316787
I don't see why it would make a difference, but try Invalidating() the dialog itself. See what happens.
0
 

Expert Comment

by:Beatachon
ID: 1316788
Try UpdateWindow on the button itself
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1316789
Hey sandip, was that a 'money back guarantee'? Well Invalidate on the whole dialog itself doesn't either work BUT... both the button or a static text box will be updated immediatly. Why won't an edit box!?!?!
0
 
LVL 1

Author Comment

by:Grailman
ID: 1316790
The Invalidate() function marks the window for painting when the next WM_PAINT message occurs. It adds a rectangle to the specified window’s update region. The UpdateWindow() function updates the client area of the specified window by sending a WM_PAINT message to the window if the window’s update region is not empty. The function sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue. If the update region is empty, no message is sent. So, you invalidate the edit box but the dialog box is still valid. The UpdateWindow() actually does not send a WM_PAINT message.

m_strScreen+="\r\nScreen will be cleared";
SetDlgItemText( IDC_SCREEN, m_strScreen);
GetDlgItem( IDC_SCREEN ) -> Invalidate();
GetDlgItem( IDC_SCREEN ) -> UpdateWindow();

Sleep(5000);

m_strScreen = "";
SetDlgItemText( IDC_SCREEN, m_strScreen);
GetDlgItem( IDC_SCREEN ) -> Invalidate();
GetDlgItem( IDC_SCREEN ) -> UpdateWindow();


0
 
LVL 23

Expert Comment

by:chensu
ID: 1316791
Hey chensu! That did it. If you lock the question I'll go ahead & give you your points. Thanks.
0
 
LVL 1

Author Comment

by:Grailman
ID: 1316792
  I do not get it...  When you put my suggestion, your reply, and "MikeP"'s comment together, you get what "chensu" just put up.  But it did not work for you then?

   Strange...

-=- James.
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1316793
The Invalidate() function marks the window for painting when the next WM_PAINT message occurs. It adds a rectangle to the specified window’s update region. The UpdateWindow() function updates the client area of the specified window by sending a WM_PAINT message to the window if the window’s update region is not empty. The function sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue. If the update region is empty, no message is sent. So, you invalidate the edit box but the dialog box is still valid. The UpdateWindow() actually does not send a WM_PAINT message.

m_strScreen+="\r\nScreen will be cleared";
SetDlgItemText( IDC_SCREEN, m_strScreen);
GetDlgItem( IDC_SCREEN ) -> Invalidate();
GetDlgItem( IDC_SCREEN ) -> UpdateWindow();

Sleep(5000);

m_strScreen = "";
SetDlgItemText( IDC_SCREEN, m_strScreen);
GetDlgItem( IDC_SCREEN ) -> Invalidate();
GetDlgItem( IDC_SCREEN ) -> UpdateWindow();


Thank you.
0
 
LVL 23

Accepted Solution

by:
chensu earned 200 total points
ID: 1316794
jtwine,

Yes, combining all of your comments may get the code I give. But it seems that none of you explains the reason clearly.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question