Thank you, Thank you... THANK. YOU! Your program is fantastic. I see where it went wrong now, the SelectObjects were causing the HDCs to overwrite with old images as they weren't done properly (I think...). I delayed it till later in the code. For the record, this code works:
void CCaptureAndDisplayDlg::OnTest()
{
HBITMAP hbitmap = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB\_BITMAP1));
BITMAP bitm;
GetObject( hbitmap, sizeof(BITMAP), &bitm );
long width=bitm.bmWidth;
long height=bitm.bmHeight;
BITMAPINFO bmInfo;
int rtn=0;
memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER));
bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biWidth=width;
bmInfo.bmiHeader.biHeight=height;
bmInfo.bmiHeader.biPlanes=1;
bmInfo.bmiHeader.biBitCount=24;
//create a temporary dc in memory.
HDC pDC = ::GetDC(0);
HDC TmpDC=CreateCompatibleDC(pDC);
//create a new bitmap and select it in the memory dc
BYTE \*pbase;
HBITMAP TmpBmp=CreateDIBSection(pDC, &bmInfo,DIB\_RGB\_COLORS,(void\*\*)&pbase,0,0);
HGDIOBJ TmpObj=SelectObject(TmpDC,TmpBmp);
//draw the background
HDC dcBmp=CreateCompatibleDC(TmpDC);
HGDIOBJ TmpObj2 = SelectObject(dcBmp,hbitmap);
BitBlt(TmpDC,0,0,width,height,dcBmp,0,0,SRCCOPY);
char \*myText = "Testing";
HFONT oldFnt, font1;
font1 = CreateFont(-13, 0, 0, 0, 400, FALSE, FALSE, FALSE, 1, 400, 0, 0, 0, "Tahoma Bold");
oldFnt = (HFONT)SelectObject(TmpDC, font1);
// print text at an arbitrary position
TextOut(TmpDC, 30, 30, myText, strlen(myText));
SelectObject(TmpDC,TmpObj2);
m\_Placemat.SetBitmap(TmpBmp);
SelectObject(TmpDC, oldFnt);
DeleteObject(oldFnt);
DeleteDC(TmpDC);
DeleteDC(dcBmp);
}
Great Program you have there.... Jeffrey
modified on Friday, November 28, 2008 1:40 AM