在那些控件中可以显示图片呢?我想在picture控件中显示BMP图片,要求从文件中读取出数据后再显示,还要根据图片和控件的实际大小实现滚动条显示,怎么办啦?最好有源码。各位高人指点,帮帮小妹!
解决方案 »
- 求书(图形相关)
- 如何让其他的应用程序作为MDI程序中的字窗口
- 2003server系统到底可以安装vs6吗?
- 关于托盘的2个问题,以前的帖子中没有解答的。
- 谁知道卸载程序的原理?
- 我想用mscomm控件进行处理
- 用 CreateFile 创建的文件,在 CloseHandle 之前,怎么用在 CreateProcess 中?
- 在一个对话框里的问题,困扰~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 关CString类的问题
- MFC,C#,Winform的区别是什么
- 看看这样的代码会生成怎样的机器行为?
- 使用BeginWaitCursor();和EndWaitCursor();
m_mapstore.LoadBitmap(IDB_BITMAP1);
m_Map.SetBitmap(m_mapstore);其中m_Map为picture控件的变量,为CStatic型
HDC hDesDC;
HDC hSrcDC;
CRect rect;
BITMAP bm;
HBITMAP hBitmap;void CShowpictureDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
if(hBitmap)
::StretchBlt(hDesDC, rect.left, rect.top, rect.right, rect.bottom, hSrcDC, 0, 0, bm.bmWidth, bm.bmHeight,+SRCCOPY);}// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CShowpictureDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}void CShowpictureDlg::OnOpen()
{
CFileDialog dlg(TRUE,"bmp",".bmp",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"位图文件(*.BMP)|*.BMP||");
if(dlg.DoModal() == IDOK)
{
hWnd = GetDlgItem(IDC_PIC);
hDesDC = hWnd->GetDC()->m_hDC;
hSrcDC =CreateCompatibleDC(hDesDC);
hBitmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(),dlg.GetPathName(),IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
GetObject(hBitmap, sizeof BITMAP, &bm);
SelectObject(hSrcDC, hBitmap);
hWnd->GetClientRect(&rect);
//::SetStretchBltMode(hDesDC,COLORONCOLOR);
::SetStretchBltMode(hDesDC,HALFTONE);
::StretchBlt(hDesDC, rect.left, rect.top, rect.right, rect.bottom, hSrcDC, 0, 0, bm.bmWidth, bm.bmHeight,+SRCCOPY);
}
UpdateData(FALSE);
}
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(INVALID_HANDLE_VALUE==hFile)
return;
DWORD dsize,outsize;
dsize= GetFileSize(hFile,NULL);
char *data = new char[dsize];
ReadFile(hFile,data,dsize,&outsize,NULL);
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE,dsize);
LPVOID pvData = GlobalLock(hGlobal );
memcpy(pvData,data,dsize);
GlobalUnlock(hGlobal); IPicture *pic = NULL;
LPSTREAM pStream = NULL;
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream );
OleLoadPicture(pStream, 0, FALSE,IID_IPicture, (void **)&pic);
pStream->Release(); OLE_XSIZE_HIMETRIC cx;
OLE_YSIZE_HIMETRIC cy;
pic->get_Width(&cx);
pic->get_Height(&cy);
long PictureWitdh = MAP_LOGHIM_TO_PIX(cx, GetDeviceCaps(::GetDC(m_hWnd), LOGPIXELSX));
long PictureHeight = MAP_LOGHIM_TO_PIX(cy, GetDeviceCaps(::GetDC(m_hWnd), LOGPIXELSX));
RECT bounds;
bounds.top = 0;
bounds.bottom = PictureHeight;
bounds.left = 0;
bounds.right = PictureWitdh; pic->Render(::GetDC(m_hWnd), bounds.left, bounds.bottom, bounds.right - bounds.left,
bounds.top - bounds.bottom, 0, 0, cx, cy, NULL); pic->Release();
delete data;