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:

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:

  1. load necessary .cpl library using LoadLibrary function
  2. get address of CPlApplet function using GetProcAddress function. Signature of CPlApplet function is described in the example below.
  3. send CPL_INIT message (call CPlApplet function with CPL_INIT parameter)
  4. send CPL_GETCOUNT message to get number of applets
  5. for each applet send CPL_NEWINQUIRE message to get structure that contain applet name, icon, etc
  6. 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; i<nCount; i++) { //Read information about the next applet... NEWCPLINFO info; pAppletProc(m_hWnd, CPL_NEWINQUIRE, i, (DWORD)&info); //... and add new iten in the list int nIconId = pImageList->Add(info.hIcon); m_ctrlApplets.InsertItem(i, info.szName, nIconId); }

Related resources: