Solved

Force Window Redraw

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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
Macro to save highlighted rows as a separate file 5 51
Looking for a specific application/software 2 124
sumNumber challenge 16 145
x-bar in Google Sheets 2 123
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Suggested Courses

738 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