SetDlgItemText( ) - faster update?

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.
LVL 1
GrailmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jtwine100697Commented:
Use CWnd::Invalidate():

   GetDlgItem( IDC_SCREEN ) -> Invalidate();

-=- James.

0
GrailmanAuthor Commented:
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
jtwine100697Commented:
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

MikeP090797Commented:
I think you forgot the UpdateWindow call
0
jtwine100697Commented:
I think you are right! :P

-=- James.
0
sandipCommented:
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
MikeP090797Commented:
Wasn't that what I already said?
0
jtwine100697Commented:
Nuthin' like a little point snatchin' to make yer day... :P

-=- James.
0
GrailmanAuthor Commented:
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
BeatachonCommented:
I don't see why it would make a difference, but try Invalidating() the dialog itself. See what happens.
0
BeatachonCommented:
Try UpdateWindow on the button itself
0
MikeP090797Commented:
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
GrailmanAuthor Commented:
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
chensuCommented:
Hey chensu! That did it. If you lock the question I'll go ahead & give you your points. Thanks.
0
GrailmanAuthor Commented:
  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
jtwine100697Commented:
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
chensuCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.