Click here to Skip to main content
15,894,291 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: The best way to use worker thread to connect to an database Pin
David Crow19-Nov-10 4:13
David Crow19-Nov-10 4:13 
GeneralRe: The best way to use worker thread to connect to an database Pin
mesajflaviu19-Nov-10 6:44
mesajflaviu19-Nov-10 6:44 
GeneralRe: The best way to use worker thread to connect to an database Pin
David Crow19-Nov-10 7:43
David Crow19-Nov-10 7:43 
GeneralRe: The best way to use worker thread to connect to an database Pin
mesajflaviu19-Nov-10 8:23
mesajflaviu19-Nov-10 8:23 
QuestionSorting CListCtrl with group view enabled Pin
Paul201319-Nov-10 1:20
Paul201319-Nov-10 1:20 
AnswerRe: Sorting CListCtrl with group view enabled Pin
Richard MacCutchan19-Nov-10 2:53
mveRichard MacCutchan19-Nov-10 2:53 
GeneralRe: Sorting CListCtrl with group view enabled Pin
Paul201319-Nov-10 3:47
Paul201319-Nov-10 3:47 
QuestionCreate compatible bitmap Pin
MacCPlus19-Nov-10 0:57
MacCPlus19-Nov-10 0:57 
Hi,

I can't seem to properly create a compatible bitmap in my MFC application. I'm trying to StretchBlt a byte buffer (with 8-bit greyscale pixel information) to a DC, but the only way to get it done is by taking a rather unconventional detour. Here's what I do:

HBITMAP hBmp = (HBITMAP)::LoadImage(NULL, "bitmap.bmp", IMAGE_BITMAP,
    0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

CBitmap cBmp;
cBmp.Attach(hBmp);
cBmp.SetBitmapBits(m_width*m_height, datap);

CDC dcMem;
dcMem.CreateCompatibleDC(dc);
HBITMAP BitmapOld = (HBITMAP)SelectObject(dcMem, cBmp);
dc->StretchBlt(xOffset, yOffset, m_width*rectSizeX, m_height*rectSizeY, &dcMem, 0, 0, m_width, m_height, SRCCOPY);
dcMem.SelectObject(BitmapOld);
dcMem.DeleteDC();

The file bitmap.bmp contains an uncompressed 8-bit greyscale image with exactly the same dimension of m_width*m_height. So far only by loading this one file first, attaching it to CBitmap cBmp and then calling SetBitmapBits with the pointer to my own byte buffer (datap), thus overwriting the bitmap information from the file, I can create a compatible bitmap out of my byte buffer that I can blit into the window. If I go like this

BITMAPINFO *lpInfo = new BITMAPINFO;
lpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lpInfo->bmiHeader.biWidth = m_width;
lpInfo->bmiHeader.biHeight = m_height;
lpInfo->bmiHeader.biPlanes = 1;
lpInfo->bmiHeader.biBitCount = 8;
lpInfo->bmiHeader.biCompression = BI_RGB;
lpInfo->bmiHeader.biSizeImage = m_width*m_height;
lpInfo->bmiHeader.biClrUsed = 0;

HBITMAP hBmp = (HBITMAP)::CreateDIBSection(0, lpInfo, DIB_RGB_COLORS, 0, 0, 0x0);


... and then do the rest mentioned above (Attach(), CreateCompatibleDC(), SelectObject(), StretchBlt() etc.), I see only a greenish version of the image I want to blit (but in right aspect ratio, stride, dimension etc.), and it keeps appearing and disappearing with a blurry spot all the time.

What am I doing wrong?

Mac
AnswerRe: Create compatible bitmap [modified] Pin
CPallini19-Nov-10 1:41
mveCPallini19-Nov-10 1:41 
GeneralRe: Create compatible bitmap Pin
MacCPlus19-Nov-10 2:26
MacCPlus19-Nov-10 2:26 
GeneralRe: Create compatible bitmap [fixed] Pin
CPallini19-Nov-10 3:03
mveCPallini19-Nov-10 3:03 
GeneralRe: Create compatible bitmap Pin
MacCPlus19-Nov-10 4:30
MacCPlus19-Nov-10 4:30 
GeneralRe: Create compatible bitmap Pin
CPallini19-Nov-10 6:34
mveCPallini19-Nov-10 6:34 
GeneralRe: Create compatible bitmap Pin
MacCPlus21-Nov-10 21:55
MacCPlus21-Nov-10 21:55 
GeneralRe: Create compatible bitmap Pin
CPallini21-Nov-10 22:06
mveCPallini21-Nov-10 22:06 
GeneralRe: Create compatible bitmap Pin
MacCPlus22-Nov-10 0:49
MacCPlus22-Nov-10 0:49 
GeneralRe: Create compatible bitmap Pin
CPallini22-Nov-10 1:55
mveCPallini22-Nov-10 1:55 
GeneralRe: Create compatible bitmap Pin
MacCPlus23-Nov-10 1:43
MacCPlus23-Nov-10 1:43 
GeneralRe: Create compatible bitmap Pin
CPallini23-Nov-10 1:52
mveCPallini23-Nov-10 1:52 
GeneralRe: Create compatible bitmap Pin
MacCPlus23-Nov-10 2:25
MacCPlus23-Nov-10 2:25 
QuestionAutomation tool for MFC Dialog based applications Pin
kapardhi18-Nov-10 19:37
kapardhi18-Nov-10 19:37 
AnswerRe: Automation tool for MFC Dialog based applications Pin
David Crow19-Nov-10 4:15
David Crow19-Nov-10 4:15 
QuestionHow to Load Tiff File using LoadImage? Pin
002comp18-Nov-10 18:03
002comp18-Nov-10 18:03 
AnswerRe: How to Load Tiff File using LoadImage? Pin
Luc Pattyn18-Nov-10 18:42
sitebuilderLuc Pattyn18-Nov-10 18:42 
GeneralRe: How to Load Tiff File using LoadImage? Pin
CPallini19-Nov-10 0:59
mveCPallini19-Nov-10 0:59 

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.