Click here to Skip to main content
14,693,741 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
Questionc programm Pin
Honey1724-Sep-15 10:08
MemberHoney1724-Sep-15 10:08 
AnswerRe: c programm Pin
k505424-Sep-15 10:26
mvek505424-Sep-15 10:26 
AnswerRe: c programm Pin
CPallini24-Sep-15 10:57
mveCPallini24-Sep-15 10:57 
GeneralRe: c programm Pin
Maximilien24-Sep-15 11:17
MemberMaximilien24-Sep-15 11:17 
QuestionFunction parameter question Pin
econy23-Sep-15 8:42
Memberecony23-Sep-15 8:42 
AnswerRe: Function parameter question Pin
David Crow23-Sep-15 8:58
MemberDavid Crow23-Sep-15 8:58 
GeneralRe: Function parameter question Pin
Richard Andrew x6423-Sep-15 12:48
professionalRichard Andrew x6423-Sep-15 12:48 
GeneralRe: Function parameter question Pin
David Crow23-Sep-15 17:59
MemberDavid Crow23-Sep-15 17:59 
GeneralRe: Function parameter question Pin
Richard MacCutchan23-Sep-15 22:38
mveRichard MacCutchan23-Sep-15 22:38 
AnswerRe: Function parameter question Pin
CPallini24-Sep-15 1:57
mveCPallini24-Sep-15 1:57 
Questionhelp Pin
robsons200722-Sep-15 17:17
Memberrobsons200722-Sep-15 17:17 
AnswerRe: help Pin
Richard Andrew x6422-Sep-15 19:15
professionalRichard Andrew x6422-Sep-15 19:15 
GeneralRe: help Pin
robsons200723-Sep-15 4:41
Memberrobsons200723-Sep-15 4:41 
SuggestionRe: help Pin
Richard MacCutchan22-Sep-15 22:04
mveRichard MacCutchan22-Sep-15 22:04 
QuestionCreating a thread in c Pin
mmapulac22-Sep-15 16:46
Membermmapulac22-Sep-15 16:46 
AnswerRe: Creating a thread in c Pin
Richard MacCutchan22-Sep-15 22:00
mveRichard MacCutchan22-Sep-15 22:00 
AnswerRe: Creating a thread in c Pin
David Crow23-Sep-15 3:34
MemberDavid Crow23-Sep-15 3:34 
Questionthe drag of listview column don't work Pin
ProCodix21-Sep-15 15:59
MemberProCodix21-Sep-15 15:59 
AnswerRe: the drag of listview column don't work Pin
_Flaviu21-Sep-15 21:50
Member_Flaviu21-Sep-15 21:50 
QuestionHaving trouble with c++ templates Pin
BobInNJ21-Sep-15 13:48
MemberBobInNJ21-Sep-15 13:48 
AnswerRe: Having trouble with c++ templates Pin
CPallini21-Sep-15 22:45
mveCPallini21-Sep-15 22:45 
QuestionCalling GDI+ DrawImage function throws _BLOCK_TYPE_IS_VALID error Pin
Kiran Satish21-Sep-15 8:39
MemberKiran Satish21-Sep-15 8:39 
I am trying to use GDI+ within my MFC dialog based application with multiple child dialogs. On one of the child dialogs, I am trying to draw an image from an array of 8 bit BYTE pixel data. Here is how my flow process is for this-

Variables declared in my child dialog's header file.
LONG	DIBSecWidth;
LONG	DIBSecHeight;
LONG	BitsPerPixel;
LONG        Stride;
BITMAPINFO* bmi;
BYTE*       pDIBSectionBits;
HBITMAP     hbm;
Graphics*   imagedisp;
Bitmap*     offscreenBitmap;
RECT        m_imagedisp_rect;
BOOL        m_BUpdate;

Then in my OnInitDialog() function, I do the following
DIBSecWidth = 512;
DIBSecHeight = 512;
BitsPerPixel = 8;

Stride = ((DIBSecWidth* BitsPerPixel + 31L) & (~31L)) / 8L;	
	
bmi = (BITMAPINFO *)new BYTE[sizeof(BITMAPINFO) + UCHAR_MAX * sizeof(RGBQUAD)];
bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi->bmiHeader.biWidth = DIBSecWidth;
bmi->bmiHeader.biHeight = DIBSecHeight;
bmi->bmiHeader.biPlanes = 1;
bmi->bmiHeader.biBitCount = (WORD)BitsPerPixel;
bmi->bmiHeader.biCompression = BI_RGB;
bmi->bmiHeader.biSizeImage = 0;
bmi->bmiHeader.biXPelsPerMeter = 0;
bmi->bmiHeader.biYPelsPerMeter = 0;
bmi->bmiHeader.biClrUsed = 0;
bmi->bmiHeader.biClrImportant = 0;
memcpy(bmi->bmiColors, summercmap, 256*sizeof(RGBQUAD)); //summercmap is a color table of 256 RGB (COLORREF) values
	
hbm = ::CreateDIBSection(NULL, bmi, DIB_RGB_COLORS, (void**)&pDIBSectionBits, NULL, 0);
	
offscreenBitmap = new Bitmap(bmi, pDIBSectionBits);
ImageDisplay.GetClientRect(&m_imagedisp_rect);
imagedisp = new Graphics(ImageDisplay.GetDC()->GetSafeHdc());
m_BUpdate = true;

and in OnPaint() message handler I have the following
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
if (m_BUpdate)
{
BYTE *pCurRowPixel = (BYTE *)(pDIBSectionBits);
memcpy(pCurRowPixel, m_pImgBuffPrc, DIBSecWidth*DIBSecHeight);
imagedisp->DrawImage(offscreenBitmap, 0, 0, DIBSecWidth, DIBSecWidth);
m_BUpdate = false;
delete pCurRowPixel;
}

Whenever I run my application, it throws an error at imagedisplay->DrawImage function, if I comment it out it doesn't throw the error. I am sure there is something simple that I am missing here or the way I am trying to draw is not right, any ideas/suggestions?
thanks
PKNT


modified 21-Sep-15 13:49pm.

AnswerRe: Calling GDI+ DrawImage function throws _BLOCK_TYPE_IS_VALID error Pin
CPallini21-Sep-15 22:50
mveCPallini21-Sep-15 22:50 
GeneralRe: Calling GDI+ DrawImage function throws _BLOCK_TYPE_IS_VALID error Pin
Jochen Arndt21-Sep-15 22:54
professionalJochen Arndt21-Sep-15 22:54 
GeneralRe: Calling GDI+ DrawImage function throws _BLOCK_TYPE_IS_VALID error Pin
CPallini21-Sep-15 23:01
mveCPallini21-Sep-15 23: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.