Q: How do you implement a custom action in PC Card Manager
3.x? When the user double-clicks our card's desktop icon, we
want to open up our card's application. In PC Card Manager
2.x, this was easily done by responding to the
kCSActionProcSubfunction message, but this
isn't present in PC Card Manager 3.x.
A: You do this by means of a special resource in your
custom card enabler file. The resource is of type
'pccd' and is loaded by name. The resource name
must match the card name, as returned by
PCCardGetCardInfo .
The resource's format is defined by the
PCCardCustomResource , which is declared in
"PCCardEnablerPlugin.h" in Universal Interfaces. A copy of
the definition is given below for your convenience.
struct PCCardCustomResource {
long version;
short customIconID;
short customStringsID;
short customTypeStringIndex;
short customHelpStringIndex;
OSType customAction;
long customActionParam1;
long customActionParam2;
};
typedef struct PCCardCustomResource PCCardCustomResource;
|
The fields are defined as follows:
version
This field must be set to
kPCCardCustomInfoVersion (0).
customIconID
This field must contain the resource ID of an icon
suite in your custom card enabler file, or -1. If it
contains an icon resource ID, the Finder displays that
icon to represent your card on the desktop. If it
contains -1, the Finder does not display an icon for your
card. In that case, the remaining fields in the
'pccd' resource are ignored (you should set
them to 0).
customStringsID
This field must contain the ID of a
'STR#' resource in your custom card enabler
file.
customTypeStringIndex
This field must contain the index in the above
'STR#' resource of the user-visible card
type string for your card.
customHelpStringIndex
This field must contain the index in the above
'STR#' resource of the help string for your
card.
customAction
This field must contain a FindFolder
selector of the folder containing the custom action
application for your card, or 0 to define no custom
action.
customActionParam1
This field must contain the creator
code of your custom action application, or 0
when you are using no custom action.
customActionParam2
This field must contain the file
type of your custom action application, or 0
when you are using no custom action. The file type must
be "launchable," that is, one of the standard
application-like file types that a user can launch in the
Finder. For example, 'APPL' and
'APPC' are acceptable, but
'appe' is not.
When the user double-clicks your PC Card on the desktop,
the Finder will look for an application of type
customActionParam2 and creator
customActionParam1 in the folder that
FindFolder returns when called with
customAction as the folderType
parameter. The Finder will then launch that application as
it would launch any other. Your custom action application
will typically present a user interface directly, but it
might just launch some other application and script its user
interface. The choice is yours.
The following Rez code builds a 'pccd'
resource that specifies a custom action, in this case to
launch an application of type 'APPC' and
creator 'Frog' in the Control Panels folder.
#include "MacTypes.r"
#include "Folders.r"
#include "PCCardEnablerPlugin.r"
resource 'pccd' (0, "Frog Card Name") {
kPCCardCustomInfoVersion,
128, // resource ID of icon suite
128, // resource ID of 'STR#'
1, // type string
2, // help string
kControlPanelFolderType, // custom action in Control Panels folder
'Frog', // custom action creator code
'APPC' // custom action file type
};
resource 'STR#' (128) {
{
"Frog PC Card",
"Frog PC Card\n\n"
"This PC Card allows your computer to nee-deep."
}
};
|
|