Solved

Force Window Redraw

Posted on 2003-11-07
5
4,530 Views
Last Modified: 2013-11-20
Hi,

I have a window that has a progress bar that's supposed to show progress during a long calculation. It works fine except if you place another window over it then remove it - it never receives anymore paint messages. I've tried a list of different functions including :

InvalidateWindow(), UpdateWindow(), RedrawWindow().. then SendMessage(WM_PAINT, 0, 0).

I used these in the function that updates the progress bar so everytime it moves it should redraw its window. But this never occurs and the window will just remain white. Is there any way to really force it to redraw - I thought SendMessage() would not let the program continue until that message was processed?

Thanks
0
Comment
Question by:ragin_cajun
  • 2
  • 2
5 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9706200
Invalidate();
UpdateWindow();

This is a way to force window redraw. When you move another window above your window, Windows invalidates your window. Possibly your window doesn't handle WM_PAINT message. Please show your code - how do you draw progress bar.
0
 
LVL 1

Author Comment

by:ragin_cajun
ID: 9707221
This is basically how my progress bar function will run, all the different methods I tried to use are below:

void CProgressDialog::UpdateProgressBar(int i)
{
    // Set progress bar
    progress_control.SetPos(i);
    i++;
   
    // try 1
    Invalidate();
    UpdateWindow();

    // try 2
    RedrawWindow(0, 0, RDW_UPDATENOW);

    // try 3
    SendMessage(WM_PAINT, 0, 0);

    // try 4 - perhaps update parent instead?    
    CWnd *pParent;
    ::InvalidateRect(pParent->GetSafeHwnd(), NULL, 1);
    ::UpdateWindow(pParent->GetSafeHwnd());

    // try 5
    ::SendMessage(h->GetSafeHwnd(), WM_PAINT, 0, 0);

    // try 6
    ::RedrawWindow(h->GetSafeHwnd(), NULL, NULL, RDW_UPDATENOW);

    // Still no results!!! Window remains unpainted after moving another window above.
}


0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9707560
Read this thread, possibly this may be also your problem:

http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20791684.html
0
 
LVL 3

Accepted Solution

by:
freewell earned 55 total points
ID: 9711935
Inside your calculation loop, add the following codes to allow windows to process the invalidate messages.

MSG msg;
while(bLoop)
{
  // Your loop processing

  pWnd->Invalidate(TRUE);
  while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
  }
}
0
 
LVL 1

Author Comment

by:ragin_cajun
ID: 9712315
That's what I was missing, it worked perfectly, thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ BOOL WINAPI ReadFile fails on windows 10 when reading from USB cable 9 476
sumNumber challenge 16 139
lucky13 challenge 11 155
java ^ examples 8 69
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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