?
Solved

Force Window Redraw

Posted on 2003-11-07
5
Medium Priority
?
4,585 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
[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
  • 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 220 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

801 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