⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 samplecontrolpaneldlg.cpp

📁 windows ce开发技巧与实例光盘代码
💻 CPP
字号:
// SampleControlPanelDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SampleControlPanel.h"
#include "SampleControlPanelDlg.h"
#include <cpl.h>
#include <Afxcmn.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSampleControlPanelDlg dialog

CSampleControlPanelDlg::CSampleControlPanelDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSampleControlPanelDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSampleControlPanelDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSampleControlPanelDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSampleControlPanelDlg)
	DDX_Control(pDX, IDC_APPLETS, m_ctrlApplets);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSampleControlPanelDlg, CDialog)
	//{{AFX_MSG_MAP(CSampleControlPanelDlg)
	ON_NOTIFY(NM_CLICK, IDC_APPLETS, OnClickApplets)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSampleControlPanelDlg message handlers

BOOL CSampleControlPanelDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	CRect rt;
	GetClientRect(rt);
	m_ctrlApplets.MoveWindow(rt);

	//Load control panel applets from cplmain.cpl library
	AddAppletsOfLibrary(_T("cplmain.cpl"));
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSampleControlPanelDlg::AddAppletsOfLibrary(const CString &strLibraryFileName)
{
	//Initialize library
	HMODULE hModule = ::LoadLibrary(strLibraryFileName);
	
	//Find main function
	FARPROC pProc = GetProcAddress(hModule, _T("CPlApplet"));
	m_pAppletProc = (CPlAppletProc*)pProc;

	//Initialize library
	LONG nInitResult = m_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 = m_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;
		m_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);
	}
}

void CSampleControlPanelDlg::OnClickApplets(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int iAppletIndex = m_ctrlApplets.GetNextItem(-1, LVNI_SELECTED);
	m_pAppletProc(m_hWnd, CPL_DBLCLK, iAppletIndex , (DWORD)NULL);	

	*pResult = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -