• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 848
  • Last Modified:

Message Queue - Invalidate

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
ramsay
Asked:
ramsay
  • 6
  • 3
  • 2
  • +3
1 Solution
 
jstolanCommented:
UpdateWindow()
0
 
jstolanCommented:
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
 
plebelCommented:
UpdateWindow Also call directly the WM_PAINT message
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ramsayAuthor Commented:
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
 
BridgeCommented:
RedrawWindow()
0
 
jstolanCommented:
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
 
ramsayAuthor Commented:
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
 
ramsayAuthor Commented:
Can someone answer?
0
 
BridgeCommented:
Did you try CWnd::RedrawWindow() ??
0
 
ramsayAuthor Commented:
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
 
ramsayAuthor Commented:
points increased
0
 
VAM345Commented:
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
 
polimetlaCommented:
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
 
ramsayAuthor Commented:
I lockedupdate then did all the drawing stuff then unlocked the update.. stopped all the smeg being shown.

0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 6
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now