Click here to Skip to main content
15,924,317 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Sleep() Pin
ThatsAlok26-Nov-08 19:31
ThatsAlok26-Nov-08 19:31 
AnswerRe: Sleep() Pin
CPallini26-Nov-08 21:08
mveCPallini26-Nov-08 21:08 
AnswerRe: Sleep() Pin
Jijo.Raj26-Nov-08 21:22
Jijo.Raj26-Nov-08 21:22 
QuestionSleep() blacken the screen Pin
220826-Nov-08 18:19
220826-Nov-08 18:19 
QuestionConvert lpbyte* to Hex String (Unicode) Pin
silentandromeda26-Nov-08 18:15
silentandromeda26-Nov-08 18:15 
AnswerRe: Convert lpbyte* to Hex String (Unicode) Pin
CPallini26-Nov-08 22:20
mveCPallini26-Nov-08 22:20 
GeneralRe: Convert lpbyte* to Hex String (Unicode) Pin
silentandromeda28-Nov-08 15:54
silentandromeda28-Nov-08 15:54 
QuestionHaving difficulty writing text on a bitmap Pin
JJeffrey26-Nov-08 16:19
JJeffrey26-Nov-08 16:19 
I am facing problems trying to write text onto a bitmap in the hopes of getting pixelated text on it.

I have looked at the code shown here: <ahref>http://www.codeproject.com/KB/GDI/gdionbitmaps.aspx[^]
but I can't seem to get it to work right.

Here's my code, I am using the code shown on the above site and triggering it to run on a button click form a dialog:
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;

	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);
	SelectObject(TmpDC,TmpObj2);
	DeleteDC(dcBmp);

	//choose the font
	CFont m_Font;
	LOGFONT* m_pLF;
	m_pLF=(LOGFONT*)calloc(1,sizeof(LOGFONT));
	strncpy(m_pLF->lfFaceName,"Times New Roman",31);
	m_pLF->lfHeight=64;
	m_pLF->lfWeight=400;
	m_pLF->lfItalic=0;
	m_pLF->lfUnderline=0;
	m_Font.CreateFontIndirect(m_pLF);

	//select the font in the dc
	CDC dc;
	dc.Attach(TmpDC);
	CFont* pOldFont=NULL;
	if (m_Font.m_hObject) 
		pOldFont = dc.SelectObject(&m_Font);
	else 
		dc.SelectObject(GetStockObject(DEFAULT_GUI_FONT));

	//Set text color
	dc.SetTextColor(RGB(0,0,0));		//Black Pen

	//Set text position;

	RECT pos = {40,40,0,0};

	//draw the text
	dc.SetBkMode(TRANSPARENT);

	dc.DrawText(strTxt,TxtLen,&pos,DT_CALCRECT);
	dc.DrawText(strTxt,TxtLen,&pos,0);

	m_Placemat.SetBitmap(TmpBmp);

	//cleanup 
	if (pOldFont) dc.SelectObject(pOldFont);
	m_Font.DeleteObject();
	dc.Detach();
	free(m_pLF);

	DeleteObject(hbitmap);
	hbitmap=TmpBmp;

	//final cleanup
	SelectObject(TmpDC,TmpObj);
	DeleteDC(TmpDC);
}

m_Placemat is a Bitmap object embedded on the dialog window. It is how I am displaying the bitmap on screen.

I can get the bitmap out, but there does not seem to be any change from the original, no text, no visible difference. I seem to be getting the code wrong somehow. Can anyone enlighten me?

I have already posted on the comments section of the page witht he code, but I was hoping for some opinions from someone fast.

I'm running this using VC 6.0, no GDI+ library. If this truely cannot be done on pre-.Net, please tell me

My final objective is to get a text string into pixels or a bit array. If you have a better solution to achieve this, please let me know too.

Thanks.
AnswerRe: Having difficulty writing text on a bitmap [modified] Pin
enhzflep26-Nov-08 17:26
enhzflep26-Nov-08 17:26 
GeneralRe: Having difficulty writing text on a bitmap Pin
JJeffrey26-Nov-08 19:35
JJeffrey26-Nov-08 19:35 
GeneralRe: Having difficulty writing text on a bitmap Pin
enhzflep26-Nov-08 19:48
enhzflep26-Nov-08 19:48 
GeneralRe: Having difficulty writing text on a bitmap Pin
JJeffrey26-Nov-08 20:52
JJeffrey26-Nov-08 20:52 
GeneralRe: Having difficulty writing text on a bitmap Pin
enhzflep26-Nov-08 21:04
enhzflep26-Nov-08 21:04 
GeneralRe: Having difficulty writing text on a bitmap Pin
JJeffrey26-Nov-08 21:37
JJeffrey26-Nov-08 21:37 
GeneralRe: Having difficulty writing text on a bitmap Pin
PJ Arends27-Nov-08 7:13
professionalPJ Arends27-Nov-08 7:13 
GeneralRe: Having difficulty writing text on a bitmap [modified] Pin
JJeffrey27-Nov-08 15:49
JJeffrey27-Nov-08 15:49 
QuestionCursor not changing [modified] Pin
Leslie Sanford26-Nov-08 9:00
Leslie Sanford26-Nov-08 9:00 
AnswerRe: Cursor not changing Pin
CPallini26-Nov-08 9:30
mveCPallini26-Nov-08 9:30 
GeneralRe: Cursor not changing Pin
Leslie Sanford26-Nov-08 10:06
Leslie Sanford26-Nov-08 10:06 
GeneralRe: Cursor not changing Pin
CPallini26-Nov-08 10:17
mveCPallini26-Nov-08 10:17 
Question<tag>/, source code questions</tag> Pin
ForNow26-Nov-08 6:26
ForNow26-Nov-08 6:26 
AnswerRe: /, source code questions Pin
Maximilien26-Nov-08 6:52
Maximilien26-Nov-08 6:52 
GeneralRe: /, source code questions Pin
jeron126-Nov-08 7:16
jeron126-Nov-08 7:16 
AnswerRe: /, source code questions Pin
CPallini26-Nov-08 7:13
mveCPallini26-Nov-08 7:13 
QuestionRe: /, source code questions Pin
led mike26-Nov-08 7:21
led mike26-Nov-08 7:21 

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.