Click here to Skip to main content
12,401,995 members (28,391 online)
Click here to Skip to main content
Add your own
alternative version

Stats

65.5K views
1.4K downloads
20 bookmarked
Posted

ControlPanel

, 16 Nov 2002
Rate this:
Please Sign up or sign in to vote.
The ControlPanel is a small application showing you how the Windows Control Panel application works
<!-- Download Links -->

<!-- Main HTML starts here -->

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

Share

About the Author

Farooque Khan
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralNice sample Pin
Armen Hakobyan29-Jul-02 11:57
memberArmen Hakobyan29-Jul-02 11:57 
GeneralOther places Pin
Thomas Freudenberg7-Nov-01 22:49
memberThomas Freudenberg7-Nov-01 22:49 
GeneralRe: Other places Pin
Alex Farber8-Nov-01 3:35
memberAlex Farber8-Nov-01 3:35 
GeneralRe: Other places Pin
Farooque8-Nov-01 17:22
memberFarooque8-Nov-01 17:22 
GeneralOther way to run Control Panel applet from the program Pin
Alex Farber7-Nov-01 22:26
memberAlex Farber7-Nov-01 22:26 
GeneralRe: Other way to run Control Panel applet from the program Pin
Farooque8-Nov-01 17:18
memberFarooque8-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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160721.1 | Last Updated 17 Nov 2002
Article Copyright 2001 by Farooque Khan
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid