Solved

How to prevent "wait 20 sec." message on shutdown

Posted on 1998-09-27
6
279 Views
Last Modified: 2010-04-06
Im running a backup program on windows shutdown.
How do I prevent the window message:
"wait 20 second for program to finish".

I am running the backup in a FormCloseQuery
and want windows to shoutdown when my backup i done.
0
Comment
Question by:EEsep
6 Comments
 
LVL 1

Expert Comment

by:duke_n
ID: 1340976
didn't get ya.
tell more
0
 
LVL 10

Accepted Solution

by:
viktornet earned 200 total points
ID: 1340977
Instead of OnCloseQuery() use the WMQUERYENDSESSION which will run your code when windows shuts down.......
public
  procedure TForm1.wmQueryEndSession(VAR Msg: TWMQueryEndSession);
    message WM_QueryEndSession;

procedure TForm1.wmQueryEndSession(VAR Msg: TWMQueryEndSession);
begin
  Inherited;
        //Do the process of closing the brocess of backing up stuff....
        Halt;
        Msg.Result := 1;
end;

Regards,
Viktor Ivanov
0
 

Author Comment

by:EEsep
ID: 1340978
Thanks - your solution lets windows shutdown - but the
"wait 20 second for program to finish" message still shows.

Is there any way to prevent that message from showing?


0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Expert Comment

by:viktornet
ID: 1340979
Tell me the Caption of the window ....

When the Dialog box shows to show you that message it's got a Caption, like the name of the window.....like 'Untitled - Notepad'

Tell me that name and it will do it.....

in OnTimer() of some timer.....
var
  H : HWND;
begin
  H := FindWindow(nil, 'TheCaptionOfTheWindow');
  if H <> 0 then
    SendMessage(H, WM_CLOSE, 0,0);
end;

Regards,
Viktor Ivanov
0
 

Author Comment

by:EEsep
ID: 1340980
The caption of the windows message is the same as on my application.

How do I close the correct window?


0
 
LVL 1

Expert Comment

by:pjdb
ID: 1340981
This message is due to the backup that is longer than 20 seconds. To solve it, just trap the OnCloseQuery, cancel the close of windows, do the backup and then close windows. The following code can do it :

in the begining of the form declaration put :
Const
  WM_Backup=WM_User + 1; //window message to ask for the bakup to be done

in the form declaration add :
BackupDone:Boolean;  //true if the backup has been done
procedure DoBackup; message WM_Backup;  //do the backup

in The onShow event of the main form add :
BackupDone:=False  //indicate that the backup has not been done

in the OnCloseQuery of the main form add :
if not BackupDone Then  //test if the backup has been done
Begin  //backup not done -> cancel the close and launch the backup
  CanClose:=False;  //cancel the close of the application (and of windows)
  SendMessage(Handle, WM_Backup, 0, 0); //start the backup via a message (this procedure will end so there will no message on 20 seconds...)
End;

Then add the procedure :
procedure MyForn.DoBackup;
Begin
  Try
//  Do The Backup or anything you want here
  Finally  //no error occur
    BackupDone:=True;  //indicate that the backup has been done -> disable the close trapping
    ExitWindowsEx(EWX_POWEROFF);  //shutdown the computer
  End;
End;

NB : If you want to support windows NT, you have to change the process properties to be able to ask for the system to shut down. If you want this code, just let me know.

JDB
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 85
How to run this video in webbrowse ? 2 68
Delphi XE10, MySQL Query 4 109
Delphi inherited method 6 40
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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