How much is the control panel?

zhaozj2021-02-16  65

How much is the control panel?

Control panel, how much do you know. When you have installed some applications, if you feel that your control panel adds some components, if you have BORLAND C Builder installed, "BDE Administrator" will enter your control panel, and QuickTime will also add "QuickTime". Components, these phenomena, I think it just shows a fact: "Control Panel" can be manipulated, you can also control your control panel, there is no mystery, how can I manipulate, this It is the theme I have to discuss today. Here I will lead you a shallow into the deep to explore the "control panel" this little-known theme. I am divided into 3 parts: (Due to the limitations of the article size, I decided to introduce it into two chapters)

1. What is the control panel, where is it?

2, true identity of the CPL file

3, how VCL provides support for "Control Panel"

What is the control panel, where is it?

What is the control panel? Where is it? In the past, I was also very confused, just occasionally heard the "Control Panel" description from some books about "Windows System Management": "Every item of the control panel generally corresponds to one .cpl file, these files exist Under the system directory, you can specify the items you want to display in the control panel, you can hide, etc. "About how to implement, may also teach you some to achieve the purpose by modifying the registry, yes, this can achieve the purpose, but I Think of this is just from a manager's point of view, if you are from the programmer's perspective, can their description solve your problem? How do you use a program to reach the purpose of controlling your "Control Panel", you want to know, please listen to the decomposition.

True identity of the CPL file

The above mentioned ".CPL" extension file ", since it is related to the control panel, I will analyze what the CPL file is, just find some CPL files, such as: main.cpl, access.cpl, etc. , I use the Dumpbin test results as follows:

C: / windows / system32> dumpbin main.cpl

Microsoft (R) Coff Binary File Dumper Version 6.00.8168

Copyright (c) Microsoft Corp 1992-1998. All Rights Reserved.

Dump of file main.cpl

FILE TYPE: DLL (you can know it is a DLL file)

C: / windows / system32> dumpbin / exports appwiz .cpl

Microsoft (R) Coff Binary File Dumper Version 6.00.8168

Copyright (c) Microsoft Corp 1992-1998. All Rights Reserved.

DUMP OF File AppWiz.cpl

FILE TYPE: DLL

Section Contains The Following Exports for AppWiz.dll

Ordinal Hint Rva Name

1 0 00017926 CPLAPPLET

2 1 00017F05 ConfigStartMenu

. . . . . .

C: / Windows / System32> Dumpbin / Exports Access.cpl

Microsoft (R) Coff Binary File Dumper Version 6.00.8168

Copyright (c) Microsoft Corp 1992-1998. All Rights Reserved.dump of File Access.cpl

FILE TYPE: DLL

Section Contains the Following Exports for Access.dll

Ordinal Hint Rva Name

1 0 00004B41 CPLAPPLET

2 1 00004B33 Debugmain

3 2 00004B30 DLLREGISTERSERVER

3 3 00004A27 DLLUNREGISTERSERVER

From the above test results, what do you see, I think there are at least two:

1, the CPL file is a DLL file

2, the CPL file exports a CPLAPPLET function

These two points uncover the mystery of the control panel program, you will not be confused about the control panel program, in fact, the control panel program is a DLL file that must export the CPLApplet function, just hangs the suffix name of the CPL Yes. Since all the CPLApplet functions can be exported, you can imagine the importance of the function of the CPLApplet, in fact, not only the control panel, as long as all all applications that want to load the CPL file must obtain the address of the CPLApplet function and then call the function to complete the corresponding Function, the following is the statement about it from MSDN, please refer to MSDN for details.

Long Apientry CPLApplet

HWND HWNDCPL,

UINT UMSG,

Long Lparam1,

Long lparam2

);

Meaning of parameters

HWNDCPL activates the window handle of the Control Panel Component Application

UMSG external incoming control message, the cplapplet function is to complete through this message

Corresponding task

LPARAM1 Message Parameters 1

LPARAM2 Message Parameters 2

CPLAPPLET function acceptable control message list:

Message description

━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The first message received by the CPL_INIT CPL program, which usually completes the initialization of the control panel component data and variables here.

The CPL_GETCOUNT CPLAPPLET function received the second message after the CPL_INIT message, which causes the CPLAPPLET function to return the number of control panel components included in the CPL file.

CPL_INQUIRE CPL_INQUIRE and the next CPL_Newinquire message to be described is the most important message in all control panel messages, which can say that the control panel is to use these two messages to acquire the name, description, and icon of each component. CPL_INQUIRE fills the component information into the structure of TCPLINFO, the declaration of the TCPLINFO structure is as follows:

Typedef struct tagcplinfo {

Int idicon;

Int idName;

Int iDinfo;

Long LDATA;

} CPLinfo;

Typedef tagcplinfo tcplinfo;

Then you can use LoadString, Loadicon (this API)

The function has been replaced by the loadImage function, but you can still use it), etc. API

Function to achieve the corresponding information

CPL_Newinquire

CPL_NEWINQUIRE is similar to the function completed by the CPL_INQUIRE message, but it will fill the component information in the TNewCPLINFO structure instead of the TCPLINFO structure. When the name knows the name of CPL_Newinquire, it will be prioritized by conventional thinking, Using CPL_Newinquire, but this is an exception. Although the TNewCPLinfo structure is more complete than TCPLINFO, it is unable to cache, so use TNewCPLinfo will slow down the speed of the turning control panel, which is also a Microsoft file to indicate "unless If necessary, otherwise, please try to pass the component information as a CPL_DBLCLK when the user double-click the icon of the component in the control panel, triggers the CPL_DBLCLK message to the corresponding user, usually open a dialog to provide the user to adjust settings Such as: "Internet Option" shows a dialog for IE settings, you can set some properties of IE in this dialog

CPL_STOP This message is mainly to provide opportunities to work after a good job, such as released with components.

CPL_EXIT This message is the last chance of your work, that is, you can make some good work before the application calls the freelyibray function, such as: release memory, etc.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Tip: The message sequence listed above is also the order of the messages received by the CPL program, that is, the CPL program is based on CPL_INIT, CPL_GETCOUNT to CPL_EXIT to complete the corresponding task.

If you still feel abstract on the above description, I will explain how the actual example is how to build the application of the control panel.

The steps are as follows:

1: Establish a resource file to use in the program, the following figure is the case where Ctrl.rc is made with Borland Resound Workshop.

Figure 1-1 Editing a resource file

Tip: 1, 2 Represents the code of the string and the icon resource, you can also go to other names, you can use brcc32.exe to compile it as the RES resource file command as follows:

Brc32 ctrl.rc

This will be compiled by Ctrl.res, of course, you can also use Borland Resound Workshop to establish a file in RES format, save this link.

2: Open your BCB, build a DLL project through DLL Wizard (because the CPL program is a DLL file)

3: Export CPLApplet functions, this is the most important, other operations and other programs have no difference

4: Select the "Project / Options" option from the menu, change the "Target file extension" of the Application page to "CPL" in the "Project Options" option dialog box

prompt:

Since the program is not an executable file, you cannot press F9, you must run through the control panel or Rundll32.exe, first put it under the CPL file copy to the system directory, then use the control panel to run or run, command. As follows: rundll32 shell32.dll control_rundll * .cpl

The source program is as follows:

#include

#include

#pragma HDRSTOP

// Import the header file related to the control panel program

#include

#pragma resource "ctrl.res"

/ / Export CPLApplet function

Extern "C" __declspec (dllexport) long _stdcall CPLApplet (HWND HWNDCPL,

UINT UMSG,

Long Lparam1,

Long lparam2

);

/ / Implement a CPLAPPLET function

Long _stdcall CPLApplet (HWND HWNDCPL, UINT UMSG, Long LParam1, Long LPARAM2)

{

LPCPLINFO PTCPLINFO;

Switch (UMSG)

{

Case CPL_INIT:

ShowMessage ("Initialization Data or Variables!");

Return 1;

Case CPL_Getcount:

ShowMessage ("There is only one component!");

Return 1;

Case CPL_INQUIRE:

ShowMessage ("Sets Control Panel Component Resource Information!");

PTCPLINFO = (LPCPLINFO) LPARAM2;

// Fill information in the structure of TCPLINFO

PTCPLINFO-> IDNAME = 1;

PTCPLINFO-> iDINFO = 1;

PTCPLINFO-> iDicon = 2;

PTCPLINFO-> LDATA = 0;

Break;

Case CPL_DBLCLK:

SHOWMESSAGE ("I am very happy to see you!");

Return 0;

Case CPL_EXIT:

ShowMessage ("Exit Control Panel!");

Return 0;

}

Return 0;

}

#pragma argsused

Int WinApi DLLENTRYPOINT (Hinstance Hinst, Unsigned Long Reason, Void * LPRESERVED)

{

Return 1;

}

The DLLLENTRYPOINT function is the entry function of all DLL files, which is equivalent to the Winmain function of the executable file, and the "# include statement imports the relevant statement provided by the control panel provided by Borland C Builder, statement extern" c "__declspec (dllexport) Long _stdcall CPLAPPLET (...) Exports the CPLAPPLET function

Tip: How VCL provides the support for "Control Panel" will be introduced "" Control Panel knows how much (continued) "

转载请注明原文地址:https://www.9cbs.com/read-22002.html

New Post(0)