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

📄 imagelistdlg.cpp

📁 这些源代码
💻 CPP
字号:
// ImageListDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Controls.h"
#include "ImageListDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CImageListDlg property page

IMPLEMENT_DYNCREATE(CImageListDlg, CPropertyPage)

CImageListDlg::CImageListDlg() : CPropertyPage(CImageListDlg::IDD)
{
	//{{AFX_DATA_INIT(CImageListDlg)
	m_nImageList = 0;
	//}}AFX_DATA_INIT
	m_psp.dwFlags &= ~PSP_HASHELP;
}

CImageListDlg::~CImageListDlg()
{
}

void CImageListDlg::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CImageListDlg)
	DDX_Control(pDX, IDC_LISTBOX_IMAGES, m_ImageListBox);
	DDX_Control(pDX, IDC_COMBO_IMAGES, m_ImageComboBox);
	DDX_Radio(pDX, IDC_RADIO_SMALLIMAGELIST, m_nImageList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CImageListDlg, CPropertyPage)
	//{{AFX_MSG_MAP(CImageListDlg)
	ON_BN_CLICKED(IDC_RADIO_LARGEIMAGELIST, OnRadioLargeimagelist)
	ON_BN_CLICKED(IDC_RADIO_SMALLIMAGELIST, OnRadioSmallimagelist)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CImageListDlg message handlers

void CImageListDlg::OnRadioLargeimagelist() 
{
	m_ImageListBox.SetImageList (&m_LargeImages);
	RecreateListBox ();
}

void CImageListDlg::OnRadioSmallimagelist() 
{
	m_ImageListBox.SetImageList (&m_SmallImages);
	RecreateListBox ();
}

BOOL CImageListDlg::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();

	const TCHAR *szItems[] = 
		{
		"Folder",
		"Open Folder",
		"3.5-Inch Floppy",
		"Hard Drive",
		"Network Drive",
		"CD-ROM",
		"Audio CD",
		"Desktop",
		"My Computer",
		"Puters in the Hood",
		"Dudley"
		};

	m_SmallImages.Create (IDB_SMALLDRIVES, 20, 10, RGB (0x00, 0x80, 0x80)); 
	m_LargeImages.Create (IDB_LARGEDRIVES, 32, 10, RGB (0x00, 0x80, 0x80)); 

//******************************************
//	New images are added here.
//	First the small image list.
//
	HICON hIcon = (HICON) LoadImage (AfxGetInstanceHandle (),
							 MAKEINTRESOURCE(IDI_DESKTOP), IMAGE_ICON, 16, 16, LR_DEFAULTSIZE);
	m_SmallImages.Add (hIcon);
	DeleteObject (hIcon);
	hIcon = (HICON) LoadImage (AfxGetInstanceHandle (),
							 MAKEINTRESOURCE(IDI_MYPUTER), IMAGE_ICON, 16, 16, LR_DEFAULTSIZE);
	m_SmallImages.Add (hIcon);
	DeleteObject (hIcon);
	hIcon = (HICON) LoadImage (AfxGetInstanceHandle (),
							 MAKEINTRESOURCE(IDI_THEHOOD), IMAGE_ICON, 16, 16, LR_DEFAULTSIZE);
	m_SmallImages.Add (hIcon);
	DeleteObject (hIcon);
//
//	Load a bitmap, resizing it to the image size.
//
	HBITMAP hBmp = (HBITMAP) LoadImage (AfxGetInstanceHandle (),
							 MAKEINTRESOURCE(IDB_DUDLEYPC), IMAGE_BITMAP, 20, 16, LR_DEFAULTCOLOR);
	CBitmap bmp;
	bmp.Attach (hBmp);
	m_SmallImages.Add (&bmp, (COLORREF) 0);
	bmp.Detach ();
	DeleteObject (hBmp);
//
//	Replace the floppy icon with a better one
//	Notice we use the large icon even for the small
//	image list.
	hIcon = (HICON) LoadImage (AfxGetInstanceHandle (),
							 MAKEINTRESOURCE(IDI_35INCHDRIVE), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE);
	m_SmallImages.Replace (2, hIcon);
//
//	Now do the same for the large image list. The
//	large floppy icon already is loaded, so replace
//	it first.
//
	m_LargeImages.Replace (2, hIcon);
	DeleteObject (hIcon);

	hIcon = (HICON) LoadImage (AfxGetInstanceHandle (),
							 MAKEINTRESOURCE(IDI_DESKTOP), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE);
	m_LargeImages.Add (hIcon);
	DeleteObject (hIcon);
	hIcon = (HICON) LoadImage (AfxGetInstanceHandle (),
							 MAKEINTRESOURCE(IDI_MYPUTER), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE);
	m_LargeImages.Add (hIcon);
	DeleteObject (hIcon);
	hIcon = (HICON) LoadImage (AfxGetInstanceHandle (),
							 MAKEINTRESOURCE(IDI_THEHOOD), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE);
	m_LargeImages.Add (hIcon);
	DeleteObject (hIcon);
//
//	Now add that Dudley bitmap.
//
	hBmp = (HBITMAP) LoadImage (AfxGetInstanceHandle (),
							 MAKEINTRESOURCE(IDB_DUDLEYPC), IMAGE_BITMAP, 32, 32, LR_DEFAULTCOLOR);
	bmp.Attach (hBmp);
	m_LargeImages.Add (&bmp, (COLORREF) 0);
	bmp.Detach ();
	DeleteObject (hBmp);

