大家好,我通过一下代码,想在一个控件上显示一张图片,但是不知为什么图片一直不显示:TCHAR buff[200];
CString strPath;
CImage img;
GetModuleFileName(NULL,buff,200);
strPath.Format(_T("%s"),buff);
strPath = strPath.Left(strPath.ReverseFind('\\'));
HDC dc;
CRect rect;
dc = ::GetDC(m_hWnd);
HRESULT hResult;
CString str = strPath + _T("\\Winter.jpg");
hResult = img.Load(str);
GetDlgItem(IDC_STATIC)->GetWindowRect(&rect);
img.Draw(dc,rect);
CString strPath;
CImage img;
GetModuleFileName(NULL,buff,200);
strPath.Format(_T("%s"),buff);
strPath = strPath.Left(strPath.ReverseFind('\\'));
HDC dc;
CRect rect;
dc = ::GetDC(m_hWnd);
HRESULT hResult;
CString str = strPath + _T("\\Winter.jpg");
hResult = img.Load(str);
GetDlgItem(IDC_STATIC)->GetWindowRect(&rect);
img.Draw(dc,rect);
解决方案 »
- 如何在ListBox 中 的行中加入 checkbox,combobox
- visual studio c++中mfc应用程序入门(望高手指点迷津)
- 在DLL中使用主程序的ListCtrl为何不行?
- 请教 结构清空
- 求有关链表操作封装的类,例如,查询,删除,插入,更新,.....
- 高分求例子:类似于Sql的查询设计器或Acess的视图设计器的应用?UP有分!
- 什么是compound document
- TabCtrl控件问题
- VS2012重载对话框类中重载OnCreateerror C2019: 应输入预处理器指令,却找到“3”
- vc编程取数啊求助
- CListCtrl的LVS_LIST样式,如何显示两列?
- vc6.0中listbox控件实时显示问题
然后载入图片后调用invalidate刷新试试
CString strPath;
CImage img;
GetModuleFileName(NULL,buff,200);
strPath.Format(_T("%s"),buff);
strPath = strPath.Left(strPath.ReverseFind('\\'));
HDC dc;
CRect rect;
dc = ::GetDC(GetDlgItem(IDC_STATIC)->m_hWnd); //修改过控件的DC
HRESULT hResult;
CString str = strPath + _T("\\Winter.jpg");
hResult = img.Load(str);
GetDlgItem(IDC_STATIC)->GetClientRect(&rect); //修改过控件大小
img.Draw(dc,rect);
例如BUTTON 加载图片 BS_BITMAP