求编程高手,告诉我怎么在vc++6.0中加载图片,请给出完整的代码,如果给出相关书籍,可加分。
谢谢!以前的答案都不太满意,有没有简便的,从头文件起到结尾,是一个例子的最好了,回答满意,加20分...
谢谢!
以前的答案都不太满意,有没有简便的,从头文件起到结尾,是一个例子的最好了,回答满意,加20分 展开
以前的答案都不太满意,有没有简便的,从头文件起到结尾,是一个例子的最好了,回答满意,加20分 展开
2个回答
展开全部
void CHelloDialog::OnPaint()
{
// TODO: Add your message handler code here
//////////////以下三种情况任选一种会是不同效果(只能一种存在)///////////
//CPaintDC dc(this); //若用此句,得到的是对话框的DC,图片将被绘制在对话框上.
CPaintDC dc(GetDlgItem(IDC_DUSTSTROM1)); //用此句,得到picture控件的DC,图像将被绘制在控件上
// CDC dc;
// dc.m_hDC=::GetDC(NULL); //若用此两句,得到的是屏幕的DC,图片将被绘制在屏幕上///////////////////////////////////////////////////////
CRect rcclient;
GetDlgItem(IDC_DUSTSTROM1)->GetClientRect(&rcclient);
CDC memdc;
memdc.CreateCompatibleDC(&dc);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(&dc, rcclient.Width(), rcclient.Height());
memdc.SelectObject( &bitmap );
CWnd::DefWindowProc(WM_PAINT, (WPARAM)memdc.m_hDC , 0);
CDC maskdc;
maskdc.CreateCompatibleDC(&dc);
CBitmap maskbitmap;
maskbitmap.CreateBitmap(rcclient.Width(), rcclient.Height(), 1, 1, NULL);
maskdc.SelectObject( &maskbitmap );
maskdc.BitBlt( 0, 0, rcclient.Width(), rcclient.Height(), &memdc,
rcclient.left, rcclient.top, SRCCOPY);
CBrush brush;
brush.CreatePatternBrush(&m_bmp);
dc.FillRect(rcclient, &brush);
dc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(), &memdc, rcclient.left, rcclient.top,SRCPAINT);
brush.DeleteObject();
// Do not call CDialog::OnPaint() for painting messages
}
#define THUMWIDTH 180
#define THUMHEIGHT 180
//加载Jpg、Bmp图片,这个函数是关键代码!!!!!!!
HBITMAP CHelloDialog::LoadPicture(CString mFile)
{
CString pFSize;
WCHAR wpath[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, mFile, -1, wpath, MAX_PATH);
IPicture* pPic;
OleLoadPicturePath(wpath, NULL, NULL, NULL, IID_IPicture,(LPVOID*)&pPic);
if (pPic==NULL) return NULL;
HBITMAP hPic = NULL;
pPic->get_Handle((UINT*)&hPic);
long nWidth=THUMWIDTH;
long nHeight=THUMHEIGHT;
long mWid,mHei;
pPic->get_Height(&mHei);
pPic->get_Width(&mWid);
HBITMAP hPicRet = (HBITMAP)CopyImage(hPic, IMAGE_BITMAP, nWidth, nHeight , LR_COPYDELETEORG);
HBRUSH hBrushBorder=::CreateSolidBrush(RGB(192, 192, 192));
HBRUSH hBrushBk=::CreateSolidBrush(RGB(255, 255, 255));
RECT rcBorder;
rcBorder.left=rcBorder.top=0;
rcBorder.right=THUMWIDTH;
rcBorder.bottom=THUMHEIGHT;
const float fRatio=(float)THUMHEIGHT/THUMWIDTH;
int XDest, YDest, nDestWidth, nDestHeight;
const float fImgRatio=(float)mHei/mWid;
if(fImgRatio > fRatio)
{
nDestWidth=(THUMHEIGHT/fImgRatio);
XDest=(THUMWIDTH-nDestWidth)/2;
YDest=0;
nDestHeight=THUMHEIGHT;
}
else
{
XDest=0;
nDestWidth=THUMWIDTH;
nDestHeight=(THUMWIDTH*fImgRatio);
YDest=(THUMHEIGHT-nDestHeight)/2;
}
CClientDC cdc(this);
HDC hDC=::CreateCompatibleDC(cdc.m_hDC);
HBITMAP bm = CreateCompatibleBitmap(cdc.m_hDC, THUMWIDTH, THUMHEIGHT);
HBITMAP pOldBitmapImage = (HBITMAP)SelectObject(hDC,bm);
::FillRect(hDC, &rcBorder, hBrushBk);
::FrameRect(hDC, &rcBorder, hBrushBorder);
HBITMAP hBmReturn= (HBITMAP)::SelectObject(hDC, pOldBitmapImage);
CDC hdcSrc, hdcDst;
hdcSrc.CreateCompatibleDC(NULL);
hdcDst.CreateCompatibleDC(NULL);
// Load the bitmaps into memory DC
CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet);
CBitmap* hbmDstT = (CBitmap*) hdcDst.SelectObject(hBmReturn);
hdcDst.BitBlt(XDest,YDest,nDestWidth, nDestHeight, &hdcSrc,0,0,SRCCOPY);
pOldBitmapImage = (HBITMAP)SelectObject(hdcDst.m_hDC,bm);
DeleteDC(hDC);
DeleteObject(hBrushBorder);
DeleteObject(hBrushBk);
return pOldBitmapImage;
}
//在加载函数中添加代码:
if( m_bmp.m_hObject != NULL )//判断
m_bmp.DeleteObject();
/////////载入图片
HBITMAP hbmp=LoadPicture( "e:\\pictrue.*");
m_bmp.Attach( hbmp );
{
// TODO: Add your message handler code here
//////////////以下三种情况任选一种会是不同效果(只能一种存在)///////////
//CPaintDC dc(this); //若用此句,得到的是对话框的DC,图片将被绘制在对话框上.
CPaintDC dc(GetDlgItem(IDC_DUSTSTROM1)); //用此句,得到picture控件的DC,图像将被绘制在控件上
// CDC dc;
// dc.m_hDC=::GetDC(NULL); //若用此两句,得到的是屏幕的DC,图片将被绘制在屏幕上///////////////////////////////////////////////////////
CRect rcclient;
GetDlgItem(IDC_DUSTSTROM1)->GetClientRect(&rcclient);
CDC memdc;
memdc.CreateCompatibleDC(&dc);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(&dc, rcclient.Width(), rcclient.Height());
memdc.SelectObject( &bitmap );
CWnd::DefWindowProc(WM_PAINT, (WPARAM)memdc.m_hDC , 0);
CDC maskdc;
maskdc.CreateCompatibleDC(&dc);
CBitmap maskbitmap;
maskbitmap.CreateBitmap(rcclient.Width(), rcclient.Height(), 1, 1, NULL);
maskdc.SelectObject( &maskbitmap );
maskdc.BitBlt( 0, 0, rcclient.Width(), rcclient.Height(), &memdc,
rcclient.left, rcclient.top, SRCCOPY);
CBrush brush;
brush.CreatePatternBrush(&m_bmp);
dc.FillRect(rcclient, &brush);
dc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(), &memdc, rcclient.left, rcclient.top,SRCPAINT);
brush.DeleteObject();
// Do not call CDialog::OnPaint() for painting messages
}
#define THUMWIDTH 180
#define THUMHEIGHT 180
//加载Jpg、Bmp图片,这个函数是关键代码!!!!!!!
HBITMAP CHelloDialog::LoadPicture(CString mFile)
{
CString pFSize;
WCHAR wpath[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, mFile, -1, wpath, MAX_PATH);
IPicture* pPic;
OleLoadPicturePath(wpath, NULL, NULL, NULL, IID_IPicture,(LPVOID*)&pPic);
if (pPic==NULL) return NULL;
HBITMAP hPic = NULL;
pPic->get_Handle((UINT*)&hPic);
long nWidth=THUMWIDTH;
long nHeight=THUMHEIGHT;
long mWid,mHei;
pPic->get_Height(&mHei);
pPic->get_Width(&mWid);
HBITMAP hPicRet = (HBITMAP)CopyImage(hPic, IMAGE_BITMAP, nWidth, nHeight , LR_COPYDELETEORG);
HBRUSH hBrushBorder=::CreateSolidBrush(RGB(192, 192, 192));
HBRUSH hBrushBk=::CreateSolidBrush(RGB(255, 255, 255));
RECT rcBorder;
rcBorder.left=rcBorder.top=0;
rcBorder.right=THUMWIDTH;
rcBorder.bottom=THUMHEIGHT;
const float fRatio=(float)THUMHEIGHT/THUMWIDTH;
int XDest, YDest, nDestWidth, nDestHeight;
const float fImgRatio=(float)mHei/mWid;
if(fImgRatio > fRatio)
{
nDestWidth=(THUMHEIGHT/fImgRatio);
XDest=(THUMWIDTH-nDestWidth)/2;
YDest=0;
nDestHeight=THUMHEIGHT;
}
else
{
XDest=0;
nDestWidth=THUMWIDTH;
nDestHeight=(THUMWIDTH*fImgRatio);
YDest=(THUMHEIGHT-nDestHeight)/2;
}
CClientDC cdc(this);
HDC hDC=::CreateCompatibleDC(cdc.m_hDC);
HBITMAP bm = CreateCompatibleBitmap(cdc.m_hDC, THUMWIDTH, THUMHEIGHT);
HBITMAP pOldBitmapImage = (HBITMAP)SelectObject(hDC,bm);
::FillRect(hDC, &rcBorder, hBrushBk);
::FrameRect(hDC, &rcBorder, hBrushBorder);
HBITMAP hBmReturn= (HBITMAP)::SelectObject(hDC, pOldBitmapImage);
CDC hdcSrc, hdcDst;
hdcSrc.CreateCompatibleDC(NULL);
hdcDst.CreateCompatibleDC(NULL);
// Load the bitmaps into memory DC
CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet);
CBitmap* hbmDstT = (CBitmap*) hdcDst.SelectObject(hBmReturn);
hdcDst.BitBlt(XDest,YDest,nDestWidth, nDestHeight, &hdcSrc,0,0,SRCCOPY);
pOldBitmapImage = (HBITMAP)SelectObject(hdcDst.m_hDC,bm);
DeleteDC(hDC);
DeleteObject(hBrushBorder);
DeleteObject(hBrushBk);
return pOldBitmapImage;
}
//在加载函数中添加代码:
if( m_bmp.m_hObject != NULL )//判断
m_bmp.DeleteObject();
/////////载入图片
HBITMAP hbmp=LoadPicture( "e:\\pictrue.*");
m_bmp.Attach( hbmp );
追问
从头文件起到结尾,是一个例子的最好了,回答满意,加20分
2011-06-03
展开全部
{
typedef int (WINAPI ICEPUB_DISPIMG)(HWND hWnd,char *strImgFilename,int x,int y);
ICEPUB_DISPIMG *icePub_dispImg = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_dispImg = (ICEPUB_DISPIMG *)GetProcAddress(hDLLDrv, "icePub_dispImg");
}
if(icePub_dispImg != NULL)
icePub_dispImg(m_hWnd,"b.png",10,10);
// icePub_dispImg(m_ctrlText.m_hWnd,"b.jpg",0,0);
if(hDLLDrv)
FreeLibrary(hDLLDrv);
}
if(hDLLDrv)
FreeLibrary(hDLLDrv);
http://dl.icese.net/dev.php?f=icePubDll.rar 下载
typedef int (WINAPI ICEPUB_DISPIMG)(HWND hWnd,char *strImgFilename,int x,int y);
ICEPUB_DISPIMG *icePub_dispImg = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_dispImg = (ICEPUB_DISPIMG *)GetProcAddress(hDLLDrv, "icePub_dispImg");
}
if(icePub_dispImg != NULL)
icePub_dispImg(m_hWnd,"b.png",10,10);
// icePub_dispImg(m_ctrlText.m_hWnd,"b.jpg",0,0);
if(hDLLDrv)
FreeLibrary(hDLLDrv);
}
if(hDLLDrv)
FreeLibrary(hDLLDrv);
http://dl.icese.net/dev.php?f=icePubDll.rar 下载
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询