Why not callng VpeCloseDoc in VPE_PRINT?

Knowledge exchange related to the VPE Report Engine and PDF Library

Moderator: IDEAL Software Support

Why not callng VpeCloseDoc in VPE_PRINT?

Postby Bengt » Sun Sep 14, 2014 10:31 am

I want to close a document automatically after printing it from a preview. Before reading the VPE DLL Reference manual, I tried to call VpeCloseDoc in the VPE_PRINT event, and it seemed to work.

Then I saw this remark in the manual, 2.7 VPE_PRINT: Do not call VpeCloseDoc() when processing this event. You would terminate a module that is working.

Is there another correct way to programmatically close a preview after printing?
Bengt
 
Posts: 89
Joined: Fri Jan 27, 2006 5:29 pm

Re: Why not callng VpeCloseDoc in VPE_PRINT?

Postby IDEAL Software Support » Mon Sep 15, 2014 6:42 am

It depends, whether a message is sent via Win API SendMessage() or PostMessage().

SendMessage() immediately jumps into the code of your application, therefore it is unsafe to call CloseDoc() from there.

PostMessage() puts the message onto the Windows message queue and is sent to your application when your app enters its main message loop. Here it is safe to call CloseDoc().

We checked our code, and the following messages are sent via SendMessage():
PRINT_MSG_SETUPSTART
PRINT_MSG_SETUPEND
PRINT_MSG_START

The following messages are sent via PostMessage():
PRINT_MSG_SETUPABORT
PRINT_MSG_ABORT
PRINT_MSG_END

Therefore it is safe to call CloseDoc() when receiving PRINT_MSG_ABORT or PRINT_MSG_END.

Otherwise - when receiving a message which does not allow to call CloseDoc() - you can always PostMessage() yourself a WM_USER message and close the document when receiving it. Or you can start a timer and close the document when the timer has finished.
IDEAL Software Support
 
Posts: 1621
Joined: Thu Nov 18, 2004 4:03 pm


Return to VPE Open Forum

Who is online

Users browsing this forum: No registered users and 10 guests

cron