Click here to Skip to main content
16,017,634 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: VC++ 6 -warpper Pin
Chris Losinger31-May-07 10:43
professionalChris Losinger31-May-07 10:43 
AnswerRe: VC++ 6 -warpper Pin
Hamid_RT31-May-07 18:27
Hamid_RT31-May-07 18:27 
Questionconverting from const char [] to 'LPWSTR' Pin
maizhiming31-May-07 9:28
maizhiming31-May-07 9:28 
AnswerRe: converting from const char [] to 'LPWSTR' Pin
Matthew Faithfull31-May-07 9:43
Matthew Faithfull31-May-07 9:43 
AnswerRe: converting from const char [] to 'LPWSTR' Pin
Xing Chen31-May-07 15:18
Xing Chen31-May-07 15:18 
QuestionGetDIBits() function call fails Pin
TheDelChop31-May-07 8:50
TheDelChop31-May-07 8:50 
AnswerRe: GetDIBits() function call fails Pin
John R. Shaw31-May-07 9:17
John R. Shaw31-May-07 9:17 
AnswerRe: GetDIBits() function call fails Pin
Mark Salsbery31-May-07 9:30
Mark Salsbery31-May-07 9:30 
I see a few problems -

TheDelChop wrote:
GetObject(hSavedXYBitmap,sizeof(BITMAP),(LPSTR)(&bmp));


Irrelevent, but cast to a LPSTR?? No cast to a void pointer is necessary Wink | ;)

Problems:
Creating a BITMAPINFO the size of a BITMAPINFOHEADER.
Using the planes value from the DDB when it HAS to be 1 in a DIB.
bmiHeader.biSizeImage is calculated wrong - rows of pixel data in a DIB need to be DWORD aligned.
You've provided no color table (16-colors) for your destination 4-bit DIB
The resulting GetDIBits call should fail based on the above.

Something like this maybe will get you closer:
...
int nNumColors = 1 << cClrBits;
 
LONG lBytesPerRow = (((bmp.bmWidth * (long)cClrBits + 31L) & (~31L)) / 8L);
 
BYTE* pBitmapBits;
 
LONG SizeOfBitmapInfo = sizeof(BITMAPINFO) + ((nNumColors - 1) * sizeof(RGBQUAD));
  
BITMAPINFO *pbmi = (PBITMAPINFO) LocalAlloc(LPTR, SizeOfBitmapInfo);
memset(pbmi, 0, SizeOfBitmapInfo);
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = bmp.bmWidth;
pbmi->bmiHeader.biHeight = bmp.bmHeight;
pbmi->bmiHeader.biPlanes = 1;
pbmi->bmiHeader.biBitCount = cClrBits;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = lBytesPerRow * bmp.bmHeight;
//pbmi->bmiHeader.biXPelsPerMeter = 0;
//pbmi->bmiHeader.biYPelsPerMeter = 0;
//pbmi->bmiHeader.biClrUsed = 0;
//pbmi->bmiHeader.biClrImportant = 0;
 
// I forget if you need to do this before GetDIBits() :doh:
//// Initialize color table
//for (int i = 0; i < nNumColors; i++)
//{
//   pbmi->bmiColors[i].rgbBlue = ; 
//   pbmi->bmiColors[i].rgbGreen = ; 
//   pbmi->bmiColors[i].rgbRed = ; 
//   pbmi->bmiColors[i].rgbReserved = 0; 
//}
 
pBitmapInfoHeader = (PBITMAPINFOHEADER)pbmi;
 
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED,pbmi->bmiHeader.biSizeImage);
 
test = ::GetDIBits(hdc, hSavedXYBitmap, 0, (WORD) pbmi->bmiHeader.biHeight, lpBits, pbmi, DIB_RGB_COLORS);
if (test == 0)
   test = GetLastError();







"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

QuestionNewbie Question Pin
joshp121731-May-07 8:45
joshp121731-May-07 8:45 
AnswerRe: Newbie Question Pin
David Crow31-May-07 10:31
David Crow31-May-07 10:31 
AnswerRe: Newbie Question Pin
Matthew Faithfull31-May-07 11:10
Matthew Faithfull31-May-07 11:10 
GeneralRe: Newbie Question Pin
joshp121731-May-07 11:15
joshp121731-May-07 11:15 
GeneralRe: Newbie Question Pin
Matthew Faithfull31-May-07 11:37
Matthew Faithfull31-May-07 11:37 
Question64 bit XP Pin
Monty231-May-07 7:40
Monty231-May-07 7:40 
AnswerSolution for those interested Pin
Monty231-May-07 22:41
Monty231-May-07 22:41 
GeneralRe: Solution for those interested Pin
Mark Salsbery1-Jun-07 6:22
Mark Salsbery1-Jun-07 6:22 
QuestionRegistry vs .Ini files. Pin
Anurag Gandhi31-May-07 7:37
professionalAnurag Gandhi31-May-07 7:37 
AnswerRe: Registry vs .Ini files. Pin
David Crow31-May-07 7:57
David Crow31-May-07 7:57 
GeneralRe: Registry vs .Ini files. Pin
Anurag Gandhi31-May-07 8:00
professionalAnurag Gandhi31-May-07 8:00 
QuestionRe: Registry vs .Ini files. Pin
David Crow31-May-07 8:15
David Crow31-May-07 8:15 
AnswerRe: Registry vs .Ini files. Pin
Anurag Gandhi31-May-07 8:17
professionalAnurag Gandhi31-May-07 8:17 
GeneralRe: Registry vs .Ini files. Pin
Maximilien31-May-07 8:45
Maximilien31-May-07 8:45 
GeneralRe: Registry vs .Ini files. Pin
David Crow31-May-07 8:45
David Crow31-May-07 8:45 
GeneralRe: Registry vs .Ini files. Pin
Matthew Faithfull31-May-07 8:25
Matthew Faithfull31-May-07 8:25 
GeneralRe: Registry vs .Ini files. Pin
Anurag Gandhi31-May-07 8:35
professionalAnurag Gandhi31-May-07 8:35 

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.