The following example shows the CPlApplet function for a DLL containing three Control Panel applications that set preferences for a component stereo system attached to the computer.
The example uses a programmer-defined StereoApplets array that contains three structures, each corresponding to one of the Control Panel applications. Each structure contains all the information required by the CPL_INQUIRE message, as well as the dialog box template and dialog box procedure required by the CPL_DBLCLK message. The following example fills the structures in the StereoApplets array:
#define NUM_APPLETS 3
typedef struct tagApplets
{
int icon; /* icon-resource identifier */
int namestring; /* name-string resource identifier */
int descstring; /* description-string resource identifier */
int dlgtemplate; /* dialog box template resource identifier */
FARPROC dlgfn; /* dialog box procedure */
} APPLETS;
APPLETS StereoApplets[NUM_APPLETS] =
{
AMP_ICON, AMP_NAME, AMP_DESC, AMP_DLG, AmpDlgProc,
TUNER_ICON, TUNER_NAME, TUNER_DESC, TUNER_DLG, TunerDlgProc,
TAPE_ICON, TAPE_NAME, TAPE_DESC, TAPE_DLG, TapeDlgProc,
};
This code defines the CPlApplet function for the preceding example:
LONG FAR PASCAL CPlApplet(hwndCPL, iMessage, lParam1, lParam2)
HWND hwndCPL; /* handle of Control Panel window */
unsigned int iMessage; /* message */
LONG lParam1; /* first message parameter */
LONG lParam2; /* second message parameter */
{
int i;
LPCPLINFO lpCPlInfo;
i = (int) lParam1;
switch (iMessage) {
case CPL_INIT: /* first message, sent once */
return ((LONG) TRUE);
case CPL_GETCOUNT: /* second message, sent once */
return (NUM_APPLETS);
break;
case CPL_INQUIRE: /* third message, sent once per app */
lpCPlInfo = (LPCPLINFO)lParam2;
lpCPlInfo->idIcon = StereoApplets[i].icon;
lpCPlInfo->idName = StereoApplets[i].namestring;
lpCPlInfo->idInfo = StereoApplets[i].descstring;
lpCPlInfo->lData = 0L;
break;
case CPL_SELECT: /* application selected */
break;
case CPL_DBLCLK: /* application double-clicked */
DialogBox(hInstance,
MAKEINTRESOURCE(StereoApplets[i].dlgtemplate),
hwndCPL, (DLGPROC) StereoApplets[i].dlgfn);
break;
case CPL_STOP: /* sent once per app before CPL_EXIT */
break;
case CPL_EXIT: /* sent once before FreeLibrary called */
break;
default:
break;
}
return (0L);
}