MFC listcontrol显示图片问题

金色12点丶 2015-04-13 06:35:25
代码如下:
// PicDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "Test.h"
#include "PicDlg.h"
//#include "PicView.h"
//#include "PicDoc.h"


// PicDlg 对话框

IMPLEMENT_DYNAMIC(PicDlg, CDialog)

PicDlg::PicDlg(CWnd* pParent /*=NULL*/)
: CDialog(PicDlg::IDD, pParent)
{
/*CCreateContext pContext;
CWnd* pFrameWnd = this;
pContext.m_pCurrentDoc = new PicDoc;
pContext.m_pNewViewClass = RUNTIME_CLASS(PicView);
PicView* pView = (PicView*)((CFrameWnd*)pFrameWnd)->CreateView(&pContext);
ASSERT(pView);
pView->m_nMapMode = MM_TEXT;
pView->ShowWindow(SW_NORMAL);
CRect rect;
GetWindowRect(rect);
rect.top -= 40;
rect.bottom -= 40;
pView->MoveWindow(rect);*/
}

PicDlg::~PicDlg()
{
}

void PicDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//DDX_Control(pDX,IDC_LIST1,m_list);
}


BEGIN_MESSAGE_MAP(PicDlg, CDialog)
ON_BN_CLICKED(IDC_BUTTON1, &PicDlg::OnBnClickedButton1)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &PicDlg::OnLvnItemchangedList1)
END_MESSAGE_MAP()


// PicDlg 消息处理程序
void PicDlg::PicCreate()
{
i = 0;
i_list = new CImageList();
bool a= i_list->Create(24,24,ILC_COLOR24,0,200);
}

void PicDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
CString PicPathName = NULL;
m_list = (CListCtrl*)GetDlgItem(IDC_LIST1);
m_list->SetExtendedStyle(m_list->GetExtendedStyle()|LVS_EX_GRIDLINES|LVS_EX_SUBITEMIMAGES|LVS_EX_FULLROWSELECT);
edit = (CEdit*)GetDlgItem(IDC_EDIT1);
CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,(LPCTSTR)_TEXT("BMP Files(*bmp)|*.bmp||"),NULL);
if(dlg.DoModal()==IDOK)
{
PicPathName = dlg.GetPathName();
edit->SetWindowTextA(PicPathName);
if(PicPathName) //PicPathName为读取的bmp文件路径
{ //NULL换成AfxGetInstanceHandle()也不行
HBITMAP hbitmap = (HBITMAP)::LoadImage(NULL,_T(PicPathName),IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_CREATEDIBSECTION|LR_LOADFROMFILE);
CBitmap m_Bitmap;
if(hbitmap>0)
{
m_Bitmap.Attach(hbitmap);
}
i_list->Add(&m_Bitmap,RGB(0,0,0));
int a = i_list->GetImageCount(); ->此处getcount为什么执行一次就是42???
m_list->SetImageList(i_list,LVSIL_SMALL);
m_list->InsertItem(0,_T("图片"),i);//i的初始值为0
}
i++;
}
else
{
return;
}
}


void PicDlg::OnLvnItemchangedList1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
//m_list.InsertColumn(0,_T("图片"));
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
}
...全文
243 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-04-14
  • 打赏
  • 举报
回复
请检查每个函数的返回值。 用TRACE辅助调试MFC程序。 TRACE TRACE( exp ) Parameters exp Specifies a variable number of arguments that are used in exactly the same way that a variable number of arguments are used in the run-time function printf. Remarks Provides similar functionality to the printf function by sending a formatted string to a dump device such as a file or debug monitor. Like printf for C programs under MS-DOS, the TRACE macro is a convenient way to track the value of variables as your program executes. In the Debug environment, the TRACE macro output goes to afxDump. In the Release environment, it does nothing. TRACE is limited to sending a total of 512 characters at a time. If you call TRACE with formatting commands, the total string length after the formatting commands have been expanded cannot be more than 512 characters, including the terminating NULL. Exceeding this limit causes an ASSERT. Note This macro is available only in the debug version of MFC. For more information, seeMFC Debugging Support in Visual C++ Programmer’s Guide. Example // example for TRACE int i = 1; char sz[] = "one"; TRACE( "Integer = %d, String = %s\n", i, sz ); // Output: 'Integer = 1, String = one' See Also TRACE0, TRACE1, TRACE2, TRACE3, AfxDump, afxTraceEnabled

64,680

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