Solved

SetDlgItemText( )  - faster update?

Posted on 1998-03-05
17
731 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
  • 5
  • 4
  • 3
  • +3
17 Comments
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
Use CWnd::Invalidate():

   GetDlgItem( IDC_SCREEN ) -> Invalidate();

-=- James.

0
 
LVL 1

Author Comment

by:Grailman
Comment Utility
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
Comment Utility
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
 
LVL 8

Expert Comment

by:MikeP090797
Comment Utility
I think you forgot the UpdateWindow call
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
I think you are right! :P

-=- James.
0
 

Expert Comment

by:sandip
Comment Utility
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
Comment Utility
Wasn't that what I already said?
0
 
LVL 4

Expert Comment

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

-=- James.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:Grailman
Comment Utility
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
Comment Utility
I don't see why it would make a difference, but try Invalidating() the dialog itself. See what happens.
0
 

Expert Comment

by:Beatachon
Comment Utility
Try UpdateWindow on the button itself
0
 
LVL 8

Expert Comment

by:MikeP090797
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
  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
Comment Utility
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 50 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now