Click here to Skip to main content
15,886,199 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
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 
Thanks for the quick reply. I appreciate it.

I have put your function as such:

void DrawOnBitmap(HBITMAP hBmp)
{    
    HFONT oldFnt, font1;
    HDC memDC;
    HBITMAP oldBM;    
	// some arbitrary junk text
    char *myText = "Testing";  
	
	// create a mem dc
    memDC = CreateCompatibleDC(NULL);    
	
	// select bitmap into it
    oldBM = (HBITMAP)SelectObject(memDC, hBmp);    

	
	//create the font
    font1 = CreateFont(-13, 0, 0, 0, 400, FALSE, FALSE, FALSE, 1, 400, 0, 0, 0, "Tahoma Bold");
    oldFnt = (HFONT)SelectObject(memDC, font1);        
	
	// print text at an arbitrary position
    TextOut(memDC, 30, 30, myText, strlen(myText));

    m_Placemat.SetBitmap(oldBM);   //Output Bitmap into Dialog Box CStatic object

	// clean-up time!
    SelectObject(memDC, oldBM);
    SelectObject(memDC, oldFnt);
    DeleteObject(oldBM);
    DeleteObject(oldFnt);
    DeleteDC(memDC);
}

void OnTest() 
{
	HBITMAP hbitmap = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP3));
        DrawOnBitmap(hbitmap);
}


What I get back is a black BMP.

The point when
oldBM = (HBITMAP)SelectObject(memDC, hBmp);
was executed, the BMP turned entirely black (when i tried to output at that point). I think when the CreateCompatibleDC is executed with a null, there creates a problem. I tried passing in the DC I used previously but it doesn't make a difference.

When I run
m_Placemat.SetBitmap(hBmp);
instead, I get a black box with a smaller grey box in the centre.


I have tried integrating your Font section into mine:
void CCaptureAndDisplayDlg::OnTest() 
{

	HBITMAP hbitmap = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP3));

	BITMAP bitm;
	GetObject( hbitmap, sizeof(BITMAP), &bitm );
	long width=bitm.bmWidth;
	long height=bitm.bmHeight;
	BITMAPINFO bmInfo;
	CBitmap	FinalBMP;
	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);
	SelectObject(TmpDC,TmpObj2);
	DeleteDC(dcBmp);

// Insert Font and Write code here
	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, 330, 230, myText, strlen(myText));

	m_Placemat.SetBitmap(TmpBmp);


        SelectObject(TmpDC, oldFnt);
        DeleteObject(oldFnt);
        DeleteDC(TmpDC);
}


This way I get my BMP displayed, but still no text.

This has to be my understanding of the whole workings of this BMP thing going wonky because i don't know why it doesn't work on my system.

Am I doing this all wrong?
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 
AnswerRe: /, source code questions Pin
CPallini26-Nov-08 7:46
mveCPallini26-Nov-08 7:46 
Questionhook for Outlook Express 6 Pin
Dr. Kelwin26-Nov-08 5:33
Dr. Kelwin26-Nov-08 5:33 

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.