QA: How can I get information about Control Panel applets like dialog names, icons, etc?
Vassili Philippov (vasja@spbteam.com), August 26, 2001.
Question
How can I enumerate existing Control Panel applets, get corresponding applet icons and names?
Answer
There are special dynamic linked libraries (files with .cpl extension) that are responsible for Control
Panel applets. Each such library has a CPlApplet function that works line WindowProc
function in Windows applications. It handles the following messages:
- CPL_DBLCLK
- CPL_EXIT
- CPL_GETCOUNT
- CPL_INIT
- CPL_NEWINQUIRE
- CPL_STOP
Standard Pocket PC Control Panel applets are handled by cplmain.cpl library.
There could be additional Control Panel applets handled by other .cpl libraries.
To get information about existing applets:
- load necessary .cpl library using LoadLibrary function
- get address of CPlApplet function using GetProcAddress function.
Signature of CPlApplet function is described in the example below.
- send CPL_INIT message (call CPlApplet function with CPL_INIT parameter)
- send CPL_GETCOUNT message to get number of applets
- for each applet send CPL_NEWINQUIRE message to get structure that contain applet name, icon, etc
- send CPL_EXIT message
Sample application
You can download sample control panel (22 Kb) application that works like standard
Control Panel (Settings).
Source code
Here is a sample code that reads information about Control Panel applets
handled by cplmain.cpl library and adds icons to CListCtrl control.
In header file there is a definition of a list control member:
CListCtrl m_ctrlApplets;
In .cpp file:
//Define signature of CPlApplet function
typedef LONG CPlAppletProc(HWND hwndCpl, UINT msg, LONG lParam1, LONG lParam2);
PlAppletProc *pAppletProc
//Initialize library
HMODULE hModule = ::LoadLibrary(_T("cplmain.cpl"));
//Find main function
FARPROC pProc = GetProcAddress(hModule, _T("CPlApplet"));
pAppletProc = (CPlAppletProc*)pProc;
//Initialize library
LONG nInitResult = pAppletProc(m_hWnd, CPL_INIT, 0, 0);
if (nInitResult==0) {
::AfxMessageBox(_T("Initialization of library ")+
strLibraryFileName+_T(" failed."));
return;
}
//Reads number of applets in the library
LONG nCount = pAppletProc(m_hWnd, CPL_GETCOUNT, 0, 0);
//Initialize image list of the list control
CImageList *pImageList = m_ctrlApplets.GetImageList(LVSIL_NORMAL);
if (pImageList==NULL) {
pImageList = new CImageList();
pImageList->Create(32, 32, ILC_COLOR, 10, 10);
m_ctrlApplets.SetImageList(pImageList, LVSIL_NORMAL);
}
for (int i=0; iAdd(info.hIcon);
m_ctrlApplets.InsertItem(i, info.szName, nIconId);
}
Related resources:
-
http://www.pocketpcdn.com/sections/controlpanel.html
Section: Control Panel
-
http://www.pocketpcdn.com/articles/controlpanel.html
Article: Using Control Panel
-
http://www.pocketpcdn.com/articles/controlpanelapplet.html
Article: Creating Control Panel Applet
-
http://www.pocketpcdn.com/libraries/stcontrolpanel.html
Library: STControlPanel