Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SetDlgItemText( )  - faster update?

Posted on 1998-03-05
17
Medium Priority
?
843 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

604 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