
Adobe Acrobat SDK
Creating Menus and Menu Commands
Developing Plug-ins and Applications
Creating menu callback functions 94
After you create a pointer, such as a pointer that points to
AVExecuteProc
, you can invoke the
ASCallbackCreateProto
macro that is defined in the Acrobat core API to convert a user-defined
function to an Acrobat callback function. For example, you can invoke
ASCallbackCreateProto
to
convert
ShowMessage
to a callback function. The
ASCallbackCreateProto
macro requires the
following arguments:
●
The callback type. For example, you can pass
AVExecuteProc
.
●
The address of the user-defined function to convert to a callback function.
The
ASCallbackCreateProto
macro returns a callback of the specified type that invokes the
user-defined function whose address was passed as the second argument. The following code example
shows the
ASCallbackCreateProto
macro converting the
ShowMessage
user-defined function to a
AVExecuteProc
callback.
AVExecuteProc ExecProcPtr = NULL;
ExecProcPtr = ASCallbackCreateProto(AVExecuteProc, &ShowMessage);
After you create an
AVExecuteProc
callback, invoke the
AVMenuItemSetExecuteProc
method to
associate a menu command with a callback. That is, when a user selects a specific menu command,
Acrobat or Adobe Reader will invoke the user-defined function whose address was passed to the
ASCallbackCreateProto
macro. The
AVMenuItemSetExecuteProc
method requires the following
parameters:
●
An
AVMenuItem
instance that represents the menu command.
●
An
AVExecuteProc
that represents the callback function.
●
The address of a user-defined data structure that can be passed to the user-defined function.
When you are done with a menu callback, you can invoke the
ASCallbackDestroy
method to release
memory that it consumes. The following code example creates callback functions for menu commands.
Example 6.3
Creating menu callback functions
/* Display a message box */
ACCB1 void ACCB2 ShowMessage (void* data)
{
AVAlertNote ("A menu command was selected.");
}
ACCB1 ASBool ACCB2 ComputeMarkedProc (void* data)
{
ASBool expressionorcondition = true;
if (expressionorcondition)
return true;
else return false;
}
ACCB1 ASBool ACCB2 ComputeEnabledProc (void* data)
{
if (AVAppGetNumDocs() > 0)
return true;
else return false;
}
ACCB1 ASBool ACCB2 PluginInit (void)
{
//Declare menu callbacks
AVExecuteProc ExecProcPtr = NULL;