I've tried to explain the creation of the control Panel applet in one of the simplest way.
Create a new project of .dll type from the template wizard. Let's name it as ConfigPanel
Select regular dll using MFC in the second step.
following classes would be generated by the template.
ConfigPanel
A class derived from CWinApp
.
ConfigPanel.def
export definition file showing the symbols that are exported.
Add the CPlApplet
function. This function is the entry point of this CPL (control panel application).
LRESULT APIENTRY CPlApplet
(
HWND aHwndCPL_in,
UINT aUMsg_in,
LPARAM aLParam1_in,
LPARAM aLParam2_in
)
aUMsg_in
This parameter is filled with the CPL related messages like..
CPL_INIT
The CPL_INIT message is sent to a Control Panel application to prompt it to perform global initialization, especially memory allocation.
Return Values: If initialization succeeds, a Control Panel application should return
nonzero. Otherwise, it should return zero. If the application returns zero, the
controlling application ends communication and releases the DLL containing the Control Panel application.
Remarks: Because this is the only way a Control Panel application can signal an error
condition, the application should allocate memory in response to this message.
This message is sent immediately after the DLL containing the application is
loaded via LoadLibrary().
CPL_GETCOUNT
The The CPL_GETCOUNT message is sent to a Control Panel application to retrieve the number of dialog boxes supported by the application.
Return Values: A Control Panel application should return the number of dialog boxes it supports.
Remarks: This message is sent immediately after the CPL_INIT
message.
CPL_NEWINQUIRE
The CPL_NEWINQUIRE
message is sent to a Control Panel application to request information about a dialog box that the application supports.
Parameters: Value of aLParam1_in
. Specifies the dialog box number. Value
of aLParam2_in
. Specifies the address of a NEWCPLINFO
structure. The Control Panel application should fill this structure with information about the dialog box.
Return Values: If a Control Panel application processes this message successfully, it should return zero.
Remarks: This message is sent once for each dialog box supported by the application. It is sent immediately after the
CPL_GETCOUNT
message. Upon receiving this message, the application can initialize the dialog box. If the application must allocate memory, it should do so in response to the CPL_INIT message.
CPL_SELECT
The CPL_SELECT
message is sent to a Control Panel application when the user selects the icon of a dialog box supported by the application. Value of
aLParam1_in
. Specifies the dialog box number. Value of aLParam2_in
. Specifies the value that the Control Panel application loaded into the
lData
member of the CPLINFO
or NEWCPLINFO
structure for the dialog box. The application loads the
lData
member in response to the CPL_INQUIRE
or CPL_NEWINQUIRE
message.
Return Values: If a Control Panel application processes this message successfully, it should return zero.
CPL_DBLCLK
The CPL_DBLCLK message is sent to a Control Panel application when the user double-clicks the icon of a dialog box supported by the application.
Parameters: Value of aLParam1_in. Specifies the dialog box number. Value of
aLParam2_in
. Specifies the value that the Control Panel application loaded into the
lData
member of the CPLINFO
or NEWCPLINFO
structure for the dialog box. The application loads
lData
member in response to the CPL_INQUIRE
or CPL_NEWINQUIRE
message.
Return Values: If a Control Panel application processes this message successfully, it should return zero.
Remarks: In response to this message, a Control Panel application must display the corresponding dialog box.
CPL_STOP
The CPL_STOP message is sent once for each dialog box when the application controlling the Control Panel application closes.
Parameters: Value of aLParam1_in
. Specifies the dialog box number. Value of
aLParam2_in
. Specifies the value that the Control Panel application loaded into the
lData
member of the CPLINFO
or NEWCPLINFO
structure for the dialog box. The application loads
lData
member in response to the CPL_INQUIRE
or CPL_NEWINQUIRE
message.
Return Values: A Control Panel application should return the number of dialog boxes it supports.
Remarks: In response to this message, a Control Panel application must perform cleanup for the given dialog box.
CPL_EXIT
The CPL_EXIT
message is sent once to a Control Panel application before the controlling application releases the DLL containing the application.
Return Values: A Control Panel application should return the number of dialog boxes it supports.
Remarks: This message is sent after the last CPL_STOP
message is sent. In response to this message, a Control Panel application must free any memory that it has allocated and perform global-level cleanup.
That's it now you application is ready, but before that don't forget to add CPlApplet PRIVATE
in the export
definition file, otherwise the callback would not be called. :)
The output that you would get after compilation would be of .dll kind rename this file to .cpl and copy it to windows directory and you would see your application in the config panel.
The demo project opens the notepad.exe when double clicked, you can either run any exe from there by giving the path or you can create dialogs as the part of the .cpl itself
There is a MakeCpl.bat in the source directory this would copy the .dll to System32 directory and also rename it to .cpl
Hope the topic would have helped you....
Mail me back in case of any comments or suggestion for the same.