How to develop control panel program (CPL Program)

Source: Internet
Author: User
How to develop control panel program (CPL Program)
Cpl program is a kind of deformation of the dynamic link library (DLL), but the extension is. CPL, And the entry function is cplapplet () instead of dllmain (). It is actually very simple to compile.
Create a DLL project and write the following code:

# Include <windows. h>
# Include <Cpl. h>
# Include <cplext. h>
Extern "C" _ declspec (dllexport) long _ stdcall cplapplet (hwnd hwndcpl, uint umsg, lparam lparam1, lparam lparam2 );

Long _ declspec (dllexport) _ stdcall cplapplet (hwnd hwndcpl, uint umsg, lparam lparam1, lparam lparam2)
{
Lpnewcplinfo CPL; // you can view the lpnewcplinfo structure in the CPL. h header file.
Long result = 0;
Switch (umsg) // judge the incoming information
{
Case cpl_init: // The first information generated when calling the control panel
Result = 1;
Break;
Case cpl_getcount: // the second message, which is generated when the control panel is transferred in.
Result = 1;
Break;
Case cpl_inquire: // The third information, which is generated when the control panel queries
Result = 0;
Break;
Case cpl_newinquire: // The third information, which is generated when the control panel queries
Cpl = lpnewcplinfo (lparam2); // pass the pointer in lparam2 to mycpl
Cpl-> dwsize = sizeof (newcplinfo );
Cpl-> dwflags = 0; // The flag variable is generally set to 0.
Cpl-> dwhelpcontext = 0; // The help handle is generally set to 0
Cpl-> ldata = 0;
Cpl-> hicon = (hicon) loadicon (null, idi_winlogo );
Cpl-> szhelpfile [0] = '/0'; // Help File
Strcpy (CPL-> szname, "Control Panel Demo"); // the description text displayed under the icon
Strcpy (CPL-> szinfo, "Develop your own control panel program"); // The description displayed in the control panel Status Bar
Result = 0;
Break;
Case cpl_dblclk: // when the icon is double-clicked
MessageBox (hwndcpl, "This is a CPL test program", "hello", mb_ OK );
Result = 0;
Break;
Case cpl_stop: // generated when the user closes his/her own program
Result = 1;
Break;
Case cpl_exit: // when the control panel is closed, the system uses freelibrary () to release
Result = 0;
Break;
Default:
Break;
}
Return result;
}

Compile it into a DLL file.

Program description:

The running process of the CPL program is based on a series of messages sent to the program.

When the user opens the control panel, the system will traverse all CPL programs under the system directory and send them CPL-INT messages. In this case, the CPL program can perform initialization and then return a non-zero value. If it returns zero, the program will be terminated. If the CPL-INT message processing is complete, the CPL program receives the CPL-GETCOUNT message, at which point the program must return the number of dialogs, typically 1. Then, the program will receive a CPL-NEWINQUIRE message, at this time the system requires the CPL program to provide information, label, description text, help files, etc., the program must fill the lparam2 pointer to the information structure, then return 0. At this point, the control panel is initialized and various icons are displayed. If you double-click an icon, the CPL program represented by this icon receives a CPL-DBCLICK message. At this time, the CPL program can display the dialog interface for relevant operations. When the user completes the operation and closes the program, 0 must be returned. When the user closes the control panel, the CPL program will receive the CPL-STOP message, then it will release the memory resources, do the aftermath, and then return 1. Finally, the CPL program will receive the last message CPL-EXIT, the system will delete each window, and use the freelibrary () function to delete the CPL program from the system, complete the process. In general, we only need to process the CPL-NEWINQUIRE and CPL-DBCLICK messages, other messages as long as the default value is returned.

You only need to compile this CPl project and copy the results to the Windows/system (system32) directory. Then open the control panel and you will see the results. Double-click the icon, and the program will pop up a message box: "This is a CPL test program! ". This CPL program is complete. You can also click "open with control panel" to run the program. You can also run the program. Winexec ("C:/Windows/system32/control.exe mycpl. Cpl", sw_normal );

If you use BCB for development, you must add the DLL entry function. That is, the following code.

Int winapi dllentrypoint (hinstance hinst, unsigned long reason, void *)
{
Return 1;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.