//******************************************

	CFont *font = GetFont ();
	m_ImageListBox.SetFont (font);

	int nCount = sizeof (szItems) / sizeof (char *);

	m_ImageListBox.SetImageList (&m_SmallImages);
	for (int n = 0; n < nCount; ++n)
	{
		LISTIMAGEDATA ld;
		ld.nItem = n;
		ld.nImage = n;
		ld.Text = szItems[n];
		m_ImageListBox.AddItem (ld);
	}
	m_ImageListBox.SetCurSel (0);

//	HIMAGELIST hImages = GetSystemImageList ();
//	m_ComboImages.Attach (hImages);
//	m_ImageComboBox.SetImageList (&m_ComboImages);

    CControlsApp *app = (CControlsApp *) AfxGetApp();
    m_ImageComboBox.SetImageList(app->GetSystemImageList());

	LoadComboBox();
	TCHAR szPath[_MAX_PATH];
	GetCurrentDirectory (_MAX_PATH, szPath);
	TCHAR szDrive[_MAX_PATH], szDir[_MAX_PATH],
		  szName[_MAX_PATH], szExt[_MAX_PATH];
	_splitpath (szPath, szDrive, szDir, szName, szExt);
	if (m_ImageComboBox.SelectString (-1, szDrive) == CB_ERR)
		m_ImageComboBox.SetCurSel (0);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

/////////////////////////////////////////////////////////////////////////////
// CImageListBox support functions

//
//	The owner draw box's MeasureItem() function is
//	called only when the list box is created, so to
//	change image sizes, we need to recreate the box.
//
void CImageListDlg::RecreateListBox()
{
	DWORD dwStyle = m_ImageListBox.GetStyle ();
	dwStyle |= WS_BORDER | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY | WS_VSCROLL;
	int nCount = m_ImageListBox.GetCount ();
	int nSel = m_ImageListBox.GetCurSel ();
	CRect rc;
	m_ImageListBox.GetWindowRect (rc);
	ScreenToClient (rc);
	m_ImageListBox.DestroyWindow ();
	m_ImageListBox.Create (dwStyle, rc, this, IDC_LISTBOX_IMAGES);
	CFont *font = GetFont ();
	m_ImageListBox.SetFont (font);
	for (int n = 0; n < nCount; ++n)
	{
		m_ImageListBox.AddString ("");
	}
	m_ImageListBox.SetCurSel (nSel);
}

/////////////////////////////////////////////////////////////////////////////
// CImageComboBox support functions

int CImageListDlg::GetIconIndex(CString strFileName, DWORD dwAttributes)
{
	SHFILEINFO sfi;
	memset(&sfi, 0, sizeof(sfi));
	if (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)
	{
		SHGetFileInfo (
			strFileName,
			FILE_ATTRIBUTE_DIRECTORY, 
			&sfi, 
			sizeof(sfi), 
			SHGFI_SMALLICON |
				SHGFI_SYSICONINDEX | 
				SHGFI_USEFILEATTRIBUTES |
				(dwAttributes & SHGFI_OPENICON)
			);
		return (sfi.iIcon);
	}
	else
	{
		SHGetFileInfo (
			strFileName, 
			FILE_ATTRIBUTE_NORMAL,
			&sfi, 
			sizeof(sfi), 
			SHGFI_SMALLICON | SHGFI_SYSICONINDEX | (dwAttributes & SHGFI_OPENICON)
		);
		return sfi.iIcon;
	}
	return (-1);
}

void CImageListDlg::LoadComboBox()
{
char			drives [_MAX_PATH];
char *aDrive, *s;	//	= drives;

//	Get the drive string. This is a double NUL terminated list, with
//	each item terminated with a NUL.
//
	if (::GetLogicalDriveStrings(_MAX_PATH, drives))
	{
	char	CurDrive[64];		//	We need the copy because we are going to
								//	remove any trailing backslash, which would
								//	screw up our double NUL terminated list.
		aDrive = drives;
//	Parse the drives
		do
		{
		UINT	type;
//	Get a drive
			strcpy (CurDrive, aDrive);
			type = ::GetDriveType(CurDrive);

			if ((s = strchr (CurDrive, '\\')) != NULL)
				*s = '\0';
//	Make sure the drive letter is caps and add the node for the drive.
			strupr (CurDrive);
			AddNode(CurDrive, -1, type, CImageComboBox::mShort);
			aDrive += strlen (aDrive) + 1;
		} while(strlen (aDrive));
	}
}

void CImageListDlg::AddNode(TCHAR *szName, int nNode, int nType, int nMode)
{
	if (nType >= DRIVE_REMOVABLE)
	{
	char	VolName[24];
	char	RootName[10];
	DWORD	dwCompLen, dwFlags;
	DWORD	dwAttributes;
	COMBOIMAGEDATA	cd;

		dwAttributes = FILE_ATTRIBUTE_SYSTEM;
		sprintf (RootName, "%s\\", szName);
		memset (VolName, '\0', sizeof (VolName));
		GetVolumeInformation (RootName, VolName, 24, NULL, &dwCompLen, &dwFlags, NULL, 0);
		CString fn;
		fn = RootName;
		if (strlen (VolName))
		{
			cd.Text.Format ("%s (%s)", szName, VolName);
		}
		else
			cd.Text.Format ("%s", szName);
		cd.nImage = GetIconIndex (fn, dwAttributes);
		cd.nParentItem = -1;
		cd.Expanded = false;
		cd.nMode = CImageComboBox::mShort;
		m_ImageComboBox.AddItem (cd);
	}
}

⌨️ 快捷键说明

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