Wednesday, October 6, 2010

In-depth programming: Control panel Know (Part One)


Control panel, you know how much. When you install some applications, does it feel to your control panel to increase the number of components, such as the installation of the Borland C + + Builder after, "BDE Administrator" go into your control panel, will increase installed QuickTime "QuickTime "component, what they tell us, I think it just illustrates the fact that:" Control Panel "can be manipulated, you can control your control panel, it is not no mystery at all, which in the end how to manipulate it This is what I discuss today's topic, where I will lead you a light into the dark places to explore the "Control Panel" this little-known theme. I mainly consists of three parts to elaborate: (As the article size limit, I decided to split into two chapters to present)

1, Control Panel, what, where is it?

2, CPL true identity documents

3, VCL how to provide the "Control Panel" support

What is the Control Panel, where is it?

Control panel is what it is? Previously, I am confused, but occasionally from a number of "Windows system management" books dim to hear on "Control Panel" description: "Each of the control panel usually corresponds to a. CPL files that are stored in system directory, you can specify the control panel to display items, etc. can also be hidden, "about how to implement, may also teach you modify the registry to achieve their goals, yes, this can achieve their goals, but I think this is just from the perspective of a manager to the issue, from a programmer's point of view, how, and their description can solve your problem? How do you control your use of procedures to achieve "Control Panel" purposes, you would like to know, listen below decomposition.

The true identity of CPL files

Mentioned above to ". CPL" extension at the end of file ", since it related with the control panel, which I have to analyze what is right CPL file in the end, stuffing CPL files, such as: main.cpl, access.cpl etc. I used Dumpbin test results are as follows:

C: WINDOWSsystem32> 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 (the DLL can tell it is a DLL file)

C: WINDOWSsystem32> 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: WINDOWSsystem32> 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




[Next]



2 1 00004B33 DebugMain

3 2 00004B30 DllRegisterServer

3 3 00004A27 DllUnregisterServer

Test results from the above what you see, I think there are at least two points:

1, CPL file is a DLL file

2, CPL files are exported function of a CPLApplet

These two procedures opened the mystery of the Control Panel, you will not What is the procedure on the control panel was puzzled, but in fact, the control panel program is a required DLL file export CPLApplet function, but we put a name suffix CPL only. Since the function must be exported CPLApplet can imagine CPLApplet the importance of this function, in fact, not only is the control panel, as long as the CPL file is to load all other applications must be made CPLApplet address of the function and then call the function to be completed by the appropriate may function, the following MSDN I come from a statement on its detailed information please refer to MSDN.

LONG APIENTRY CPlApplet (
HWND hwndCPl,
UINT uMsg,
LONG lParam1,
LONG lParam2
);
The significance of parameters
hwndCPl activate the Control Panel window handle the application components
uMsg outside the control of incoming messages, CPLApplet function is passed the message to complete
The corresponding tasks
lParam1 message parameter 1
lParam2 message parameter 2
CPLApplet function can accept a list of control messages:

Message Description

鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?br />
CPL_INIT CPL program received the first message, here it is usually the control panel components to complete the initialization of data and variables

CPL_GETCOUNT CPLApplet function following CPL_INIT received the news of the second message, which makes CPLApplet function returns the CPL file contains the number of control panel components

CPL_INQUIRE CPL_INQUIRE and the next one to be introduced CPL_NEWINQUIRE news is all the news programs in the Control Panel the two most important messages, can be said that the control panel is the use of these two sources to obtain each component of the name, description and other information icons . CPL_INQUIRE component information will fill TCPLInfo the structure, TCPLInfo structure of a statement as follows:

typedef struct tagCPLINFO (
int idIcon;
int idName;
int idInfo;
LONG lData;
) CPLINFO;
typedef tagCPLINFO TCPLInfo;
Then your program can use LoadString, LoadIcon (the API

Function LoadImage function has been replaced, but you can still use) and other API

Function to obtain the appropriate information

CPL_NEWINQUIRE

CPL_NEWINQUIRE and CPL_INQUIRE news features almost completed, but it will fill TNewCPLInfo component information structure rather than TCPLInfo structure, a look at the name to know CPL_NEWINQUIRE later than CPL_INQUIRE out, according to conventional thinking, priority should normally be obtained after the out Even with CPL_NEWINQUIRE, but this is an exception, TNewCPLInfo structure compared with a TCPLInfo more complete, but the information it contains can not be cached, so use TNewCPLInfo will slow down to open the control panel, which is Microsoft's document on the state of " unless absolutely necessary, otherwise try to CPL_INQUIRE message to deliver components of information "because

