Solved

Force Window Redraw

Posted on 2003-11-07
5
4,495 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

18 Experts available now in Live!

Get 1:1 Help Now