(1)用Windows画图工具将图片另存为.bmp图片,现在测试支持16色图片,24色图片可以支持,256色未测试。
1、把你的图包含到程序的“Bitmap资源”里,提示说该资源使用了大于256色的调色板,在VC里无法编辑等等,点确定就可以
2、定位到 void CXXXDlg::OnPaint(),在if()...else()中的else()下添加如下代码
else
{
//CDialog::OnPaint();//要禁止这个调用 或则放到最后
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP);
//IDB_BITMAP是你自己的图对应的ID
BITMAP bitmap;
bmpBackground.GetBitmap(&bitmap);
CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,
bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
}
(2)在对话框上增加一个按钮ID_Button1,以及一个编辑框控件ID_Editpoints,为编辑框控件添加一个成员变量,m_Editpoints,实现按下按钮ID_Button1,就可以打开文本文件,并将文本文件的内容显示到编辑框中。
在OnButton1()添加如下的代码:
void CBitmap_DLgDlg::OnButton1()
{
// TODO: Add your control notification handler code here
//CColorDialog dlg;
//dlg.DoModal();
CString filter;
filter="文本文件(*txt)|*.txt|GoCAD文件(*.pl,*.ts)|*.pl;*.ts||";
CFileDialog dlg (TRUE,NULL,NULL,OFN_HIDEREADONLY,filter);
if (IDOK==dlg.DoModal())
{
CString s;
s=dlg.GetPathName();
AfxMessageBox(s);
CFile file(s,CFile::modeRead);
char *pBuff;
DWORD dwFileLen;
dwFileLen=file.GetLength();
pBuff=new char[dwFileLen+1];
pBuff[dwFileLen]=0;
file.Read(pBuff,dwFileLen);
file.Close();
UpdateData();
m_Editpoints=pBuff;
UpdateData(false);
}
如果您觉得这篇博文有用,请访问我的个人站:http://www.stubbornhuang.com,更多博文干货等着您。