Главная страница | назад





Article #17449: Control Panel App from Builder

 Question and Answer Database
FAQ2449C.txt Control Panel App from Builder
Category :VCL
Platform :All
Product :C++Builder 3.x
Question:
How exactly does one produce Control Panel Application using Borland C++
Builder Standard???
Answer:
A control panel extension is nothing more than a normal DLL, which offers a
'CPlApplet' function. The Control Panel will call this function to tell your
extension what to do.
So, create a new DLL app (File/New../DLL). Add a form to it. save the project as
CPLExtension, and the form as CPLExtensionForm. Compile it.
Then use the following code in the DLL source file:
#include 
#include  // Control Panel applet definitions
#pragma hdrstop
USERES("CPLExtension.res");
USEFORM("CPLExtensionForm.cpp", Form1); // This is the form
HINSTANCE OurInstance;
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
// Remember our instance, so we can get to our DLL resources
if (reason==DLL_PROCESS_ATTACH) OurInstance=hinst;
return 1;
}
// The Control Panel will do all calling through this function
extern "C" int __stdcall __declspec(dllexport)
CPlApplet(HWND HwControlPanel,int Msg,int lParam1,int lParam2)
{
switch (Msg) {
case CPL_INIT:
// Return "succesful initialization"
return true;
case CPL_GETCOUNT:
// This DLL contains 1 applet
return 1;
case CPL_NEWINQUIRE: {
// Control Panel asks for display information
NEWCPLINFO *Info=(NEWCPLINFO *)lParam2;
ZeroMemory(Info,sizeof(NEWCPLINFO));
Info->dwSize=sizeof(NEWCPLINFO);
// Icon is specified under Options/Project/Applications, as usual
Info->hIcon=LoadIcon(HInstance,"MAINICON");
strcpy(Info->szName,"Exception's Example Applet");
strcpy(Info->szInfo,"Exception's Example Control Panel"
" Applet — exception@mailcity.com");
return 0;
}
case CPL_DBLCLK:
// Time to show our form!!!
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
}
Compile it to a DLL, rename it to the CPL extension, and place it in your windows
system directory, and start Control Panel (Settings...). If you double click it,
you'll see your form.
You can use all your VCL thingys on the extension's form (buttons, edit components,
images, etc).
Notes for CBuilder3:
You will need to use ImageEditor (or your favorite resource bulilder) to create a
resource file with an icon called MAINICON, and use the project manager to add the resource to the project.
You can use the Project | Options | Application dialog for setting the extension
to 'cpl'.
7/2/98 10:32:32 AM

Last Modified: 01-SEP-99