Solved

Force Window Redraw

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

726 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