Click here to Skip to main content
15,914,500 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Execute program QU Pin
DNFSB22-May-04 14:26
DNFSB22-May-04 14:26 
GeneralUser created menu, using New Selection. Pin
Eversman21-May-04 14:19
Eversman21-May-04 14:19 
QuestionCapturing keyboard input from inside a background WMP9 COM plugin? Pin
IGx8921-May-04 13:47
IGx8921-May-04 13:47 
AnswerRe: Capturing keyboard input from inside a background WMP9 COM plugin? Pin
Michael Dunn21-May-04 14:06
sitebuilderMichael Dunn21-May-04 14:06 
GeneralRe: Capturing keyboard input from inside a background WMP9 COM plugin? Pin
IGx8921-May-04 15:45
IGx8921-May-04 15:45 
AnswerRe: Capturing keyboard input from inside a background WMP9 COM plugin? Pin
Blake Miller25-May-04 15:42
Blake Miller25-May-04 15:42 
GeneralRe: Capturing keyboard input from inside a background WMP9 COM plugin? Pin
IGx8925-May-04 16:05
IGx8925-May-04 16:05 
Generalraw data to bitmap Pin
Snillet2k21-May-04 12:17
Snillet2k21-May-04 12:17 
Hello.
I have posted a question about this before but i wrote it bad. So i try again.
I'm working with a program that storage BMP and WAV files in one file. I'm almost finished with it but I want to make it show BMP files directly from the packed file without extracting it.

I have tried many times but I can't make function to put BITMAPINFOHEADER and BITMAPINFO correct data.

///////////////////////////////////////////////////////////////////////////////
LPTSTR szFileName = "C:\\Min Projekt\\MittPixelTest\\3_16.bmp";
CFile test;
test.Open(szFileName, CFile::modeRead);

DWORD m_nMaxSize = test.GetLength();
void *pBuf = (BYTE *) malloc(sizeof(BYTE) * m_nMaxSize);
test.ReadHuge((LPVOID) pBuf, m_nMaxSize);

LoadBMPImage(pBuf, m_nMaxSize, myBmp, &myPalette);

///////////////////////////////////////////////////////////////////////////////
BOOL CMyArchiveDlg::LoadBMPImage(void* vBits, DWORD len, CBitmap &bitmap, CPalette *pPal)
{
BITMAPFILEHEADER bmfHeader;

// Read file header
if (!memcpy((LPSTR)&bmfHeader, vBits, 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 = len - sizeof(BITMAPFILEHEADER);
HGLOBAL hDIB = ::GlobalAlloc(GMEM_FIXED, nPackedDIBLen);
if (hDIB == 0)
return FALSE;

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

BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)hDIB ; // Gets wrong data
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; // Color value is to high!!

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 ); // Here it's stops. Debug error!

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

::GlobalFree(hDIB);
return TRUE;
}

I guess I use wrong type to put bitmap data but if anyone knows what's wrong with this function it would be greatCool | :cool:
GeneralRe: raw data to bitmap Pin
John R. Shaw22-May-04 17:51
John R. Shaw22-May-04 17:51 
GeneralUnknown Usr Breakpoint causes program halting!?!?! Pin
Wheatbread21-May-04 10:57
Wheatbread21-May-04 10:57 
GeneralRe: Unknown Usr Breakpoint causes program halting!?!?! Pin
Alexander M.,23-May-04 9:50
Alexander M.,23-May-04 9:50 
GeneralKeyboard Accelerators for CFormView Pin
brdavid21-May-04 9:54
brdavid21-May-04 9:54 
General_inp and _outp Pin
eggie521-May-04 9:35
eggie521-May-04 9:35 
GeneralRe: _inp and _outp Pin
21-May-04 10:54
suss21-May-04 10:54 
GeneralRe: _inp and _outp Pin
eggie521-May-04 11:01
eggie521-May-04 11:01 
GeneralRe: _inp and _outp Pin
21-May-04 12:29
suss21-May-04 12:29 
GeneralRe: _inp and _outp Pin
Prakash Nadar21-May-04 16:45
Prakash Nadar21-May-04 16:45 
GeneralRe: _inp and _outp Pin
eggie521-May-04 18:17
eggie521-May-04 18:17 
GeneralStrFormatByteSize() Pin
DanYELL21-May-04 9:29
DanYELL21-May-04 9:29 
GeneralRe: StrFormatByteSize() Pin
Michael Dunn21-May-04 12:57
sitebuilderMichael Dunn21-May-04 12:57 
GeneralRe: StrFormatByteSize() Pin
DanYELL21-May-04 15:20
DanYELL21-May-04 15:20 
QuestionCorrect Usage of WaitCommEvent? Pin
AnotherProgrammer21-May-04 8:31
AnotherProgrammer21-May-04 8:31 
AnswerFurthermore... (another question - about ReadFile this time) Pin
AnotherProgrammer21-May-04 8:40
AnotherProgrammer21-May-04 8:40 
AnswerRe: Correct Usage of WaitCommEvent? Pin
Antti Keskinen23-May-04 0:08
Antti Keskinen23-May-04 0:08 
GeneralSubclassed ActiveX control Pin
BlackDice21-May-04 7:01
BlackDice21-May-04 7:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.