|RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Books|Link Back|
|Locate, Display and Execute Control Panel Applets|
|Page 2: Inside Control Panel Applets: Extracting a Name, Description and the Icon|
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.
Once we have found all Control Panel applications inside the Windows System folder, we can "look" inside, and extract any information we need.
But, first some info on how CPL files are "structured".
CPL: special-purpose DLLAs stated, CPL files are special-purpose dynamic link libraries. To be able to get information from a Control Panel application, we need to load the CPL file using the LoadLibrary API call.
Every Control Panel application exports the standard entry-point function, named CPlApplet. This function receives requests, in the form of messages (like "CPL_SOMETHING"), and carries out the requested work, such as initializing the application, returning a number of dialog boxes it supports, providing information about a specified dialog box, and closing the application.
Therefore, after we have dynamically loaded the CPL, in order to look inside the CPL application we need to "find" the CPlApplet function. This is done by calling the GetProcAddress API call.
Once we lay our hands on the CPlApplet function, we use it to grab the information about the Contol Panel Application we want. First, we send it the CPL_GetCount message to get the number of dialog boxes (Applets) it carries. Remember that each .CPL file is an application that can hold more than one Applet. Second, for each Applet, we send the CPL_INQUIRE message that fills the CPLInfo structure. This structure contains resource information (such as the name of the applet, description and icon) and an application-defined value for a dialog box supported by a Control Panel application. Finally, we use LoadIcon and LoadString API calls to get the information we are interested in.
When we have finished with the Control Panel application (the CPL file), we unload it using the FreeLibrary function.
Uh, the "story" above looks quite messy ;) Don't runaway, Delphi code looks much more friendly.
Control Panel Folder - Delphi WayAt the end of the article you'll have the option to download the full project source.
For now, I suggest you to start Delphi, and on that empty new form drop two TButton components, one TListView and one TImageList.
The TListView should be named 'lvCPL', you should add 3 columns (Name, Comment, FileName) to it. Name the TImageList 'cplIcons' - we'll use for SmallImages property of the ImageList. The cplIcons will be run-time filled with icons extracted from the CPLInfo structure (as explained above). The two buttons are used to locate the CPL files and execute the selected one. More about executing, later in this article...
The ProcessCPLApplet function
Note: the TCPLApplet and the TCPLInfo types are defined in the Delphi CPL.pas unit, which you will have to include in the uses clause. The LoadStringFromModule is a function defined in the project used to extract the string value (stored as a resource) inside the CPLInfo structure.
All set, we have a Delphi clone of the Windows Control Panel folder, now we proceed to executing a particular applet!
All graphics (if any) in this feature created by Zarko Gajic.
|· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time.
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2003|2002|2001|2000|1999|1998 or by TOPIC.
|Stay informed with all new and interesting things about Delphi (for free).|
|Got some code to share? Got a question? Need some help?|