Click here to Skip to main content
15,881,641 members
Articles / Programming Languages / C++
Article

ControlPanel

Rate me:
Please Sign up or sign in to vote.
4.00/5 (4 votes)
16 Nov 2002 70.7K   1.5K   20   6
The ControlPanel is a small application showing you how the Windows Control Panel application works

Introduction

The ControlPanel is a small application showing you how the Windows Control Panel application works.

The normal procedure is that when the application is launched it looks for .cpl files in the windows system directory. The cpl files are simple dll's which exports the CPlApplet() function. Control Panel now loads each cpl file one by one and gets the address of its CPlApplet() function. For each file it calls the CPlApplet() function by passing it different messages such as CPL_INIT, CPL_INQUIRE etc. You can get help about different messages in the MSDN. When control panel calls CPlApplet() function with CPL_INQUIRE message, the cpl file returns a CPLINFO structure which holds information about that perticular applet such as its name, icon, info tip etc. When a control panel applet is double clicked control panel calls CPlApplet() function with CPL_DBLCLK message to let the applet perform its work.

History

17 Nov 2002: Changed code. Now one can simply use the

class CControlItems
{
public:
	CControlItems();
	~CControlItems();

	void ReadFiles ( HWND hWnd );
	
	virtual void ProgressText ( char* pText );
	virtual void AddCplDialog( char* pName, int i, int k );

	// Return TRUE if one found,
	BOOL CheckIndex ( int iCpl, int iDialog );
	BOOL FindIndexByName ( const char* pName, int iCpl, int iDialog );

	HICON GetIconByIndex ( int iCpl, int iDialog );

	const char* GetToolTipByIndex ( int iCpl, int iDialog );
	const char* GetToolTipByName ( char* pName );

	BOOL StartByIndex ( HWND hWnd, int iCpl, int iDialog );
	BOOL StartByName ( HWND hWnd, char* pName );

	CCtrlPnlInfo* cpl_info;
};

By adding this class to a simple dialog which has a CListBox called m_list and a button which calls the ReadFiles

void CCPService::OnButtonReload() 
{
	m_list.ResetContent();

	ReadFiles( GetSafeHwnd() );

	m_list.UpdateWindow();
}

void CCPService::ProgressText ( char* pText )
{
	CWnd* pButton = GetDlgItem ( IDC_BUTTON_RELOAD );
	if ( pButton )
	{
		pButton->SetWindowText ( pText );
	}
}

void CCPService::AddCplDialog( char* pName, int i, int k )
{
	// Simple way to remember the index in an integer
	int iData = i << 16 | k;

	int iNewItem = m_list.AddString((LPCTSTR) pName);
	m_list.SetItemData( iNewItem,iData);

	m_list.UpdateWindow();
}

void CCPService::OnSelchangeList1() 
{
	int index = m_list.GetCurSel();
	if(index > -1)
	{
		int iData = m_list.GetItemData( index );

		// Split integer to the index values
		int i = iData >> 16;
		int k = iData & 0xffff;

		HICON hI = GetIconByIndex	( i, k );
		const char* pT = GetToolTipByIndex( i, k );

		if ( pT )
		{
			CWnd* pW = GetDlgItem ( IDC_TOOLTIP );
			if ( pW )
			{
				pW->SetWindowText ( pT );
			}
		}

		if ( hI )
		{
			m_icon.SetIcon ( hI );
		}	
	}
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralNice sample Pin
Armen Hakobyan29-Jul-02 11:57
professionalArmen Hakobyan29-Jul-02 11:57 
GeneralOther places Pin
Thomas Freudenberg7-Nov-01 22:49
Thomas Freudenberg7-Nov-01 22:49 
GeneralRe: Other places Pin
56789012348-Nov-01 3:35
56789012348-Nov-01 3:35 
GeneralRe: Other places Pin
Farooque8-Nov-01 17:22
Farooque8-Nov-01 17:22 
cool,

i didn't know about this. Thanks.

I'll make sure the next version incorporates this too.

Regards

Farooque
GeneralOther way to run Control Panel applet from the program Pin
7-Nov-01 22:26
suss7-Nov-01 22:26 
GeneralRe: Other way to run Control Panel applet from the program Pin
Farooque8-Nov-01 17:18
Farooque8-Nov-01 17:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.