2 {* TKOLCPLApplet object used with TKOLCPLProject to visually create CPL applets.
4 Created for KOL by Bogus³aw Brandys.
9 uses Messages
, Windows
, KOL
;
13 WM_CPL_LAUNCH
= (WM_USER
+1000);
14 WM_CPL_LAUNCHED
= (WM_USER
+1001);
16 // The messages CPlApplet() must handle:
18 { This constant may be used in place of real resource IDs for the idIcon,
19 idName or idInfo members of the CPLINFO structure. Normally, the system
20 uses these values to extract copies of the resources and store them in a
21 cache. Once the resource information is in the cache, the system does not
22 need to load a CPL unless the user actually tries to use it.
24 CPL_DYNAMIC_RES tells the system not to cache the resource, but instead to
25 load the CPL every time it needs to display information about an item. This
26 allows a CPL to dynamically decide what information will be displayed, but
27 is SIGNIFICANTLY SLOWER than displaying information from a cache.
28 Typically, CPL_DYNAMIC_RES is used when a control panel must inspect the
29 runtime status of some device in order to provide text or icons to display.
33 { This message is sent to indicate CPlApplet() was found. lParam1 and lParam2
34 are not defined. Return TRUE or FALSE indicating whether the control panel
39 { This message is sent to determine the number of applets to be displayed.
40 lParam1 and lParam2 are not defined. Return the number of applets you wish
41 to display in the control
46 { This message is sent for information about each applet. lParam1 is the
47 applet number to register, a value from 0 to(CPL_GETCOUNT - 1).
48 lParam2 is a far ptr to a CPLINFO structure. Fill in CPL_INFO's idIcon,
49 idName, idInfo and lData fields with the resource id for an icon to
50 display, name and description string ids, and a long data item
51 associated with applet #lParam1.
55 { This message is sent when the applet's icon has been clicked upon.
56 lParam1 is the applet number which was selected. lParam2 is the
61 { This message is sent when the applet's icon has been double-clicked
62 upon. lParam1 is the applet number which was selected. lParam2 is the
63 applet's lData value. This message should initiate the applet's dialog box.
67 { This message is sent for each applet when the control panel is exiting.
68 lParam1 is the applet number. lParam2 is the applet's lData value.
69 Do applet specific cleaning up here.
73 { This message is sent just before the control panel calls FreeLibrary.
74 lParam1 and lParam2 are not defined.
75 Do non-applet specific cleaning up here.
79 { This is the same as CPL_INQUIRE execpt lParam2 is a pointer to a
80 NEWCPLINFO structure. this will be sent before the CPL_INQUIRE
81 and if it is responed to (return != 0) CPL_INQUIRE will not be sent
85 { This message parallels CPL_DBLCLK in that the applet should initiate
86 its dialog box. where it differs is that this invocation is coming
87 out of RUNDLL, and there may be some extra directions for execution.
88 lParam1: the applet number.
89 lParam2: an LPSTR to any extra directions that might exist.
90 returns: TRUE if the message was handled; FALSE if not.
94 { This message is internal to the Control Panel and MAIN applets.
95 It is only sent when an applet is invoked from the Command line
96 during system installation.
100 TKOLCPLProject
= Pointer;
102 //The data structure CPlApplet() must fill in.
103 PCPLInfo = ^TCPLInfo;
104 tagCPLINFO = packed record
105 idIcon: Integer; // icon resource id, provided by CPlApplet()
106 idName: Integer; // name string res. id, provided by CPlApplet()
107 idInfo: Integer; // info string res. id, provided by CPlApplet()
108 lData : Longint; // user defined data
112 CPLINFO = tagCPLINFO;
113 TCPLInfo = tagCPLINFO;
116 PNewCPLInfoA
= ^TNewCPLInfoA
;
117 PNewCPLInfo
= PNewCPLInfoA
;
118 tagNEWCPLINFOA
= packed record
119 dwSize
: DWORD
; // similar to the commdlg
121 dwHelpContext
: DWORD
; // help context to use
122 lData
: Longint; // user defined data
123 hIcon
: HICON
; // icon to use, this is owned by CONTROL.EXE (may be deleted)
124 szName
: array[0..31] of AnsiChar
; // short name
125 szInfo
: array[0..63] of AnsiChar
; // long name (status line)
126 szHelpFile
: array[0..127] of AnsiChar
; // path to help file to use
129 tagNEWCPLINFO
= tagNEWCPLINFOA
;
130 NEWCPLINFOA
= tagNEWCPLINFOA
;
131 NEWCPLINFO
= NEWCPLINFOA
;
132 TNewCPLInfoA
= tagNEWCPLINFOA
;
133 TNewCPLInfo
= TNewCPLInfoA
;
136 TCPLExit
= procedure of object;
138 TCPLInit
= procedure (var Initiate
: Boolean) of object;
140 TCPLSel
= procedure (Number
: Longint; Data
: Longint) of object;
142 TCPLParams
= procedure (Number
: Longint; Params
: PChar
; var Handle
: Boolean) of object;
144 TCPLStart
= procedure (Number
: Longint; var NewCPLInfo
: TNewCPLInfo
) of object;
149 PKOLCPLApplet
=^TKOLCPLApplet
;
150 TKOLCPLApplet
= object(TObj
)
154 fOnSelect
,fOnExecute
,fOnStop
: TCPLSel
;
155 fOnStart
: TCPLStart
;
156 fOnParams
: TCPLParams
;
161 destructor Destroy
;virtual;
163 procedure AddIcon(IconRes
,Name
,InfoTip
,Help
: String; Data
,HelpCtx
: Integer);
164 {* Adds applet (icon,necessary name,description,name of help file
165 and help context and simple data sent to applet) to internal object applet's list}
166 property IconList
: PList read fIconList write fIconList
;
167 {* Low level access to applets list}
168 property OnInit
: TCPLInit read fOnInit write fOnInit
;
169 {* Initialize ALL applets. If Initiate = False applets are not loaded}
170 property OnSelect
: TCPLSel read fOnSelect write fOnSelect
;
171 {* Seems not working at all (CPL_SELECT is not invoked by system)}
172 property OnExecute
: TCPLSel read fOnExecute write fOnExecute
;
173 {* When user double-click applet icon}
174 property OnStart
: TCPLStart read fOnStart write fOnStart
;
175 {* After applet icon is created}
176 property OnStop
: TCPLSel read fOnStop write fOnStop
;
177 {* Put applet cleaning here }
178 property OnParams
: TCPLParams read fOnParams write fOnParams
;
179 {* When applet is invoked by rundll with params}
180 property OnExit
: TCPLExit read fOnExit write fOnExit
;
181 {* Just before control panel detach applet's library }
185 function NewCPLApplet
: PKOLCPLApplet
;
186 function Run(hWndCpl
: HWnd
; Msg
: Word; lParam
: longint; var NewCPLInfo
: TNewCPLInfo
): longint;stdcall;
189 CplObj
: PKOLCPLApplet
;
194 destructor TKOLCPLApplet
.Destroy
;
196 CPLInfo
: PNewCPLInfo
;
199 for i
:=0 to fIconList
.Count
-1 do begin
200 CPLInfo
:= PNewCPLInfo(fIconList
.Items
[i
]);
201 // DestroyIcon(CPLInfo.hIcon);
209 procedure TKOLCPLApplet
.AddIcon(IconRes
,Name
,InfoTip
,Help
: String; Data
,HelpCtx
: Integer);
211 CPLInfo
: PNewCPLInfo
;
214 with CPLInfo
^ do begin
215 dwSize
:= sizeof(TNewCPLInfo
);
217 dwHelpContext
:= HelpCtx
;
219 hIcon
:= LoadIcon(hInstance
,PChar(UpperCase(IconRes
)));
220 StrPCopy(szName
,Name
);
221 StrPCopy(szInfo
,InfoTip
);
222 StrPCopy(szHelpFile
,Help
);
224 fIconList
.Add(CPLInfo
);
229 function NewCPLApplet
;
233 Result
.fIconList
:= NewList
;
236 function Run(hWndCpl
: HWnd
; Msg
: Word; lParam
: longint; var NewCPLInfo
: TNewCPLInfo
): longint;stdcall;
239 CPLInfo
: PNewCPLInfo
;
248 Applet
:= NewApplet('');
249 Applet
.Visible
:= False;
250 if Assigned(CplObj
.OnInit
) then CplObj
.OnInit(i
);
251 Result
:= Integer(i
);
256 Result
:= CplObj
.fIconList
.Count
;
261 CPLInfo
:= PNewCPLInfo(CplObj
.fIconList
.Items
[lParam
]);
262 NewCPLInfo
.dwSize
:= sizeof(TNewCPLInfo
);
263 NewCPLInfo
.dwFlags
:= 0;
264 NewCPLInfo
.dwHelpContext
:= CPLInfo
.dwHelpContext
;
265 NewCPLInfo
.lData
:= CPLInfo
.lData
;
266 NewCPLInfo
.hIcon
:= CPLInfo
.hIcon
;
267 StrCopy(NewCPLInfo
.szName
,CPLInfo
.szName
);
268 StrCopy(NewCPLInfo
.szInfo
,CPLInfo
.szInfo
);
269 StrCopy(NewCPLInfo
.szHelpFile
,CPLInfo
.szHelpFile
);
270 if Assigned(CplObj
.OnStart
) then CplObj
.OnStart(lParam
,NewCPLInfo
);
273 CPL_STARTWPARMS
:begin
275 if Assigned(CplObj
.OnParams
) then
276 CplObj
.OnParams(lParam
,PChar(@NewCPLInfo
),i
);
277 Result
:= Integer(i
);
281 if Assigned(CplObj
.OnExecute
) then
282 CplObj
.OnExecute(lParam
,Longint(@NewCPLInfo
));
286 if Assigned(CplObj
.OnSelect
) then
287 CplObj
.OnSelect(lParam
,Longint(@NewCPlInfo
));
290 if Assigned(CplObj
.OnStop
) then
291 CplObj
.OnStop(lParam
,Longint(@NewCPlInfo
));
296 if Assigned(CplObj
.OnExit
) then CplObj
.OnExit
;