CPL_DBLCLK when the user double-click the Control Panel icon in the component is triggered CPL_DBLCLK message to the user's operation, is generally open a dialog box for users to adjust settings, such as: "Internet Options" will display a relevant IE Settings dialog box, you can set the dialog box IE some of the properties

CPL_STOP this message is to provide opportunities for you to carry out remedial work, such as the release of components related to memory.




[Next]



CPL_EXIT this news is that you were the last chance for rehabilitation, that the application before calling FreeLibray function when you can make some remedial work, such as: free memory, etc.

鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?br />
Note: the information listed in the order of the table is the CPL program also received the news of the order, that CPL program is in accordance with the CPL_INIT, CPL_GETCOUNT to CPL_EXIT to complete the corresponding task.

If you still feel that the abstract description of the above if I had a real following example to illustrate how to set up the control panel in the end application.

Follow these steps:

1: Create the resource file for use in the program, the next plan is to use Borland Resoure Workshop production ctrl.rc situation.


Figure 1-1 Editing the resource file

Hint: 1,2 string and icon resources that code, you can also go after other names do you use brcc32.exe to compile the resource file for the res command as follows:

brc32 ctrl.rc

This will of the ctrl.res compiled resource file, of course, you can use Borland Resoure Workshop to establish Res format, eliminating the need for compiling this link

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

3: Export CPLApplet function, which is the most important, other operations and other procedures do not distinguish

4: From the menu, select "Project / Options" option in "Project Options" Application Options dialog page "Target file extension" to "cpl"

Tip:

Because the program is not executable, it can not run by F9, must control panel or rundll32.exe to run, the first of its CPL file to the system directory Copy, and then use the control panel to run or rundll32.exe to run, command as follows: rundll32 shell32.dll Control_RunDLL *. cpl

Source code is as follows:

# Include

# Include

# Pragma hdrstop

file / / import control panel program associated header files

# Include

# Pragma resource "ctrl.RES"

file / / Export CPlApplet function

extern "C" __declspec (dllexport) LONG _stdcall CPlApplet (

HWND hwndCPl,

UINT uMsg,

LONG lParam1,

LONG lParam2

);

file / / function to achieve CPlApplet

LONG _stdcall CPlApplet (HWND hwndCPl, UINT uMsg, LONG lParam1, LONG lParam2)

(




[Next]



LPCPLINFO ptCPLInfo;

switch (uMsg)

(

case CPL_INIT:

ShowMessage ("initialize data or variable!");

return 1;

case CPL_GETCOUNT:

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

return 1;

case CPL_INQUIRE:

ShowMessage ("Resource Information settings control panel components!");

ptCPLInfo = (LPCPLINFO) lParam2;

file / / fill in the information structure of TCPLInfo

ptCPLInfo-> idName = 1;

ptCPLInfo-> idInfo = 1;

ptCPLInfo-> idIcon = 2;

ptCPLInfo-> lData = 0;

break;

case CPL_DBLCLK:

ShowMessage ("very glad to see you!");

return 0;

case CPL_EXIT:

銆??ShowMessage("閫?嚭鎺у埗闈㈡澘绋嬪簭!");

return 0;

)

return 0;

)

銆??#pragma argsused

銆??int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)

(

return 1;

)

銆??DllEntryPoint鍑芥暟鏄墍鏈塂LL鏂囦欢鐨勫叆鍙e嚱鏁帮紝鐩稿綋浜庡彲鎵ц鏂囦欢鐨刉inMain鍑芥暟锛?include 璇彞瀵煎叆Borland C++ Builder鎵?彁渚涚殑鍏充簬鎺у埗闈㈡澘鐨勭浉鍏冲0鏄庯紝璇彞extern "C" __declspec(dllexport) LONG _stdcall CPlApplet(鈥︹?)瀵煎嚭CPLApplet鍑芥暟

銆??鎻愮ず锛歏CL濡備綍鎻愪緵瀵光?鎺у埗闈㈡澘鈥濈殑鏀寔杩欎竴鑺傚皢鍦ㄢ?鎺у埗闈㈡澘鐭ュ灏戯紙缁瘒锛夆?浠嬬粛






相关链接:



My favorite Anti-Spam And Anti-Spy Tools



The face of OOXML, how can we do?



Cottage in China



Good Teaching And Training Tools



DivX to iPod



Europe And The United States Will Not Be Outsourced As "mirage"?



What is the Best Tone



Yang And His Right-hand Man



Photo Pillows Make Great Gifts



reviews Games And Entertainment



TS To MKV



L'Oreal portrait of "Edgar" Human resources together to create



CMMB TD and who needs who more?



3GP to WMV



Shenzhen, Hong Kong: forerunner of attitude



No comments:

Post a Comment