Control Panel is the control center of Windows 95, which enables you to add new hardware devices, change desktop settings, configure network protocols, and more. In Windows 95, control Panel usually has more than 20 components, and as long as we double-click the icon of any component with the mouse, a dialog box pops up, and the dialog box contains options for setting system parameters, most of which are stored in the Windows 95 registry.
The main program of the----Control Panel is CONTROL.EXE, which locates and winndows\system the Control Panel component in the file name extension cpl at startup and automatically under the directory. The Control Panel component is expandable and some software is automatically added to the new Control Panel component during the installation process. According to the Windows user interface design principle, all parameters affecting the system's overall behavior and interface style should be set through the control Panel, so it is necessary to master the programming method of the Control Panel component.
The Control Panel component works----the various components of the control Panel are special dynamic-link libraries, except that their extension is not a DLL, but a CPL, the abbreviation for the controller.
----control. EXE starts to be transferred to the CPL Library found in the system directory in turn. In general, a CPL Library is responsible for managing only one aspect of the setup, corresponding to one component in the control Panel (that is, an icon), but there are also a few CPL libraries that support multiple components.
----Each CPL library must output a function called Cplapplet () for CONTROL.EXE invocation, Cplapplet () has the following prototypes:
typedef LONG (Apientry *applet_proc) (HWND hwndcpl, UINT msg,long lparam1,long);
----It is easy to see that Cplapplet () is very similar to the normal window processing function, in fact, the control Panel communicates with the CPL Library in the form of sending messages. The parameter hwndcpl is the window handle of the control Panel, MSG is the message identifier, LPARAM1 and lParam2 are additional two parameters, and the specific meaning depends on the value of MSG.
----Control Panel uses the LoadLibrary () function to transfer the CPL library into memory, send a cpl_init message to Cplapplet () immediately to instruct the CPL Library to initialize the work.
----Because this is the only message that allows the failure to be returned, the CPL Library should now allocate all the memory and resources needed during the run, or return 0 if the memory is not sufficient or for other reasons, and the control Panel will no longer process the CPL library and automatically remove it.
----All CPL libraries are initialized, the control panel then sends a CPL_GETCOUNT message to the Cplapplet () function of each CPL library, at which point the CPL Library returns the number of components it supports. Next, the control Panel sends multiple Cpl_newinquire messages to the Cplapplet () function for each component to obtain the corresponding icon, name, and hint information for each component, which can initialize the dialog boxes of each component in turn when processing the message. In Windows 3.x, the Control Panel sends a CPL_INQUIRE message, which is retained in Windows 95, considering compatibility issues, but the CPL Library based on Win 32 only handles new Cpl_newinquire messages.
----This step, the control Panel displays the icons for all components and begins to accept the user's choice. When the user double-clicks the icon for a component, the Control Panel sends a CPL_DBLCLK message to the CPL library where the component is located and indicates that the user has selected the first of the components in the CPL Library, after receiving this message from the INI file or Windows 95 In the registry, read out the original values of the system parameters to be processed, and start the corresponding dialog box to allow the user to change the settings. When the user presses the Apply button during the modification process, the CPL Library saves the new parameter and returns it to the Control Panel, and if the user cancels the change, the CPL library simply returns.
----The control Panel sends a CPL_STOP message to each component when it is closed, and then sends a CPL_EXIT message to each CPL Library, at which point the CPL Library releases the memory and resources allocated in the CPL_INIT message. Finally, the control Panel unloads each CPL library and exits.
----The above is described in the Control Panel components of the working principle, where the specific parameters of the message definition please refer to the win-the SDK.
Using VC + + to write Control Panel components----Writing Control Panel components is actually writing a DLL, with Visual C + + this powerful visual programming tool can easily complete this work. The MFC Basic class library encapsulates the basic framework of the DLL, and we only need to write a cplapplet () function and a dialog box for each component of the message. Unfortunately, the MFC class library does not have ready-made classes on the Control Panel components, in order to fully take advantage of the advantages of C + + language inheritable, the program later in this article gives a control Panel component's base class Ccontrolpanel, its member function provides the processing various CPL message the default code, As soon as we derive a new subclass from this base class and overload the corresponding code for the message that needs to be processed, we can quickly establish a control Panel component.
----The steps to write Control Panel components in Visual C + + are as follows:
Call AppWizard to build a new project, use the application type as an MFC DLL, and connect the MFC class library as a static library, pressing the Finish button to let AppWizard automatically generate the frame file.
Add the CtrlPan.CPP to the project, adding Cplapplet to the output name table of the Def file, then select the settings for the Build menu, and modify the output file with the extension Cpl.
Derive a new subclass from the Ccontrolpanel and overload the partial message code. In most cases, you only need to overload the functions that handle Cpl_newinquire and CPL_DBLCLK messages, as follows:
#include "ctrlpan.h"
class CNewCPL : public CControlPanel
{
public:
virtual LONG OnInquire(UINT uAppNum, NEWCPLINFO* pInfo);
virtual LONG OnDblClk(HWND hwndCPl, UINT uAppNum, LONG lData);
};