Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Creating a Config Panel Applet

0.00/5 (No votes)
11 Oct 2002 1  
Step by step creation of a control panel applet

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

Project Type

Select regular dll using MFC in the second step.

Dll Type

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,    // Handle to Configuration Panel window.

    UINT    aUMsg_in,        // CPL message.

    LPARAM    aLParam1_in,    // First message parameter.

    LPARAM  aLParam2_in    // Second message parameter.

) 

aUMsg_in

This parameter is filled with the CPL related messages like..

//                       | Return            | Return

//    CPL message        | if successfully   | if not successfully

//    -------------------+-------------------+--------------------

//    CPL_INIT           | nonzero           | zero

//    CPL_GETCOUNT       | nonzero           | zero

//    CPL_NEWINQUIRE     | zero              | nonzero

//    CPL_SELECT         | zero              | nonzero

//    CPL_DBLCLK         | zero              | nonzero

//    CPL_STOP           | zero              | nonzero

//    CPL_EXIT           | zero              | nonzero

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here