Solved

refreshing a form while it's busy

Posted on 2003-11-15
4
229 Views
Last Modified: 2010-04-05
I'm trying to make my program window stay painted even if another screen is activated and displayed in front of it.  This program runs a bunch of external programs.  I also have a duration to show how long it's been running.  My problem is that while I'm waiting for the process to complete, I am trying to make the program refresh the screen so that if I move a window over it, I can still go back to the screen and see the program status.  I don't feel all that confident in my understanding of the difference between update, refresh, and repaint, or what it means for an object to be invalid.  I have tried a bunch of combinations, but none of them work.  Here's what I have for the loop that I use to wait for the running process to complete.  Thanks in advance for your assistance.

repeat
  sleep( 2000 );
  lblTime.Caption := FormatDateTime('nn:ss',Time - StartTime);
  FrmMain.Refresh;
  GetExitCodeProcess(ProcessInfo.hProcess,Resultado);
  Result := Resultado;
until (Result <> STILL_ACTIVE) or Application.Terminated;
0
Comment
Question by:bnac
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
DaFox earned 200 total points
ID: 9754828
Hi,

Application.ProcessMessages doesn't work? E.g. replace sleep(2000) with Application.ProcessMessages...

Markus
0
 
LVL 33

Expert Comment

by:Slick812
ID: 9754936
hello bnac, , you might use a different code to wait for your other process to finish

if FileExists(ProcessInfo.lpFile) and ShellExecuteEx(@ProcessInfo) then
  begin
  while WaitForSingleObject(ProcessInfo.hProcess, 100) <> WAIT_OBJECT_0 do
    begin
    lblTime.Caption := FormatDateTime('nn:ss',Time - StartTime);
    //  if you have Application.ProcessMessages you will NOT need the Refresh
    Application.ProcessMessages;
    end;
  end else
  ShowMessage(SysErrorMessage(GetLastError));
0
 
LVL 3

Author Comment

by:bnac
ID: 9754938
Markus,

I added Application.ProcessMessages, and dropped the sleep time to 250, and it's working exactly as I expected.  Taking out the sleep time caused the program to go from 0% CPU utilization to 90%.  Thanks for your amazingly quick response!

Matt
0
 
LVL 3

Author Comment

by:bnac
ID: 9754982
Slick, Thanks for your reply.  I'm going to keep the wait loop that I have though, because I've used it in a few apps, and it works well.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
proper way to parse text with delphi 7 121
Machine not responding during CopyFile() 3 98
Convert MS Word document to a PDF file 9 78
Firemonkey webbrowser scrollbars ? 1 38
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
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…

770 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