Control panel programming

zhaozj2021-02-17  60

Everyone should be very familiar with the control panel. Everyone has operational control panels, but how to use Delphi to program the control panel? First, the principle of the control panel I will tell the principle of the control panel: Control Panel In the System Directory in Windows, all of them are extension in the CPL, which is our control panel. If you want to program the control panel, you must be very familiar with the function of the CPLApplet, which is the core of the CPL file. The prototype is as follows: function cplappTet (hwndcpl: hwnd; umsg: uint; lparam1: lparam; lparam2: lparam): longint; StdCall; Parameter Description: HWNDCPL: Activate the application window handle of the Control Panel component. UMSG: The control message incorporated by the outside world. LPARAM1: Parameters 1 depending on the message type. LPARAM2: Parameters 2 depending on the message type. Return value: Depending on the type of message. When we want to program a CPL file, we load this CPL file, get the CPLAPPLET function address and then call it. The task of the CPLApplet function is to know the outside request and make an appropriate response according to the UMSG message parameters. The message species that can be incompatible are as shown in the following table: The CPL_INIT CPL file is loaded after the CPL file has the opportunity to perform the data structure, variables, and configuration memory, etc. of each control panel component, and obtain the CPL_Getcount to get the CPL file after the CPL_INIT message. The number of control panel components provided by the CPL_INQUIRE takes the information of the individual control panel after the CPL_getcount message, and the information is obtained in the CPL_INQUIRE message, the function is the same as the message CPL_INQUIRE, but the application is different, the components usually only need to choose two One of the control panel components can be activated before the CPL_DBLCLK can activate the individual components. The usual response is displaying the Modal dialog for the user to set the CPL_STOP to activate the control panel assembly in the activation. The control panel program will be sent out. Message to perform the CPL_EXIT Release CPL_exit Release CPL File, the CPL file is released, the control panel is released, providing resource release or other kind of opportunity to work. II. Detailed explanation of the CPLApplet function I will talk now, the above list Detailed effects of each message: 1, CPL_INIT: LPARAM1, LPARAM2: Unused. Return Value: Successful returns a non-zero value; failure returns zero. The first message received by the CPL program must be CPL_INIT, and we can use this opportunity to initialize the data structure and variables shared by all control panel components. If the initialization fails, returns zero, which makes the control panel do not continue to transmit other messages to this CPL file, and the components of the control panel included in this CPL will not appear in the control panel. 2, CPL_Getcount: LPARAM1, LPARAM2: Unused. Return Value: Returns the number of control panel components supported by this CPL file. After the CPL_INIT message, the CPL_GetCount message is followed, and the number of control panel components supported by the CPL file must be returned. 3, CPL_INQUIRE: LPARAM1: Component Number, value of 0 ~ (CPL_Getcount Returns - 1). LPARAM2: Pointer to the TCPLINFO structure. Return Value: Returns to zero successfully, failing to return non-zero. CPL_INQUIRE is the most important message in programming, and the control panel uses this message to obtain a certain name, description, and icon for each component.

The parameter is incorporated into the component number, and we must fill the corresponding component information in the TCPLINFO structure pointed to by the component number. The TCPLINFO structure is defined as follows: TCPLINFO = PCCKED RecordIDIDICON: Integer; // Point to component icon IDName: integer; // Point to component name IDINFO: Integer; // Pointer to component description CPL_DBLCLKCPL_STOPLDATA: longint; // User Custom Parameter End; IDCION, IDNAME The three fields of IDINFO are stored component icons, names, description, we want to call the LoadString and Loadicon API function, get the actual string and icon from the CPL file. The type of LDATA field is longint, the length of 4 bytes of unsigned integers, but can also be changed to the pointer variable, and the value in the LDATA will return the CPL_DBLCLK, the CPL_STOP message is returned by the LPARAM2 parameter when the control panel program is transmitted next time. Components use, you can freely determine its function. 4, CPL_Newinquire: LPARAM1: Component Number, value of 0 ~ (CPL_GETCOUNT Return Number - 1). LPARAM2: Pointer to the TNewCPLINFO structure. Return Value: Returns to zero successfully, failing to return non-zero. The TNewCPLINFO structure is slightly complicated than the TCPLinfo structure, defined as follows: tnewcplinfo = pccked recordwsize: dWord; // Structure occupied length dwflags: dword; // Currently unused DWHELPCONTEXT: DWORD; // Description page number, currently not using LData: longint; / User Custom Parameters HICON: HICON; // Component Illustrated Szname: Array [0..31] of char; // Component name SZINFO: array [0..63] of char;

