erehw(疯狂CS)及各位高手进来看一下,有关位图做为背景的问题!!我快要疯了!!!!!!!!!

liwenqian 2001-05-29 10:22:00
昨天,我问了一个有关位图做为背景的问题,要求在OnPaint()中实现的。
erehw(疯狂CS)回复如下:
void CAboutDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting

CString strPath;
//GetModulePath(strPath);
//strPath += "\\LoginSpalsh.bmp";
strPath += "e:\\prj\\fpcontrol\\debug\\LoginSpalsh.bmp";
CDC tempDC;
CRect rect;
HBITMAP hBitmap=(HBITMAP)LoadImage(AfxGetApp()->m_hInstance,strPath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
CBitmap m_BackBmp;
BITMAP bitmap;
m_BackBmp.Attach(hBitmap);
m_BackBmp.GetBitmap (&bitmap);
int nHeight=bitmap.bmHeight;
int nWidth =bitmap.bmWidth ;
GetClientRect(rect);
tempDC.CreateCompatibleDC(&dc);
tempDC.SelectObject(&m_BackBmp);
//dc.FillSolidRect(rect, RGB(212,208,202));
//pDC->FillSolidRect(rect, RGB(255,255,255));


dc.BitBlt(0,0, nWidth, nHeight, &tempDC, 0, 0, SRCCOPY );


tempDC.DeleteDC();
}

我在vc6中能够实现,但是,我的毕业设计要求在vc1.52,win16,windows3.2环境下.
我把代码照搬,编译时它不认得LoadImage,IMAGE_BITMAP,LR_LOADFROMFILE这几个东西.反正HBITMAP hBitmap=(HBITMAP)LoadImage(AfxGetApp()->m_hInstance,strPath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
这句话它看不懂。

各为高手若有资料或别的方法请指点一下,最好有代码。我对vc不熟!!
有没有不用上面这句话的方法但要在OnPaint()中实现

谢谢!!
另能不能解释一下 HBITMAP hBitmap=(HBITMAP)LoadImage(AfxGetApp()->m_hInstance,strPath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
我也看不懂
谢谢!

...全文
208 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
lllllll 2001-05-30
  • 打赏
  • 举报
回复
LoadBitmap() 不行吗?
shalala 2001-05-29
  • 打赏
  • 举报
回复
嘿嘿
我现在有一个CDIB的类。
很是好用的
111222 2001-05-29
  • 打赏
  • 举报
回复
vc1.52?

vc1.52支持MFC么?
lllllll 2001-05-29
  • 打赏
  • 举报
回复
LoadBitmap()
seesi 2001-05-29
  • 打赏
  • 举报
回复
什么??vc1.52,win32??
大概我贴的上面的函数也不能用了,你看看吧。我看还有没有别的方法
seesi 2001-05-29
  • 打赏
  • 举报
回复
用下面的函数加载位图

// LoadBMPImage - Loads a BMP file and creates a bitmap GDI object
// also creates logical palette for it.
// Returns - TRUE for success
// sBMPFile - Full path of the BMP file
// bitmap - The bitmap object to initialize
// pPal - Will hold the logical palette. Can be NULL
BOOL LoadBMPImage( LPCTSTR sBMPFile, CBitmap& bitmap, CPalette *pPal )
{
CFile file;
if( !file.Open( sBMPFile, CFile::modeRead) )
return FALSE;

BITMAPFILEHEADER bmfHeader;

// Read file header
if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader)) != sizeof(bmfHeader))
return FALSE;

// File type should be 'BM'
if (bmfHeader.bfType != ((WORD) ('M' << 8) | 'B'))
return FALSE;

// Get length of the remainder of the file and allocate memory
DWORD nPackedDIBLen = file.GetLength() - sizeof(BITMAPFILEHEADER);
HGLOBAL hDIB = ::GlobalAlloc(GMEM_FIXED, nPackedDIBLen);
if (hDIB == 0)
return FALSE;

// Read the remainder of the bitmap file.
if (file.ReadHuge((LPSTR)hDIB, nPackedDIBLen) != nPackedDIBLen )
{
::GlobalFree(hDIB);
return FALSE;
}


BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)hDIB ;
BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB ;

// If bmiHeader.biClrUsed is zero we have to infer the number
// of colors from the number of bits used to specify it.
int nColors = bmiHeader.biClrUsed ? bmiHeader.biClrUsed :
1 << bmiHeader.biBitCount;

LPVOID lpDIBBits;
if( bmInfo.bmiHeader.biBitCount > 8 )
lpDIBBits = (LPVOID)((LPDWORD)(bmInfo.bmiColors + bmInfo.bmiHeader.biClrUsed) +
((bmInfo.bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0));
else
lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors);

