Click here to Skip to main content
15,902,938 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Question regarding DirectX Pin
godspeed1237-Aug-07 4:49
godspeed1237-Aug-07 4:49 
GeneralRe: Question regarding DirectX Pin
Mark Salsbery7-Aug-07 5:04
Mark Salsbery7-Aug-07 5:04 
QuestionSetting CComboBox Height Pin
WayneK1006-Aug-07 12:41
WayneK1006-Aug-07 12:41 
AnswerRe: Setting CComboBox Height Pin
Mark Salsbery6-Aug-07 13:35
Mark Salsbery6-Aug-07 13:35 
GeneralRe: Setting CComboBox Height Pin
WayneK1006-Aug-07 14:06
WayneK1006-Aug-07 14:06 
GeneralRe: Setting CComboBox Height Pin
Mark Salsbery6-Aug-07 14:14
Mark Salsbery6-Aug-07 14:14 
AnswerRe: Setting CComboBox Height Pin
Anurag Gandhi6-Aug-07 20:18
professionalAnurag Gandhi6-Aug-07 20:18 
QuestionExtracting binary resources -- PNG and Bitmap Pin
Torus_XL6-Aug-07 9:37
Torus_XL6-Aug-07 9:37 
I am having a problem extracting the binaries of PNG files and extracting Bitmap files to write to disk. I am using http://www.codeproject.com/win32/binaryresources.asp[^] as a rough guide.

The problem with the PNG is that the extracted PNG files are automatically buffered to have a number of bytes equal to a multiple of TCHAR. For example, one PNG resource I have is 251 bytes long, but when extracted it is 255. These 4 extra bytes seem to be making it an unreadable file. Is there any kind of data type that is a pure bit stream, or is there a way to write the TCHAR byte by byte and leave off those extra 4 bytes?

As for the bitmap files, a similar problem occurs. For this I will post some code:
void BitmapResourceToFile(int resourceId, CString dirToWriteTo)
{
  HRSRC resourceInfo;
  HGLOBAL loadedResourceHandle;
  HINSTANCE instanceHandle;
  BITMAPFILEHEADER bitmapFileHeader;
  LPBITMAPINFOHEADER bitmapInfo;
  UINT bitsPerPixel;
  UINT numberOfPixelBytes;
  UINT extra;
  CStdioFile file;

  instanceHandle = ::AfxGetInstanceHandle();
  resourceInfo = ::FindResource(instanceHandle,MAKEINTRESOURCE(resourceId),RT_BITMAP);
  loadedResourceHandle = ::LoadResource(instanceHandle,resourceInfo);
  bitmapInfo = (LPBITMAPINFOHEADER)::LockResource(loadedResourceHandle);
  numberOfPixelBytes = (lpBitmapInfo->biWidth * lpBitmapInfo->biBitCount)/8;
	
  extra = numberOfPixelBytes % 4;
  if(extra != 0 && extra != 4)
  {
    //Number of bytes is not in a multiple of 4
    numberOfPixelBytes += extra;
  }<br>

  numberOfPixelBytes *= bitmapInfo->biHeight;
  bitmapFileHeader.bfType = 0x4d42;
  bitsPerPixel = 1 << bitmapInfo->biBitCount;
  bitmapFileHeader.bfSize = (DWORD)(sizeof(bitmapFileHeader) + sizeof(bitmapInfo) + numberOfPixelBytes + bitsPerPixel);
  bitmapFileHeader.bfReserved1 = 0;
  bitmapFileHeader.bfReserved2 = 0;
  bitmapFileHeader.bfOffBits = sizeof(bitmapFileHeader) + sizeof(bitmapInfo);

  file.Open(resourceFileDir,CFile::modeCreate | CFile::modeWrite);
  file.Write(&bitmapFileHeader,sizeof(bitmapFileHeader));
  file.Close();
  file.Open(resourceFileDir,CFile::modeNoTruncate | CFile::modeWrite);
  file.Write(bitmapInfo,sizeof(bitmapInfo) + numberOfPixelBytes + bitsPerPixel);
  file.Close();
}


Every bmp file written to disk is not a valid bmp. What am I doing wrong? Is there a better (and correct) way of doing what I am trying to do? If no one knows an answer, are there any good resources on this subject? (MSDN has not been a good resource D'Oh! | :doh: )

Thanks for any help!

NOTE: I have left out all of my error checking in the above code to make it more readable. The code compiles and runs, it just does not produce valid bmps or pngs. And sorry about the code being squished together. The forum does not seem to want to preserve my line breaks...
AnswerRe: Extracting binary resources -- PNG and Bitmap Pin
Mark Salsbery6-Aug-07 9:52
Mark Salsbery6-Aug-07 9:52 
GeneralRe: Extracting binary resources -- PNG and Bitmap Pin
Torus_XL6-Aug-07 10:10
Torus_XL6-Aug-07 10:10 
GeneralRe: Extracting binary resources -- PNG and Bitmap Pin
Mark Salsbery6-Aug-07 13:28
Mark Salsbery6-Aug-07 13:28 
GeneralRe: Extracting binary resources -- PNG and Bitmap Pin
Torus_XL7-Aug-07 8:10
Torus_XL7-Aug-07 8:10 
AnswerRe: Extracting binary resources -- PNG and Bitmap Pin
Torus_XL6-Aug-07 11:04
Torus_XL6-Aug-07 11:04 
QuestionWin32: Writing a new line of text? [modified] Pin
deostroll6-Aug-07 9:33
deostroll6-Aug-07 9:33 
AnswerRe: Win32: Writing a new line of text? Pin
Wes Aday6-Aug-07 9:52
professionalWes Aday6-Aug-07 9:52 
GeneralRe: Win32: Writing a new line of text? Pin
Nemanja Trifunovic6-Aug-07 10:03
Nemanja Trifunovic6-Aug-07 10:03 
AnswerRe: Win32: Writing a new line of text? Pin
deostroll7-Aug-07 19:57
deostroll7-Aug-07 19:57 
QuestionCSocket stops receiving Pin
Trooper_IL6-Aug-07 8:54
Trooper_IL6-Aug-07 8:54 
AnswerRe: CSocket stops receiving Pin
led mike6-Aug-07 9:13
led mike6-Aug-07 9:13 
QuestionRe: CSocket stops receiving Pin
Mark Salsbery6-Aug-07 9:40
Mark Salsbery6-Aug-07 9:40 
AnswerRe: CSocket stops receiving Pin
Trooper_IL7-Aug-07 3:09
Trooper_IL7-Aug-07 3:09 
GeneralRe: CSocket stops receiving Pin
Mark Salsbery7-Aug-07 4:57
Mark Salsbery7-Aug-07 4:57 
GeneralRe: CSocket stops receiving Pin
JudyL_MD7-Aug-07 10:14
JudyL_MD7-Aug-07 10:14 
QuestionAdd text to title bar (or document header) Pin
AeJai6-Aug-07 8:09
AeJai6-Aug-07 8:09 
AnswerRe: Add text to title bar (or document header) Pin
Mark Salsbery6-Aug-07 8:11
Mark Salsbery6-Aug-07 8:11 

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.