Szhelpfile: Array [0..127] of char; // Description file name, currently not using end; SZNAME, SZINFO, HICON, LDATA these four fields in the previous CPLinfo structure are identical, only However, SZNAME, SZINFO, the HICON field becomes a string and HICN type. This allows the CPL program to generate and return the name, description, and icon of the component depending on the situation. 5, CPL_DBLCLK: LPARAM1: Component Number, value of 0 ~ (CPL_GETCOUNT Return Number - 1). LPARAM2: Points the LDATA field value returned to the TCPLINFO or TNEWCPLINFO structure. Return Value: Returns to zero successfully, failing to return non-zero. When we double-click the component icon in the control panel, the CPL_DBLCLK message is triggered. This is our use to open the control panel, open the corresponding dialog, and then set it. 6, CPL_STOP: LPARAM1: Component Number, Value is 0 ~ (CPL_Getcount Returns Number - 1). LPARAM2: Points the LDATA field value returned to the TCPLINFO or TNEWCPLINFO structure. Return Value: Returns to zero successfully, failing to return non-zero. This message provides a chance to make individual components work, such as releasing GDI or core objects, and more. Returns zero if everything is correct. 7, CPL_EXIT: LPARAM1, LPARAM2: Nothing. Return Value: Returns to zero successfully; failure returns a non-zero value. Just quit. Ok, about the research on the control panel, I will tell a paragraph, if you want to perform in-depth programming, you can go to an instance to practice exercises. Third, the production of my control panel must have used Windows Optimization Master, there is a control panel in it, you can display the control panel in our computer, we have passed the previous learning, can you also compile a similar What about the program? The answer is yes. Let's take a look! After we observe, decided to use the TListView control. For the beautiful, the TListView control is set as follows: CHECKBOXES is set to true; color, set to false; FlatscrollBar is set to true; SortType is set to vSreport; click Column, plus three values: project name, project instructions, Project role. Add declarations in Usetes: CPL. Programming code: Procedure TForm1.FormCreate (Sender: Tobject); Procedure NewView (Anode: TListItem); Varhlib: THANDE; CPLPROC: TCPLAPPLET; / / Pointer ICOUNT, I: Integer; // to acquire control panel Structure CPLINFO: TCPLINFO;

// Record the name, description and icon Sname, SINFO: array [0..255] of char; happicon: hic; beginhlib: = loadingLibrary (pchar (anode.caption); if hlib = 0 Thenbeginanode.Subitems.Add ('- Unable to load !!'); exit; end; trycplproc: = tcplapplet (getProcaddress (Hlib, 'cpLapplet')); if @cplproc = nil dam; if cplproc (Handle, CPL_INIT, 0, 0 = 0 THEN EXIT; ICOUNT: = CPLProc (Handle, CPL_Getcount, 0, 0); for i: = 0 to ICount - 1 DobeGinfillchar (CPLINFO, SIZEOF (TCPLINFO), 0); CPLProc (Handle, CPL_INQUIRE, I, LONGINT (@CPLINFO)); LoadString (Hlib, Cplinfo.idName, @sname, 255); LoadString (Hlib, Cplinfo.idInfo, @sinfo, 255); happicon: = loading (Hlib, makeintresource (cplinfo.idicon); anode . Subitems.add (sname); Anode.Subitems.Add (Sinfo); end; cplProc (Handle, CPL_EXIT, 0, 0); FinallyFreelibrary (HLIB); end; end; varssysdir: array [0..255] of char , SearchRec: tsearchrec; J: Integer; NewItem: TlistItSystemDirectory (ssysdir, 255); // acquired system directory J: = FINDFIRST (SSYSDIR '/ *. CPL', FAANYFILE, SearchRec); // Start looking for system directory CPL file while j = 0 dobegin

NewItem: = listview1.items.add; newItem.caption: = ansilowercase (searchRec.name); newView (newItem); // call custom function newViewj: = findnext (searchRec); // Looking for the next CPL file END; FINDCLOSE (SearchRec); END; if you want to double-click on the control panel that runs run, the code is as follows: procedure tform1.listview1dblclick (sender: TOBJECT); VARHLIB: THANDLE; CPLPROC: TCPLAPPLET; newItem: TListInfo;

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

New Post(0)