An example of writing a control Panel program

Source: Internet
Author: User

This article supporting source code

Recently, in the process of writing a MPEG player in Windows 98 and Windows 2000 systems, I want to create a control Panel program that allows users to change the basic configuration of the player. As you know, control Panel programs are generally a DLL dynamic library, and then change the name to *.cpl. After looking at a lot of data, I found that some of the examples you see are written in C. Can I use C + + to write one in MFC? The answer is yes. This article will demonstrate how to write an MFC control Panel program with an actual VC + + example.

The first thing to be clear is that although the Control Panel program is a DLL, it differs from a generic DLL because it comes with a special output interface, which is the Cplapplet function, and the following is its prototype:

LRESULT CPlApplet(HWND hwnd,
         UINT msg,
         LPARAM lp1,
         LPARAM lp2);  

In order to make the example code of this article as reusable as possible, I encapsulate the interface function of the control Panel with C + +. Made a mini Control Panel application Development framework, using it to develop Control Panel Extender is a breeze. In addition to being a special DLL, the Control Panel program has the feature that its extension must be *.cpl, not *.dll. When Windows controls the Control Panel management program. EXE), it looks for a file named Xxx.cpl in the system directory (such as: Windows\System or Winnt\System32), and then loads each DLL and calls the Cplapplet function with a different message parameter. For example, when the control Panel first starts, it calls the Cplapplet function with message msg=cpl_init, and when the user double-clicks the application icon in Control Panel, it uses the message MSG=CPL_DBLCLK to invoke the Cplapplet function. The Control Panel application then displays the corresponding dialog box, with each control Panel DLL supporting more than one icon or application. By responding to message cpl_getcount, you can let the control panel know how many applications are in the DLL, and the control Panel can request information about each application by sending Cpl_inquire or cpl_newinquire messages. Figure one is the trace Dump shown with a tracer (Tracewin), which shows how the control Panel handles the message.

Figure one using the TRACE Dump shown in Tracewin

Because most of the interaction between the control Panel and the DLL has a fixed routine, it can be encapsulated in a frame. This article provides two classes, Ccontrolpanelapp and Ccpapplet, to achieve the above encapsulation. To illustrate how these two classes are used, this article has also written the demonstration Control Panel program application DLL:MyCtrlPanel.dll, it has implemented two Control Panel application, figure Two is this article example program to run in the control Panel to create two icons, these two icons one is the dialog box form (like Figure three), One is the form of the property page (Figure IV).

Figure Two Example program icon

Figure Three

Figure Four

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.