Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
STRINGTABLE {
//the "title" of applet #1
10, "Demo Current Time #1"
//the description of applet #1
11, "Shows the current system time..."
//the "title" of applet #2
20, "Demo Current Time #2"
//the description of applet #2
21, "Shows the current system time..." }
12 ICON applet1.ico //the icon for applet #1
22 ICON applet2.ico //the icon for applet #2
library myapplets;
uses SysUtils, Classes, Windows, cpl //a unit in Delphi 3,
frmApplet1 in 'frmApplet1.pas',
frmApplet2 in 'frmApplet2.pas';
{ Demo control panel application
based off of a link to "Creating Control Panel Applets with Delphi" by Ted Houts
cleaned up & posted on tek-tips by Glenn9999 }
{$E cpl} //changes the extension to CPL from DLL
{$R cp_resource.RES} //resource built containing the icons and string for the applets in this .CPL
const
APPLETS_COUNT = 2; //the number of applets (items that show up in Control Panel)
var
Frm_Applet1 : TFrm_Applet1; //applet #1
Frm_Applet2 : TFrm_Applet2; //applet #2
//This procedure puts the action of opening applet dialog boxes into one place
procedure OpenDialogBox(DlgNo,PageNo : Integer);
{
This project has 2 applets (dialogs) which are roughly identical.
If zero is passed, open the first applet; otherwise, one should be passed,
but just in case, any other value for dialog number will open the second applet.
}
begin
if DlgNo = 0 then
begin
Frm_Applet1 := TFrm_Applet1.Create(nil);
// this line puts the icon resource associated with this form in control panel
// to the VCL form itself
Frm_Applet1.Icon.Handle :=
LoadIcon(hInstance, MakeIntResource( (10 * (DlgNo + 1)) + 2));
Frm_Applet1.ShowModal;
end
else
begin
Frm_Applet2 := TFrm_Applet2.Create(nil);
// this line puts the icon resource associated with this form in control panel
// to the VCL form itself
Frm_Applet2.Icon.Handle :=
LoadIcon(hInstance, MakeIntResource( (10 * (DlgNo + 1)) + 2));
Frm_Applet2.ShowModal;
end;
end;
{
CPlApplet is the callback function that processes all messages from
"controlling application", i.e. Control Panel
}
function CPlApplet(hWndCPL : hWnd; iMessage : integer; lParam1 : longint;
lParam2 : longint) : LongInt stdcall;
begin
case iMessage of
CPL_INIT :
//first message, sent once: this is the time to create global objects
begin
Result := 1;
exit;
end;
CPL_GETCOUNT :
//second message sent once, return the number of applets supported by this file
begin
Result := APPLETS_COUNT; //number of dialog boxes supported
exit;
end;
CPL_INQUIRE :
//Filling in the CPLINFO record with resource information. NOTE resource
//file has clever IDs so as to make the code based on the dialog number,
//see cp_resource.rc. lParam1 is zero-based dialog (or applet) number.
//lParam2 is a pointer to a CPLINFO record that's filled with the applet
//information, including "lData," which can point to application-specific
//stuctures. Fill the record and return 0.
begin
PCplInfo(lParam2)^.idName := (10 * (lParam1 + 1)) + 0;
PCplInfo(lParam2)^.idInfo := (10 * (lParam1 + 1)) + 1;
PCplInfo(lParam2)^.idIcon := (10 * (lParam1 + 1)) + 2;
PCplInfo(lParam2)^.lData := 0;
Result := 0; //handled, returning zero
exit;
end;
CPL_NEWINQUIRE :
//This has an identical function to CPL_INQUIRE except that it requires
//a different format set for data. See above for notes.
begin
PNewCplInfo(lParam2)^.dwSize := sizeof(TNewCplInfo);
PNewCplInfo(lParam2)^.lData := 0;
PNewCplInfo(lParam2)^.HIcon :=
LoadIcon(hInstance, MakeIntResource( (10 * (lParam1 + 1)) + 2));
LoadString(hInstance, (10 * (lParam1 + 1)) + 0,
@PNewCplInfo(lParam2)^.szName, sizeof(PNewCplInfo(lParam2).szName));
LoadString(hInstance, (10 * (lParam1 + 1)) + 1,
@PNewCplInfo(lParam2)^.szInfo, sizeof(PNewCplInfo(lParam2).szInfo));
PNewCplInfo(lParam2)^.dwHelpContext := 0;
PNewCplInfo(lParam2)^.szHelpFile[0] := #0;
Result := 0; //handled, returning zero
exit;
end;
CPL_SELECT :
// obsolete message supported for backwards compatibility.
begin
Result := 0;
exit;
end;
CPL_DBLCLK :
//user has double-clicked one of your icons in the control panel, respond here
begin
OpenDialogBox(lParam1,0);
Result := 0; //handled, returning zero
exit;
end;
CPL_STOP :
//sent once per applet, do form shutdown code here.
begin
if lParam1 = 0 then
Frm_Applet1.Free //user has closed Applet #1 form
else
Frm_Applet2.Free; //user has closed Applet #2 form
Result := 0; //handled, returning zero
exit;
end;
CPL_EXIT :
begin //sent once this is the time to free global objects
Result := 0; //handled, return 0
exit;
end;
CPL_STARTWPARMS : //CPL_STARTWPARMSA, CPL_STARTWPARMSW
//sent when applet started via rundll32.exe this .CPL will support an
//integer param to indicate the page number, default to page one
//if invalid
//lParam2 is the parameter string passed in the command line.
//lParam1 and return value are the same as CPL_DBLCLK
begin
OpenDialogBox(lParam1, StrToIntDef(String(lParam2),1));
Result := 1; //handled, so return 1
exit;
end;
else
begin
Result := 0; // return 0 to indicate that this message isn't processed
exit;
end;
end;
end;
//as required export CPLApplet by name
exports CPlApplet name 'CPlApplet';
begin
end.
"C:\Program Files\Borland\Delphi 3\Bin\brcc32.exe" cp_resource.rc
"C:\Program Files\Borland\Delphi 3\Bin\dcc32.exe" myapplets.dpr
rem To Deploy to the system directory if necessary.
rem copy myapplets.cpl C:\Windows\system32
rem clean up old files
del *.~*
pause
rundll32 shell32.dll,Control_RunDLL "myapplets.cpl", @0