Hi,
I have a problem when using the viewer AxtiveX in VB (Win 7), which is best explained using your VB example OpenDocument.
I added subroutines to handle the QueryUnload and Unload events of the form, so i can close the document and perform some clean-up.
When the QueryUnload event is fired with unload mode 0 (user requested unload) everything is fine. The ActiveX shows the document until i call DoVerb to close it.
But: When QueryUnload is fired with unload mode 2 (windows is about to end or to be signed off), the control does not show the document anymore. It looks like it has already been closed automatically (though there was no OnEvent event with a notification of BeforeCloseDoc). More worse: When calling DoVerb (to close the document or to save settings), runtime error 462 is raised (remote server does not exist or is unavailable).
I need to control the closing of the document even when windows is about to shut down. Can you help?
Thank you and best regards,
Christian
Controlling closing of document when Windows is ending
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
-
- User
- Posts: 12
- Joined: Wed Jul 25, 2012 6:28 pm
-
- Site Admin
- Posts: 2448
- Joined: Thu Jun 30, 2005 4:11 pm
Re: Controlling closing of document when Windows is ending
Hi, Christian,
HTH
You may use next method:I need to control the closing of the document even when windows is about to shut down. Can you help?
Code: Select all
youreventhandler OnEvent(type, name...)
{
if ((type == PXCVA_OnNamedNotify) AND (name == "Notifications.EndSession"))
{
if (YourCheckForCancel())
{
pdfControl.SetProperty("Notifications.EndSession.Cancel", 1); // to prevent shutdown/logoff system
}
return;
}
}
PDF-XChange Co. LTD (Project Developer)
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
-
- User
- Posts: 12
- Joined: Wed Jul 25, 2012 6:28 pm
Re: Controlling closing of document when Windows is ending
Hi,
thank you for the "Notifications.EndSession" tip. I Haven't found it in the manuals.
But I think there is a catch to your code example:
I thought to be smart when replacing YourCheckForCancel() with DoVerb("CloseAllDocuments") and checking for the XCVerr_Abort return code.
But doing so freezes the whole application (i believe it is kind of a deadlock situation, where the event handler waits for completion of other events, which can not occur).
Furthermore, my experience is, that pdfControl.SetProperty("Notifications.EndSession.Cancel", 1) does not prevent the windows shutdown/logoff. It merely prevents the pdf control from unloading. This however helps me to avoid the 462 runtime error, which is fine.
Now my question is: In the event of a windows shutdown, when and where should i place the function calls to save and close my open documents?
Since i believe i cannot stop the Windows shutdown programatically anyhow, I am now just unloading my program in the EndSession event, not attempting any more calls to the PDF-Control. But this is not a good solution.
Regards,
Christian
thank you for the "Notifications.EndSession" tip. I Haven't found it in the manuals.
But I think there is a catch to your code example:
I thought to be smart when replacing YourCheckForCancel() with DoVerb("CloseAllDocuments") and checking for the XCVerr_Abort return code.
But doing so freezes the whole application (i believe it is kind of a deadlock situation, where the event handler waits for completion of other events, which can not occur).
Furthermore, my experience is, that pdfControl.SetProperty("Notifications.EndSession.Cancel", 1) does not prevent the windows shutdown/logoff. It merely prevents the pdf control from unloading. This however helps me to avoid the 462 runtime error, which is fine.
Now my question is: In the event of a windows shutdown, when and where should i place the function calls to save and close my open documents?
Since i believe i cannot stop the Windows shutdown programatically anyhow, I am now just unloading my program in the EndSession event, not attempting any more calls to the PDF-Control. But this is not a good solution.
Regards,
Christian
-
- Site Admin
- Posts: 2448
- Joined: Thu Jun 30, 2005 4:11 pm
Re: Controlling closing of document when Windows is ending
Hi, Christian
Some details about YourCheckForCancel(). Possible implementation:
HTH
Some details about YourCheckForCancel(). Possible implementation:
Code: Select all
bool YourCheckForCancel()
{
int docCnt = 0;
pdfControl.GetDocumentsCount(out docCnt);
if (docCnt == 0)
return false; // we allow shutdown
pdfControl.CloseAllDocuments(0); // or try use it with PXCVA_Sync flag,
// or ask user about closing opened documents by your own message box and then
// if user canceled it - return 'true'
// otherwise - check for unsaved documents and ask about saving of each (if user canceled one - return 'true' also)
// Note: also you may use the pdfControl.CloseAllDocuments(PXCVA_NoUI | PXCVA_Sync) to close forcedly without any asking and saving changes
docCnt = 0;
pdfControl.GetDocumentsCount(out docCnt);
if (docCnt != 0)
return true; // some documents isn't closed - we prevent shutdown because user canceled closing or saving documents
return false; // we allow shutdown
}
PDF-XChange Co. LTD (Project Developer)
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
-
- User
- Posts: 12
- Joined: Wed Jul 25, 2012 6:28 pm
Re: Controlling closing of document when Windows is ending
Hi,
thank your for your code example. It is similar to what I already tried myself. But as i wrote before: The whole application freezes when calling CloseAllDocuments(). The program then has to be terminated from the TaskManager using "End Process".
The crucial hint of you was to use the PXCVA_Sync flag with the function call. Doing so, everything works fine now.
Thank you again for your help.
Best Regards,
Christian
thank your for your code example. It is similar to what I already tried myself. But as i wrote before: The whole application freezes when calling CloseAllDocuments(). The program then has to be terminated from the TaskManager using "End Process".
The crucial hint of you was to use the PXCVA_Sync flag with the function call. Doing so, everything works fine now.
Thank you again for your help.
Best Regards,
Christian
-
- Site Admin
- Posts: 5223
- Joined: Tue Jun 29, 2004 10:34 am
Re: Controlling closing of document when Windows is ending
excellent news - thanks Christian.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.
Best regards
Tracker Support
http://www.tracker-software.com
Best regards
Tracker Support
http://www.tracker-software.com