帮小学弟写的一个mfc的小程序,比较简单。
1.触发List Bo控件的左键单击事件
void Ctest_pictureDlg::OnLbnDblclkList1()
{
// TODO: 在此添加控件通知处理程序代码
int nIndex = m_listBox.GetCurSel();
CString BmpName;
CString PicInfo;
switch (nIndex)
{
case 0:
BmpName = "0.bmp";
PicInfo = "第0石英";
break;
case 1:
BmpName = "1.bmp";
PicInfo = "第1石英";
break;
case 2:
BmpName = "2.bmp";
PicInfo = "第2石英";
break;
case 3:
BmpName = "3.bmp";
PicInfo = "第3石英";
break;
case 4:
BmpName = "4.bmp";
PicInfo = "第4石英";
break;
case 5:
BmpName = "5.bmp";
PicInfo = "第5石英";
break;
default:
break;
}
ShowPicture(BmpName);
ShowPictureInfo(PicInfo);
}
参考:http://blog.csdn.net/eastmount/article/details/26404733
void Ctest_pictureDlg::ShowPicture(CString BmpName)
{
//定义变量存储图片信息
BITMAPINFO *pBmpInfo; //记录图像细节
BYTE *pBmpData; //图像数据
BITMAPFILEHEADER bmpHeader; //文件头
BITMAPINFOHEADER bmpInfo; //信息头
CFile bmpFile; //记录打开文件
//以只读的方式打开文件 读取bmp图片各部分 bmp文件头 信息 数据
if (!bmpFile.Open(BmpName, CFile::modeRead | CFile::typeBinary))
{
MessageBox( _T("Picture not found!") , _T("Error") ,NULL );
return;
}
if (bmpFile.Read(&bmpHeader, sizeof(BITMAPFILEHEADER)) != sizeof(BITMAPFILEHEADER))
return;
if (bmpFile.Read(&bmpInfo, sizeof(BITMAPINFOHEADER)) != sizeof(BITMAPINFOHEADER))
return;
pBmpInfo = (BITMAPINFO *)new char[sizeof(BITMAPINFOHEADER)];
//为图像数据申请空间
memcpy(pBmpInfo, &bmpInfo, sizeof(BITMAPINFOHEADER));
DWORD dataBytes = bmpHeader.bfSize - bmpHeader.bfOffBits;
pBmpData = (BYTE*)new char[dataBytes];
bmpFile.Read(pBmpData, dataBytes);
bmpFile.Close();
//显示图像
CWnd *pWnd = GetDlgItem(IDC_STATIC_Pic); //获得pictrue控件窗口的句柄
CRect rect;
pWnd->GetClientRect(&rect); //获得pictrue控件所在的矩形区域
CDC *pDC = pWnd->GetDC(); //获得pictrue控件的DC
pDC->SetStretchBltMode(COLORONCOLOR);
StretchDIBits(pDC->GetSafeHdc(), 0, 0, rect.Width(), rect.Height(), 0, 0,
bmpInfo.biWidth, bmpInfo.biHeight, pBmpData, pBmpInfo, DIB_RGB_COLORS, SRCCOPY);
}
参考:http://www.cppblog.com/mzty/archive/2006/11/13/15131.html
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183499%28v=vs.85%29.aspx
void Ctest_pictureDlg::OnLbnDblclkListFont()
{
// TODO: 在此添加控件通知处理程序代码
int nIndex = m_fontList.GetCurSel();
CString FontType;
switch (nIndex)
{
case 0:
FontType = _T("Arial");
break;
case 1:
FontType = _T("黑体");
break;
case 2:
FontType = _T("宋体");
break;
case 3:
FontType = _T("微软雅黑");
break;
case 4:
FontType = _T("仿宋");
break;
case 5:
FontType = _T("楷体");
break;
default:
break;
}
MySetFont(FontType);
}
void Ctest_pictureDlg::MySetFont(CString FontType)
{
CFont * f;
f = new CFont;
f->CreateFont(16, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_BOLD, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
DEFAULT_CHARSET,//CHINESEBIG5_CHARSET,//ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
FontType.GetBuffer(FontType.GetLength() )); // lpszFac
GetDlgItem(IDC_STATIC_PICINFO)->SetFont(f);
m_listBox.SetFont(f);
m_fontList.SetFont(f);
}
List Box控件操作参考:http://blog.sina.com.cn/s/blog_6ca43ae701019h8k.html
http://blog.csdn.net/joseph_happy/article/details/598267
static控件参考:
http://www.cnblogs.com/pfa2008/archive/2010/01/25/1655947.html
http://www.cnblogs.com/pfa2008/archive/2010/01/25/1655947.html