It's obvious that this can be done in many ways. let me show you some of the ways you can use (only source because I have to leave in about 15 minutes)
it's my code, so few comments
code:
PDIB CEditImageDlg: ibOpenFile(CString szFile){ HFILE fh; DWORD dwLen, dwBits; PDIB pdib; LPVOID p; OFSTRUCT of;#if defined(WIN32) | | defined (_WIN32)#define GetCurrentInstance() GetModuleHandle(NULL)#else#define GetCurrentInstance() (HINSTANCE)SELECTOROF((LPVOID)&of)#endif fh = OpenFile(szFile, &of, OF_READ); if(fh == -1) { HRSRC h; h = FindResource(GetCurrentInstance(), szFile, RT_BITMAP);#if defined(WIN32) | | defined(_WIN32) if(h) return (PDIB)LockResource(LoadResource(GetCurrentInstance(), h));#else if(h) fh = AccessResource(GetCurrentInstance(), h);#endif } if(fh == -1) return NULL; pdib = DibReadBitmapInfo(fh); if(!pdib) return NULL; dwBits = pdib->biSizeImage; dwLen = pdib->biSize + DibPaletteSize(pdib) + dwBits; p = GlobalReAllocPtr(pdib, dwLen, 0); if(!p) { GlobalFreePtr(pdib); pdib = NULL; } else { pdib = (PDIB)p; } if(pdib) { _hread(fh, (LPBYTE)pdib + (UINT)pdib->biSize + DibPaletteSize(pdib), dwBits); } _lclose(fh); return pdib;}PDIB CEditImageDlg: ibReadBitmapInfo(HFILE fh){ DWORD off; HANDLE hbi = NULL; int size; int i; int nNumColors; RGBQUAD FAR *pRgb; BITMAPINFOHEADER bi; BITMAPCOREHEADER bc; BITMAPFILEHEADER bf; PDIB pdib; if(fh == -1) return NULL; off = _llseek(fh, 0L, SEEK_CUR); if(sizeof(bf) != _lread(fh, (LPSTR)&bf, sizeof(bf))) return FALSE; if(bf.bfType != BFT_BITMAP) { bf.bfOffBits = 0L; _llseek(fh, off, SEEK_SET); } if(sizeof(bi) != _lread(fh, (LPSTR)&bi, sizeof(bi))) return FALSE; switch(size = (int)bi.biSize) { default: case sizeof(BITMAPINFOHEADER): break; case sizeof(BITMAPCOREHEADER): bc = *(BITMAPCOREHEADER*)&bi bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = (DWORD)bc.bcWidth; bi.biHeight = (DWORD)bc.bcHeight; bi.biPlanes = (UINT)bc.bcPlanes; bi.biBitCount = (UINT)bc.bcBitCount; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; _llseek(fh, (LONG)sizeof(BITMAPCOREHEADER)-sizeof(BITMAPINFOHEADER), SEEK_CUR); break; } nNumColors = DibNumColors(&bi);#if 0 if(bi.biSizeImage == 0) bi.biSizeImage = DibSizeImage(&bi); if(bi.biClrUsed == 0) bi.biClrUsed = DibNumColors(&bi);#else FixBitmapInfo(&bi);#endif pdib = (PDIB)GlobalAllocPtr(GMEM_MOVEABLE, (LONG)bi.biSize + nNumColors * sizeof(RGBQUAD)); if(!pdib) return NULL; *pdib = bi; pRgb = DibColors(pdib); if(nNumColors) { if(size == sizeof(BITMAPCOREHEADER)) { _lread(fh, (LPVOID)pRgb, nNumColors * sizeof(RGBTRIPLE)); for(i = nNumColors - 1; i >=0; i--) { RGBQUAD rgb; rgb.rgbRed = ((RGBTRIPLE FAR*)pRgb).rgbtRed;<BR> rgb.rgbBlue = ((RGBTRIPLE FAR*)pRgb).rgbtBlue;<BR> rgb.rgbGreen = ((RGBTRIPLE FAR*)pRgb).rgbtGreen;<BR> rgb.rgbReserved = (BYTE)0;<BR> }<BR> }<BR> else<BR> _lread(fh, (LPVOID)pRgb, nNumColors * sizeof(RGBQUAD));<BR> }<BR> if(bf.bfOffBits != 0L)<BR> _llseek(fh, off + bf.bfOffBits, SEEK_SET);<P> //m_ColorUsed = nNumColors;<BR> //UpdateData(FALSE);<P> return pdib;<BR>}<BR></pre><HR></BLOCKQUOTE><P>for hard coded:<P><BLOCKQUOTE><font size="1" face="Verdana, Arial">code:</font><HR><pre><BR> CPaintDC dc(this); // device context for painting<BR> HBITMAP hbitmap = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_BITMAP1));<P> HDC hMemDC = ::CreateCompatibleDC(NULL);<P> SelectObject(hMemDC, hbitmap);<P> ::StretchBlt(dc.m_hDC, 45, 175, 200, 120, hMemDC, 0, 0, 200, 120, SRCCOPY);<P> : <IMG SRC="http://www.gamedev.net/community/forums/ubb/biggrin.gif">eleteDC(hMemDC);<BR> : <IMG SRC="http://www.gamedev.net/community/forums/ubb/biggrin.gif">eleteObject(hbitmap);<P></pre><HR></BLOCKQUOTE><P>That's about the MFC manner……….check out the functions I used, and see what you can change. The best way i think is the first, because it's easier to make changes (which I will show you if you want), and to move……..and it loads every bmp file….<P>Hmmmm…..<P><BR>There are also a lot of other manners. Damn, too many to suit the needs.<P>——————<BR>Dance with me……