如何显示GIF。JPEG。BMP格式的图片 我现在想把GIF、JPEG、BMP格式的图片在ListCtrl(ICON风格)中作为图标显示出来。怎么显示。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://blog.csdn.net/jiangsheng/archive/2003/11/20/3796.aspx LPPICTURE gpPicture;// This function loads a file into an IStream.void LoadPictureFile(LPCTSTR szFile){ // open file HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); _ASSERTE(INVALID_HANDLE_VALUE != hFile); // get file size DWORD dwFileSize = GetFileSize(hFile, NULL); _ASSERTE(-1 != dwFileSize); LPVOID pvData = NULL; // alloc memory based on file size HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize); _ASSERTE(NULL != hGlobal); pvData = GlobalLock(hGlobal); _ASSERTE(NULL != pvData); DWORD dwBytesRead = 0; // read file and store in global memory BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL); _ASSERTE(FALSE != bRead); GlobalUnlock(hGlobal); CloseHandle(hFile); LPSTREAM pstm = NULL; // create IStream* from global memory HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm); _ASSERTE(SUCCEEDED(hr) && pstm); // Create IPicture from image file if (gpPicture) gpPicture->Release(); hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture); _ASSERTE(SUCCEEDED(hr) && gpPicture); pstm->Release(); InvalidateRect(ghWnd, NULL, TRUE);}case WM_PAINT: hdc = BeginPaint(hWnd, &ps); if (gpPicture) { // get width and height of picture long hmWidth; long hmHeight; gpPicture->get_Width(&hmWidth); gpPicture->get_Height(&hmHeight); // convert himetric to pixels int nWidth = MulDiv(hmWidth, GetDeviceCaps(hdc, LOGPIXELSX), HIMETRIC_INCH); int nHeight = MulDiv(hmHeight, GetDeviceCaps(hdc, LOGPIXELSY), HIMETRIC_INCH); RECT rc; GetClientRect(hWnd, &rc); // display picture using IPicture::Render gpPicture->Render(hdc, 0, 0, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, &rc); } EndPaint(hWnd, &ps); break; 现在可以在PICTURE控件上显示GIF、JPG、BMP图片没问题。我看了jiangsheng(蒋晟.MSMVP2004Jan) 的文章,但是在LISTCTRL(ICON)中用GIF、JPG图片显示在ICON位置还是不会,还请指教。。 我用的就是IPICTURE,但是在listctrl中某一ITEM占的矩形区域绘图,没有成功。我是这样用的。C**::OnPaint(){ pPicutre->render(..)}但是没有成功绘出来,显示的还是原来的ICON图标 To Mackz(在相互):我是这样写的,能否帮我看看到底哪里有问题,不甚感激我选中了ListCtrl(ICON风格)中Ownern Draw fixed属性,下面是在第一个ICON位置显示图片,但没有成功,帮我看看C**::OninitDialog(){ m_ImageList.Create(64,64,ILC_COLOR32,10,30); m_list.SetImageList(&m_ImageList,LVSIL_NORMAL); HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_ImageList.Add(hIcon); m_list.InsertItem(0, "HELLO", 0); //加载图片,省略}C**:: OnPaint(){ CPaintDC dc(this); long hmWidth; long hmHeight; pPicture->get_Width(&hmWidth); pPicture->get_Height(&hmHeight); #define HIMETRIC_INCH 2540 // convert himetric to pixels int nWidth = MulDiv(hmWidth, GetDeviceCaps(dc, LOGPIXELSX), HIMETRIC_INCH); int nHeight = MulDiv(hmHeight, GetDeviceCaps(dc, LOGPIXELSY), HIMETRIC_INCH); CRect rect2; CRect rc; CRect rect1; GetClientRect(&rect1); POINT point2; point2.x = rect1.left; point2.y = rect1.top; CRect rcImage(CPoint(0,0),CPoint(hmWidth, hmHeight)); rc.IntersectRect(&rcImage, &rect2); CPoint point; ::ClientToScreen(this->m_hWnd, &point2); ::ClientToScreen(m_Pic2.m_hWnd, &point1); CRect rect3; m_list.GetItemRect(0, &rect3, LVIR_ICON); POINT point3; point3.x = rect3.left; point3.y = rect3.top; ::ClientToScreen(m_list.m_hWnd, &point3); rc.IntersectRect(&rcImage, &rect3); pPicture->Render(dc, point3.x-point2.x, point3.y-point2.y, rc.Width(), (long)rc.Height(), 0, hmHeight, hmWidth, -hmHeight, &rc);} opengl读取单个像素问题 怎么样判断键盘按键是一直在被按着 如何获取QQ游戏大厅里面桌子的位置呢? 如何为自己分配内存空间,并管理该空间? 文件读写的问题:怎样读入一行并且写入一行字符串?? 如何将一个字符串转为16进制书 怎样显示异地服务器上的目录结构 Microsoft VS .NET 2003下,如何profile 请教大家关于16进制转换的问题,麻烦大家看看错在哪里 如何改变文本框中字的颜色? 〓〓〓〓 散分庆祝自己成为VC/MFC版大斑竹(试用期内)——2 〓〓〓〓 问题:MFC引用Win32 CPP文件C1010错误
// This function loads a file into an IStream.
void LoadPictureFile(LPCTSTR szFile)
{
// open file
HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
_ASSERTE(INVALID_HANDLE_VALUE != hFile); // get file size
DWORD dwFileSize = GetFileSize(hFile, NULL);
_ASSERTE(-1 != dwFileSize); LPVOID pvData = NULL;
// alloc memory based on file size
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
_ASSERTE(NULL != hGlobal); pvData = GlobalLock(hGlobal);
_ASSERTE(NULL != pvData); DWORD dwBytesRead = 0;
// read file and store in global memory
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
_ASSERTE(FALSE != bRead);
GlobalUnlock(hGlobal);
CloseHandle(hFile); LPSTREAM pstm = NULL;
// create IStream* from global memory
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
_ASSERTE(SUCCEEDED(hr) && pstm); // Create IPicture from image file
if (gpPicture)
gpPicture->Release();
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture);
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release(); InvalidateRect(ghWnd, NULL, TRUE);
}
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
if (gpPicture)
{
// get width and height of picture
long hmWidth;
long hmHeight;
gpPicture->get_Width(&hmWidth);
gpPicture->get_Height(&hmHeight);
// convert himetric to pixels
int nWidth = MulDiv(hmWidth, GetDeviceCaps(hdc, LOGPIXELSX), HIMETRIC_INCH);
int nHeight = MulDiv(hmHeight, GetDeviceCaps(hdc, LOGPIXELSY), HIMETRIC_INCH);
RECT rc;
GetClientRect(hWnd, &rc);
// display picture using IPicture::Render
gpPicture->Render(hdc, 0, 0, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, &rc);
}
EndPaint(hWnd, &ps);
break;
我是这样用的。
C**::OnPaint()
{
pPicutre->render(..)
}
但是没有成功绘出来,显示的还是原来的ICON图标
我选中了ListCtrl(ICON风格)中Ownern Draw fixed属性,下面是在第一个ICON
位置显示图片,但没有成功,帮我看看
C**::OninitDialog()
{
m_ImageList.Create(64,64,ILC_COLOR32,10,30);
m_list.SetImageList(&m_ImageList,LVSIL_NORMAL);
HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_ImageList.Add(hIcon);
m_list.InsertItem(0, "HELLO", 0);
//加载图片,省略
}
C**:: OnPaint()
{
CPaintDC dc(this);
long hmWidth;
long hmHeight;
pPicture->get_Width(&hmWidth);
pPicture->get_Height(&hmHeight);
#define HIMETRIC_INCH 2540
// convert himetric to pixels
int nWidth = MulDiv(hmWidth, GetDeviceCaps(dc, LOGPIXELSX), HIMETRIC_INCH);
int nHeight = MulDiv(hmHeight, GetDeviceCaps(dc, LOGPIXELSY), HIMETRIC_INCH);
CRect rect2; CRect rc;
CRect rect1;
GetClientRect(&rect1); POINT point2;
point2.x = rect1.left;
point2.y = rect1.top; CRect rcImage(CPoint(0,0),CPoint(hmWidth, hmHeight));
rc.IntersectRect(&rcImage, &rect2);
CPoint point; ::ClientToScreen(this->m_hWnd, &point2);
::ClientToScreen(m_Pic2.m_hWnd, &point1);
CRect rect3;
m_list.GetItemRect(0, &rect3, LVIR_ICON);
POINT point3;
point3.x = rect3.left;
point3.y = rect3.top;
::ClientToScreen(m_list.m_hWnd, &point3);
rc.IntersectRect(&rcImage, &rect3);
pPicture->Render(dc, point3.x-point2.x, point3.y-point2.y, rc.Width(), (long)rc.Height(), 0, hmHeight, hmWidth, -hmHeight, &rc);
}