Click here to Skip to main content
15,867,771 members
Articles / Desktop Programming / MFC
Article

Creating a Config Panel Applet

Rate me:
Please Sign up or sign in to vote.
4.08/5 (6 votes)
11 Oct 20024 min read 91.3K   2K   34   12
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


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questioncan open .cpl file in other dir. except system32 dir. Pin
wanrue9-Jul-12 20:54
wanrue9-Jul-12 20:54 
GeneralIcon problem Pin
r4dius2-Mar-07 8:49
r4dius2-Mar-07 8:49 
GeneralRe: Icon problem Pin
Nilesh K.5-Mar-07 16:07
Nilesh K.5-Mar-07 16:07 
GeneralWon't show up in control panel Pin
malignant5-Jan-06 10:08
malignant5-Jan-06 10:08 
Generaldelete the control panel item in WIN2k system Pin
Member 177242210-Jul-05 16:43
Member 177242210-Jul-05 16:43 
GeneralRe: delete the control panel item in WIN2k system Pin
Nilesh K.11-Jul-05 0:47
Nilesh K.11-Jul-05 0:47 
GeneralRe: delete the control panel item in WIN2k system Pin
Member 177242221-Jul-05 20:21
Member 177242221-Jul-05 20:21 
Nilesh K. wrote:
Loading and unloading of cpl files in XP is different from win2k.

Thanks for your reply.
by the way, what is the difference? can I delete the CPL file in system32 (after opening control panel) when i am using CPL_NEWINQUIRE message.

And How can i update the control panel (with the same effect as pressing F5) in C++ code?

I am waiting for the help......




never say never
GeneralRe: delete the control panel item in WIN2k system Pin
Nilesh K.21-Jul-05 22:18
Nilesh K.21-Jul-05 22:18 
GeneralRe: delete the control panel item in WIN2k system Pin
Ahmad Mahmoud [candseeme]4-Jan-06 0:56
Ahmad Mahmoud [candseeme]4-Jan-06 0:56 
GeneralDebugging Control Panel Applets Pin
Stuart Hart29-Aug-03 5:22
Stuart Hart29-Aug-03 5:22 
GeneralRe: Debugging Control Panel Applets Pin
Igor Mladenovic20-Jul-06 8:55
Igor Mladenovic20-Jul-06 8:55 
GeneralEnumerating Control Panel Applets Pin
Sireesh Tripurari31-Dec-02 0:45
sussSireesh Tripurari31-Dec-02 0:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.