1. Technology
Locate, Display and Execute Control Panel Applets
Page 1: What are Control Panel Applications and how to locate them in the system.
 Win prizes by sharing code!
Do you have some Delphi code you want to share? Are you interested in winning a prize for your work?
Delphi Programming Quickies Contest
 More of this Feature
• Page 2: "Inside" CPL
• Page 3: Executing Applets
• Page 4: Full Project CODE
 Join the Discussion
"Post your views, comments, questions and doubts to this article."
Discuss!
 Related Resources
• Finding files with Delphi
• Using Windows API
• Message Handling

Interested in Delphi code to mimic the Windows Control Panel folder behavior? In this article you can learn how to find CPL files, how to extract description, name and even the applet icon. Even more, learn how to execute applets from your applications.

   CPL: the theory
I bet you use them every now and then (if not every day). Control Panel applications are special-purpose dynamic link libraries (with a .CPL extension) that provide a way to configure the Windows environment. Windows provides a number of standard Control Panel applications to let users examine and modify the settings and operational modes of specific hardware and software. In general, Applets represent options for configuring your computer.
Control Panel application can provide any number of dialog boxes to control any number of system components - these individual dialog boxes are called applets.

Display Properties CPLThe main goal of any Control Panel application is to display a dialog box and to carry out any tasks specified by the user.

Here's how to show the standard "Display Properties" dialog (Control Panel Application), the one that let's you change the Windows Screen Saver, or change the wallpaper on your Desktop...
First make sure all windows are minimized and you have "access" to Windows desktop. Second, right-click anywhere on the Desktop, and from the pop-up menu select "Properties" ... and here it is ... you've executed one Control Panel Application.
To find all other Control Panel Applications, go to Windows Start menu, select Settings - Control Panel. Note: the folder that opens, and the functionality it provides ... this is what we are interested in!

Control Panel Applets are usually controlled by a Windows system utility specifically designed to give users access to these applications. However, any application can load and manage Control Panel applications.
This is exactly what we are up to in this article...

   Looking for .CPL files
As said, a Control Panel Application is really a special type of DLL with a .CPL extension. By default (read: after Windows installation), standard Windows Control Panel applications are saved in the Windows system directory. The system directory also contains such files as Windows libraries, drivers, and font files. Given the Windows version, this system directory can be "Windows\System" (Windows 98, for example) or "WinNT\System32" (Windows 2000, for example). To be able to "track" the system directory on any Windows operating system, a special API function "GetSystemDirectory" can be used.

After we have found the system folder, we need to do a search for all the .CPL files in it. Fortunately, Delphi has functions specially designed to enable file searching on the system. Those functions are FindFirst, FindNext and FindClose. In general, an application can search the current directory for all filenames that match a given pattern. If you unfamiliar with Delphi file search operations, please examine the "Searching for Files" article.

Searching for .CPL inside System folder...
First, let's locate all the CPL files inside the Windows System folder, and "put" them (i.e their file names) in a TStrings object. This is the code:

procedure TMainForm.GetCPLList(FileList : TStrings);
var
  CPLFileMask : String;
  SearchRec : TSearchRec;
  SystemPath: array[0..MAX_PATH + 1] of char;
begin
  GetSystemDirectory(SystemPath, MAX_PATH);
  CPLFileMask := IncludeTrailingPathDelimiter(SystemPath) + '*.CPL';

  //locate *.CPL files inside "System" folder
  if FindFirst(CPLFileMask, 
            faAnyFile - faDirectory, SearchRec) = 0 then
  begin
    repeat
      FileList.Add(SearchRec.Name);
    until FindNext(SearchRec) <> 0;
    FindClose(SearchRec);
  end;
end;

Note: the code first gets the System folder than initiates the search for all the .CPL files inside. Files found are saved in a TStrings object.

Now that we have located Control Panel applications, we can advance to processing (in a loop) for every single application (the .cpl file). This processing will involve getting a name of each applet, its description and the icon that represents the applet.

Next page > Processing Control Panel Applications > Page 1, 2, 3, 4

©2014 About.com. All rights reserved.