Control Panel Applet using MFC | CodeGuru

Control Panel Applet using MFC

Environment: Wnidows NT4 SP5, Visual C++ 6 SP2 Ever wanted to make a Control Panel Applet using MFC but couldent get it to work? Simlpy folow these steps: 1. Make a MFC DLL using the project wizard. 2. In the CWinApp header file define the folowing members: ////////////////////////////////////////////////////// // PanelApp.h class CPanelApp : public CWinApp […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 3, 2000
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: Wnidows NT4 SP5, Visual C++ 6 SP2

Ever wanted to make a Control Panel Applet using MFC but couldent get it to
work?
Simlpy folow these steps:

1. Make a MFC DLL using the project wizard.

2. In the CWinApp header file define the folowing members:

//////////////////////////////////////////////////////
// PanelApp.h

class CPanelApp : public CWinApp
{
public:
 CPanelApp();

 // Static data
 static CPanelApp* m_pThis;

 // Static member functions (callbacks)
 static LONG APIENTRY CPlApplet(HWND hWnd,
  UINT uMsg, LONG lParam1, LONG lParam2);

 LONG OnDblclk(HWND hWnd, UINT uAppNum, LONG lData);
 LONG OnExit();
 LONG OnGetCount();
 LONG OnInit();
 LONG OnInquire(UINT uAppNum, CPLINFO* pInfo);
 LONG OnNewInquire(UINT uAppNum, NEWCPLINFO* pInfo);
 LONG OnStop(UINT uAppNum, LONG lData);
};

2. In the CWinApp source file add the folowing code:

//////////////////////////////////////////////////////
// PanelApp.cpp


// Static data initialization
CPanelApp* CPanelApp::m_pThis = NULL;

// CPanelApp construction
CPanelApp::CPanelApp()
{
	m_pThis = this;
}

// Callback members
LONG APIENTRY CPanelApp::CPlApplet(HWND hWnd, UINT uMsg,
 LONG lParam1, LONG lParam2)
{
 // Avoids state problems in MFC extensions using 
 // shared MFC libs.
 AFX_MANAGE_STATE(AfxGetStaticModuleState());

 CPanelApp* pApplet = m_pThis;
 ASSERT(pApplet);

 switch (uMsg)
 {
  case CPL_DBLCLK:
  return pApplet->OnDblclk(hWnd, lParam1, lParam2);

  case CPL_EXIT:
  return pApplet->OnExit();

  case CPL_GETCOUNT:
  return pApplet->OnGetCount();

  case CPL_INIT:
  return pApplet->OnInit();

  case CPL_INQUIRE:
  return pApplet->OnInquire(lParam1, (CPLINFO*)lParam2);

  case CPL_NEWINQUIRE:
  return pApplet->OnNewInquire(lParam1,
   (NEWCPLINFO*)lParam2);

  case CPL_STOP:
  return pApplet->OnStop(lParam1, lParam2);

  case CPL_STARTWPARMS:
  return pApplet->OnDblclk(hWnd, lParam1, lParam2);

  default:
  break;
 }

 return 1;
}

// Default command handlers

LONG CPanelApp::OnNewInquire(UINT uAppNum,
 NEWCPLINFO* pInfo)
{
 // Fill in the data
 pInfo->dwSize		  = sizeof(NEWCPLINFO);
 pInfo->dwFlags		  = 0;
 pInfo->dwHelpContext = 0;
 pInfo->lData		  = 0;
 pInfo->hIcon		  = LoadIcon(IDI_MAINFRM);

 CString sCplName, sCplInfo;
 sCplName.LoadString(IDS_CPL_NAME);
 sCplInfo.LoadString(IDS_CPL_INFOSTRING);

 _tcscpy(pInfo->szName, sCplName);
 _tcscpy(pInfo->szInfo, sCplInfo);
 _tcscpy(pInfo->szHelpFile, _T(""));

 return 0;
}

LONG CPanelApp::OnInquire(UINT uAppNum, CPLINFO* pInfo)
{
 pInfo->idIcon	= IDI_MAINFRM;
 pInfo->idName	= IDS_CPL_NAME;
 pInfo->idInfo	= IDS_CPL_INFOSTRING;
 pInfo->lData	= 0;

 return 0;
}

LONG CPanelApp::OnDblclk(HWND hWnd, UINT uAppNum,
 LONG lData)
{
 // Insert your Control Panel Applet dialog (property 
 // sheet) code here

 return 0;
}

LONG CPanelApp::OnExit()
{
 return 0; // OK
}

LONG CPanelApp::OnGetCount()
{
 return 1; // only one applet
}

LONG CPanelApp::OnInit()
{
 return 1; // OK
}

LONG CPanelApp::OnStop(UINT uAppNum, LONG lData)
{
 return 1; // not handled
}

3. Finaly add the folowing to the projects *.def file

; Panel.def : Declares the module parameters for the DLL.

LIBRARY      "Panel"
DESCRIPTION  'Panel Windows Dynamic Link Library'

EXPORTS
    ; Explicit exports can go here

	CPlApplet

Thats all there is too it!

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.