Solved

Message Queue - Invalidate

Posted on 1998-09-10
14
822 Views
Last Modified: 2013-11-20
Ok when i call invalidate it places the message at the end of the message queue and even when i send more messages Invalidate is the last thing it does..
So my question is how would you invalidate a window and force it to invalidate first with out processing all the other messages first?

thanks in advance Mr Ramsay
0
Comment
Question by:ramsay
  • 6
  • 3
  • 2
  • +3
14 Comments
 
LVL 2

Expert Comment

by:jstolan
ID: 1322031
UpdateWindow()
0
 
LVL 2

Expert Comment

by:jstolan
ID: 1322032
Actually to elaborate a little, if you want to repaint immediately first you Invalidate, then call UpdateWindow.  Note that you can also update smaller portions of the window by calling InvalidateRect or InvalidateRgn instead of Invalidate.  The call will look something like this

Invalidate();
UpdateWindow();

If you don't invalidate something first (the update region is empty), then UpdateWindow does nothing.
0
 
LVL 1

Expert Comment

by:plebel
ID: 1322033
UpdateWindow Also call directly the WM_PAINT message
0
 
LVL 1

Author Comment

by:ramsay
ID: 1322034
ok this is the code below..
unfortunatly your suggestion doesnt work.

the window updates then
runs the function below
then invalidates.

so possibly another way would be to insert some kind of pause between the two blocks of code to allow the window to fully invalidate before it goes on.. any other suggestions?



   Invalidate();    
    UpdateWindow();  
   
    //need to insert a pause here.

    CPoint oldpt,newpt;
    oldpt = GetScrollPosition();
    newpt.Offset(GetTotalSize());
    if (newpt != oldpt) {
        ScrollToPosition(newpt);
    }
0
 
LVL 1

Expert Comment

by:Bridge
ID: 1322035
RedrawWindow()
0
 
LVL 2

Expert Comment

by:jstolan
ID: 1322036
I'm not sure I understand what you're trying to do.  Your idea of the pause to allow the window to fully invalidate won't work.  Invalidate fully invalidates the window immediately.  UpdateWindow sends an immediate WM_PAINT, bypassing the message queu, which then draws the window and validates it.

When you say "Invalidate" do you mean to draw the results immediately as you said in your original question.  If so, my suggestion will work, you simply have to put it in the right place.  Try moving the Invalidate, UpdateWindow() pair after you've done your ScrollToPosition call.

If by Invalidate you mean something else, please try to clarify a little more.
0
 
LVL 1

Author Comment

by:ramsay
ID: 1322037
Well we can always try a different approach.. ill tell you the whole thing of what i am trying to do.

First of all I have a function called drawstring which adds a line of text to an array of CStrings.  After this is written the invalidate() is called to redraw the window and then I want to adjust the scroll so it alwasy points to the bottom of the screen.

Unfortunatly I have processes which call drawstring in quick succession so that the window only gets invalidated at the end and so the scrolling doesnt take place as it does this BEFORE the invalidate() message gets through.

(Invalidate() is programmed to only execute after all other messages are taken care of)

Now with the update window it doesnt do as good a job as invalidate().

To explain what happens with the pair is as follows:

If a portion of my code executes 3 draw strings here is what happens
1) updatewindow()  -> scroll to bottom()
2) updatewindow()  -> scroll to bottom()
3) updatewindow()  -> scroll to bottom() -> invalidate()
as the invalidatemessage is ALWAYS the last to execute.

Now if updatewindow() did a good job this would not be a problem unfortunatly it paints the screen very poorly.. (the text seems like it has been adjusted to the left about 8 characters.. so it causes a vary bad flicker especially on long operations as invlaidate is always the last message to get sent.)
The big problem is that I have a function that lasts 20 seconds and that whole time the text is adjusted too far to the left(so that the sentences are cut in half).  but Invalidate() does a good job but is executed last so the scrolling doesnt work.

Oh yea sorry bout the rejection but the autograder aparently cuts you off very quickly.

Hope this clarifys the question a bit more.




0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:ramsay
ID: 1322038
Can someone answer?
0
 
LVL 1

Expert Comment

by:Bridge
ID: 1322039
Did you try CWnd::RedrawWindow() ??
0
 
LVL 1

Author Comment

by:ramsay
ID: 1322040
Yes it profuced the same result...

A bit more info..
The reason i need to invalidate the window is because i have an array of strings in the diocument file and it is used to store the messages.  
I need to invalidate the window so i can see those messages..

if you have any other suggestions on how to implement scrolling properly i would appriciate it.

0
 
LVL 1

Author Comment

by:ramsay
ID: 1322041
points increased
0
 
LVL 1

Expert Comment

by:VAM345
ID: 1322042
Try this
Change you code
//need to insert a pause here.
With this

      MSG msg;
      // Îáðàáîòâàò ñå âñè÷êè ñúîáùåíèÿ ÷àêàùè â îïàøêàòà.
      while(PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
            if(!AfxGetThread()->PumpMessage( ) )
            {      
                  ::PostQuitMessage(0);
                  break;
            }


0
 
LVL 1

Accepted Solution

by:
polimetla earned 150 total points
ID: 1322043
Dear brother/sister,

Please try the following statement.
It will force the app. to invalidate.

SendMessage( WM_PAINT, 0, 0 );

any doubts, send mail to me.

with love,
Bhavani P Polimetla
bhavani_73@hotmail.com
0
 
LVL 1

Author Comment

by:ramsay
ID: 1322044
I lockedupdate then did all the drawing stuff then unlocked the update.. stopped all the smeg being shown.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

747 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

13 Experts available now in Live!

Get 1:1 Help Now