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

C / C++ / MFC

 
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 
GeneralRe: Calling GDI+ DrawImage function throws _BLOCK_TYPE_IS_VALID error Pin
Jochen Arndt21-Sep-15 23:14
professionalJochen Arndt21-Sep-15 23:14 
QuestionShift + VK_LEFT Pin
_Flaviu20-Sep-15 22:44
Member_Flaviu20-Sep-15 22:44 
AnswerRe: Shift + VK_LEFT Pin
Jochen Arndt20-Sep-15 23:19
professionalJochen Arndt20-Sep-15 23:19 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu20-Sep-15 23:24
Member_Flaviu20-Sep-15 23:24 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu20-Sep-15 23:39
Member_Flaviu20-Sep-15 23:39 
GeneralRe: Shift + VK_LEFT Pin
Jochen Arndt20-Sep-15 23:51
professionalJochen Arndt20-Sep-15 23:51 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu21-Sep-15 0:04
Member_Flaviu21-Sep-15 0:04 
GeneralRe: Shift + VK_LEFT Pin
Jochen Arndt21-Sep-15 0:14
professionalJochen Arndt21-Sep-15 0:14 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu21-Sep-15 0:14
Member_Flaviu21-Sep-15 0:14 
GeneralRe: Shift + VK_LEFT Pin
Jochen Arndt21-Sep-15 0:21
professionalJochen Arndt21-Sep-15 0:21 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu21-Sep-15 0:23
Member_Flaviu21-Sep-15 0:23 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu21-Sep-15 23:13
Member_Flaviu21-Sep-15 23:13 
AnswerRe: Shift + VK_LEFT Pin
Richard MacCutchan20-Sep-15 23:32
mveRichard MacCutchan20-Sep-15 23:32 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu20-Sep-15 23:53
Member_Flaviu20-Sep-15 23:53 

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.