Click here to Skip to main content
15,881,803 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCreating a thread in c Pin
mmapulac22-Sep-15 15:46
mmapulac22-Sep-15 15:46 
AnswerRe: Creating a thread in c Pin
Richard MacCutchan22-Sep-15 21:00
mveRichard MacCutchan22-Sep-15 21:00 
AnswerRe: Creating a thread in c Pin
David Crow23-Sep-15 2:34
David Crow23-Sep-15 2:34 
Questionthe drag of listview column don't work Pin
ProCodix21-Sep-15 14:59
ProCodix21-Sep-15 14:59 
AnswerRe: the drag of listview column don't work Pin
_Flaviu21-Sep-15 20:50
_Flaviu21-Sep-15 20:50 
QuestionHaving trouble with c++ templates Pin
BobInNJ21-Sep-15 12:48
BobInNJ21-Sep-15 12:48 
AnswerRe: Having trouble with c++ templates Pin
CPallini21-Sep-15 21:45
mveCPallini21-Sep-15 21:45 
QuestionCalling GDI+ DrawImage function throws _BLOCK_TYPE_IS_VALID error Pin
Kiran Satish21-Sep-15 7:39
Kiran Satish21-Sep-15 7: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.
CSS
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
CSS
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
CSS
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 21:50
mveCPallini21-Sep-15 21:50 
GeneralRe: Calling GDI+ DrawImage function throws _BLOCK_TYPE_IS_VALID error Pin
Jochen Arndt21-Sep-15 21:54
professionalJochen Arndt21-Sep-15 21:54 
GeneralRe: Calling GDI+ DrawImage function throws _BLOCK_TYPE_IS_VALID error Pin
CPallini21-Sep-15 22:01
mveCPallini21-Sep-15 22:01 
GeneralRe: Calling GDI+ DrawImage function throws _BLOCK_TYPE_IS_VALID error Pin
Jochen Arndt21-Sep-15 22:14
professionalJochen Arndt21-Sep-15 22:14 
QuestionShift + VK_LEFT Pin
_Flaviu20-Sep-15 21:44
_Flaviu20-Sep-15 21:44 
AnswerRe: Shift + VK_LEFT Pin
Jochen Arndt20-Sep-15 22:19
professionalJochen Arndt20-Sep-15 22:19 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu20-Sep-15 22:24
_Flaviu20-Sep-15 22:24 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu20-Sep-15 22:39
_Flaviu20-Sep-15 22:39 
GeneralRe: Shift + VK_LEFT Pin
Jochen Arndt20-Sep-15 22:51
professionalJochen Arndt20-Sep-15 22:51 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu20-Sep-15 23:04
_Flaviu20-Sep-15 23:04 
GeneralRe: Shift + VK_LEFT Pin
Jochen Arndt20-Sep-15 23:14
professionalJochen Arndt20-Sep-15 23:14 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu20-Sep-15 23:14
_Flaviu20-Sep-15 23:14 
GeneralRe: Shift + VK_LEFT Pin
Jochen Arndt20-Sep-15 23:21
professionalJochen Arndt20-Sep-15 23:21 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu20-Sep-15 23:23
_Flaviu20-Sep-15 23:23 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu21-Sep-15 22:13
_Flaviu21-Sep-15 22:13 
AnswerRe: Shift + VK_LEFT Pin
Richard MacCutchan20-Sep-15 22:32
mveRichard MacCutchan20-Sep-15 22:32 
GeneralRe: Shift + VK_LEFT Pin
_Flaviu20-Sep-15 22:53
_Flaviu20-Sep-15 22: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.