// Create the logical palette
if( pPal != NULL )
{
// Create the palette
if( nColors <= 256 )
{
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];

pLP->palVersion = 0x300;
pLP->palNumEntries = nColors;

for( int i=0; i < nColors; i++)
{
pLP->palPalEntry[i].peRed = bmInfo.bmiColors[i].rgbRed;
pLP->palPalEntry[i].peGreen = bmInfo.bmiColors[i].rgbGreen;
pLP->palPalEntry[i].peBlue = bmInfo.bmiColors[i].rgbBlue;
pLP->palPalEntry[i].peFlags = 0;
}

pPal->CreatePalette( pLP );

delete[] pLP;
}
}

CClientDC dc(NULL);
CPalette* pOldPalette = NULL;
if( pPal )
{
pOldPalette = dc.SelectPalette( pPal, FALSE );
dc.RealizePalette();
}

HBITMAP hBmp = CreateDIBitmap( dc.m_hDC, // handle to device context
&bmiHeader, // pointer to bitmap size and format data
CBM_INIT, // initialization flag
lpDIBBits, // pointer to initialization data
&bmInfo, // pointer to bitmap color-format data
DIB_RGB_COLORS); // color-data usage
bitmap.Attach( hBmp );

if( pOldPalette )
dc.SelectPalette( pOldPalette, FALSE );

::GlobalFree(hDIB);
return TRUE;
}
liwenqian 2001-05-29
  • 打赏
  • 举报
回复
做为工控机用!
能不能提供源代码?我很急,谢了先。


















akiko 2001-05-29
  • 打赏
  • 举报
回复
LoadImage你查一下MSDN很清楚的.
你的毕业设计环境太奇怪了,要干什么啊?
BugKiller 2001-05-29
  • 打赏
  • 举报
回复
什么年代了了,还vc1.52,win32. 简直就是折磨人。
LoadImage是从文件中读出一个bmp文件至一个句柄中。你可以自己实现一个这样的函数。不会很难的。


---------------------------------
小辉 http://www.ChinaIThero.com
SmartHeart 2001-05-29
  • 打赏
  • 举报
回复
win32?我的天哪.
你去找一些老书吧.我记得当时用的是BC啊.
seesi 2001-05-29
  • 打赏
  • 举报
回复
GlobalAlloc好象是在95后采用的
vcmfc 2001-05-29
  • 打赏
  • 举报
回复
gameboy999(工作好无聊)是调用系统的COM接口来实现的,在WIN3.2我看也不一定有效呀!,不知道有没有这个接口呀!
kalling 2001-05-29
  • 打赏
  • 举报
回复
你只能去当一个windows3.2的platform sdk,查查LoadImage的用法,现在的msdn中查到的都是win95以后的
erehw 2001-05-29
  • 打赏
  • 举报
回复
天哪,我糊涂了,Windows3.2中有没有这个User32.DLL,即使有那看还有没有实现这个函数?
erehw 2001-05-29
  • 打赏
  • 举报
回复
兄弟。不过看GameBoy的代码好象有点点用。

还有一个办法就是:就是那个
HBITMAP hBitmap=(HBITMAP)LoadImage(AfxGetApp()->m_hInstance,strPath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
中的:
LoadImage是在User32.DLL
你不妨如下去做,
LoadLibrary然后
GetProcAddress
然后再试试。
Cowboy22 2001-05-29
  • 打赏
  • 举报
回复
vc1.52,win16,windows3.2
由此可见咱们的教育水平多落后啊...
gameboy999 2001-05-29
  • 打赏
  • 举报
回复
我也提供一段代码吧,加到onpaint中去
注意要改图片路径,支持bmp,jpg,gif三种格式,
需要用到dc.
如果出错,试着在CyourApp的initial里加入AfxOleInit()

IPicture *pPic;
IStream *pStm;
CFileStatus fstatus;
CFile file;
LONG cb;
if (file.Open("c://test.jpg",CFile::modeRead)&&file.GetStatus("c://test.jpg",fstatus)&&((cb = fstatus.m_size) != -1))
{
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
LPVOID pvData = NULL;
if (hGlobal != NULL)
{
if ((pvData = GlobalLock(hGlobal)) != NULL)
{
file.ReadHuge(pvData, cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
double fX,fY;
//获得象素值
fX=(double)dc.GetDeviceCaps(HORZRES);
fY=(double)dc.GetDeviceCaps(VERTRES);
if(FAILED(pPic->Render(dc,0,0,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL)))
AfxMessageBox("Failed To Render The picture!");
pPic->Release();
}
else
AfxMessageBox("Error Loading Picture From Stream!");
}
}
}
else
AfxMessageBox("Can't Open Image File!");
liwenqian 2001-05-29
  • 打赏
  • 举报
回复
seesi:
你的代码也不能用。不过还是要谢谢你!

我放弃了!
让那该死的毕业设计去见鬼吧!!!!!!!!!!!!

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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