Page 3 of 4
Re: MiniBrowser
Posted: Fri Jun 04, 2021 1:42 pm
by salvadordf
Read this :
https://stackoverflow.com/questions/39807377/how-to-get-windows-shutdown-event-in-fmx-project-as-wm-queryendsession-and-wm-en
Perhaps the second answer can help you.
Re: MiniBrowser
Posted: Sat Jun 05, 2021 2:39 pm
by Cantar
Looking at the information on Google, it can be concluded that Chromium1,
that is, CEFWindowParent1,receives a WM_QUERYENDSESSION message,
but not the main form.
Can you implement a mechanism for passing these messages from Chromium1
to the main form VCL project?
Re: MiniBrowser
Posted: Sun Jun 06, 2021 8:05 am
by salvadordf
I just added this to the MiniBrowser demo to test this :
Code: Select all
protected
procedure WMEndSession(var aMessage: TWMQueryEndSession); message WM_QUERYENDSESSION;
Code: Select all
procedure TMiniBrowserFrm.WMEndSession(var aMessage: TWMQueryEndSession);
var
TempSL : TStringList;
begin
TempSL := TStringList.Create;
TempSL.Add('TMiniBrowserFrm.WMEndSession');
TempSL.SaveToFile('1.txt');
TempSL.Free;
inherited;
end;
When I run the demo and closed the user session the demo created a file called
1.txt which means that the WM_QUERYENDSESSION message was received by the main form correctly. That message was not intercepted by Chromium.
Some other messages are intercepted by Chromium and you may get them in the
TChromium.OnRenderCompMsg event.
Re: MiniBrowser
Posted: Mon Jun 07, 2021 6:03 am
by Cantar
Thanks.
Re: MiniBrowser
Posted: Thu Jun 10, 2021 5:31 pm
by Cantar
When you click on the "Close" button, the application is quickly completed.
Below are the results of debugging the application closing.
Code: Select all
10.06.2021 19:37:54.872 FormCreated
10.06.2021 19:37:55.028 Chromium1AfterCreated CEF_AFTERCREATED
10.06.2021 20:23:11.638 FormCloseQuery CanClose 0
10.06.2021 20:23:11.674 Chromium1Close CEF_DESTROY cbaDelay
10.06.2021 20:23:11.678 BrowserDestroyMsg CEFWindowParent1 Free
10.06.2021 20:23:11.679 FormCloseQuery CanClose 1
10.06.2021 20:23:11.682 FormClose
However, when Win7 is turned off, and the form is not closed, the system requires
confirmation of the forced closing of the application. It is not very fast.
Project using third-party components. What's wrong?
Debug results of closing the application at session end.
Code: Select all
10.06.2021 19:50:44.872 FormCreated
10.06.2021 19:50:45.028 Chromium1AfterCreated CEF_AFTERCREATED
10.06.2021 20:23:21.530 FormCloseQuery CanClose 0
10.06.2021 20:23:21.532 Chromium1Close CEF_DESTROY cbaDelay
Re: MiniBrowser
Posted: Fri Jun 11, 2021 4:07 pm
by salvadordf
If the application receives a WM_QUERYENDSESSION message then make sure it calls TChromium.CloseBrowser(TRUE);
The TRUE parameter will skip the JavaScript dialogs that ask the user for some confirmation before closing the browser.
I would also suggest that you send a WM_QUERYENDSESSION message manually while debugging your application in Delphi to see what could be the problem.
Re: MiniBrowser
Posted: Sat Jun 12, 2021 3:22 pm
by Cantar
Thanks.
Yes I am calling TChromium.CloseBrowser (TRUE);
The cbaDelay parameter is set in the TChromium.Close event
When I manually send a WM_QUERYENDSESSION, the application immediately stops running.
Re: MiniBrowser
Posted: Sun Jun 13, 2021 4:43 pm
by salvadordf
I read a few more pages about this and I can see clearly that I was wrong about the "
end session" handling.
Chromium handles those two windows messages but the CEF source code don't :
https://source.chromium.org/search?q=WM_QUERYENDSESSION&ss=chromium
https://source.chromium.org/search?q=WM_ENDSESSION&ss=chromium
More information and guidelines from Microsoft :
https://docs.microsoft.com/en-us/windows/win32/rstmgr/guidelines-for-applications
https://docs.microsoft.com/en-us/windows/win32/shutdown/shutdown-changes-for-windows-vista
https://docs.microsoft.com/en-us/windows/win32/shutdown/wm-endsession
https://docs.microsoft.com/en-us/windows/win32/shutdown/wm-queryendsession
The CEF project maintainer gives this workaround :
https://magpcss.org/ceforum/viewtopic.php?f=6&t=15097
The are some interesting suggestions in this answer :
https://stackoverflow.com/questions/39807377/how-to-get-windows-shutdown-event-in-fmx-project-as-wm-queryendsession-and-wm-en
In addition to this, Delphi calls HALT when TApplication.WndProc receives a WM_ENDSESSION message.
I'll try to do more tests with all this information as soon as I have time...
Re: MiniBrowser
Posted: Mon Jun 14, 2021 11:05 am
by salvadordf
Please, download CEF4Delphi again.
I just added a workaround for this issue to the
MiniBrowser demo.
TApplication calls HALT when it receives WM_ENDSESSION and we avoid that by returning False to WM_QUERYENDSESSION.
At that moment we can send WM_CLOSE to the main form to close it correctly but Windows may send WM_QUERYENDSESSION and WM_ENDSESSION to the CEF subprocesses before the main process. If that happens the CEF subprocesses will crash.
This is the new procedure in MiniBrowser :
Code: Select all
procedure TMiniBrowserFrm.WMQueryEndSession(var aMessage: TWMQueryEndSession);
begin
// We return False (0) to close the browser correctly while we can.
// This is not what Microsoft recommends doing when an application receives
// WM_QUERYENDSESSION but at least we avoid TApplication calling HALT when
// it receives WM_ENDSESSION.
// The CEF subprocesses may receive WM_QUERYENDSESSION and WM_ENDSESSION
// before the main process and they may crash before closing the main form.
aMessage.Result := 0;
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
Re: MiniBrowser
Posted: Fri Jul 09, 2021 11:21 am
by Cantar
Thanks, It is Ok.
I upgraded my computer. Changed the hard disk on SSD
add 6 GB memory, installed Win10 64
and now the application shutdown immediatly.
Best regerd