Click here to Skip to main content
15,887,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Can't select HBRUSH into device context Pin
Jochen Arndt11-Sep-12 6:04
professionalJochen Arndt11-Sep-12 6:04 
GeneralRe: Can't select HBRUSH into device context Pin
Alan Balkany11-Sep-12 6:10
Alan Balkany11-Sep-12 6:10 
GeneralRe: Can't select HBRUSH into device context Pin
Jochen Arndt11-Sep-12 7:07
professionalJochen Arndt11-Sep-12 7:07 
GeneralRe: Can't select HBRUSH into device context Pin
Alan Balkany11-Sep-12 7:08
Alan Balkany11-Sep-12 7:08 
AnswerRe: Can't select HBRUSH into device context Pin
enhzflep11-Sep-12 10:20
enhzflep11-Sep-12 10:20 
GeneralRe: Can't select HBRUSH into device context Pin
Alan Balkany11-Sep-12 10:23
Alan Balkany11-Sep-12 10:23 
GeneralRe: Can't select HBRUSH into device context Pin
enhzflep11-Sep-12 10:30
enhzflep11-Sep-12 10:30 
GeneralRe: Can't select HBRUSH into device context Pin
Alan Balkany13-Sep-12 10:47
Alan Balkany13-Sep-12 10:47 
Hi enhzflep,

I incorporated code from your example into my function, and it works with the CreateHatchBrush call to create a new brush.

Unfortunately, when I substitute my already-created brush, it doesn't work; I just get solid white filling the text outlines.

I've verified the brush handle is the same as the nativeBrush member of my .NET Brush, which draws correctly both before and after. Can you see anything I'm doing wrong?

C++
DLLEXPORT void drawWithGdiFont (HBITMAP hBitmap, HBRUSH hbrush, LPCWSTR fontName,
	LPCWSTR text, int sizeToUse, bool bold, bool italic, int br, int bg, int bb)
{
	HDC hDc = CreateCompatibleDC (NULL);
	HGDIOBJ oldObj = SelectObject (hDc, hBitmap);
	SIZE size ;

	LOGFONT logFont;
	::ZeroMemory(& logFont, sizeof(LOGFONT));
	wcscpy ((&logFont)->lfFaceName, fontName);
	logFont.lfHeight = sizeToUse;

	if (bold)
		logFont.lfWeight = 800;
	else
		logFont.lfWeight = 500;

	logFont.lfItalic = italic;

	HFONT hFont = CreateFontIndirect(& logFont);
	HFONT oldFont = (HFONT) SelectObject (hDc, hFont);

	SetBkMode (hDc, TRANSPARENT) ;
 
	BeginPath (hDc) ;
	TextOut (hDc, 0, 0, fontName, wcslen (fontName));
	EndPath (hDc) ;
 

//  MY BRUSH FROM .NET (DOESN'T WORK):
		HBRUSH oldBrush = (HBRUSH) SelectObject (hDc, hbrush);

//  FROM EXAMPLE (WORKS): HBRUSH oldBrush = (HBRUSH) SelectObject (hDc, CreateHatchBrush (HS_DIAGCROSS, RGB (255, 0, 0))) ;


	SetBkColor (hDc, RGB (br, bg, bb));
	SetBkMode (hDc, OPAQUE) ;
 
	StrokeAndFillPath (hDc) ;

	DeleteObject (SelectObject (hDc, oldFont));
	SelectObject (hDc, oldBrush);
	DeleteObject (hDc);
}


Also, it seems like the background color here is the second color of the hatch pattern. But how do I set the color between the letters (which is also called the "background color"?)

Thanks!
Alan
"Microsoft -- Adding unnecessary complexity to your work since 1987!"

QuestionFile download help Pin
Sunil P V10-Sep-12 1:04
Sunil P V10-Sep-12 1:04 
QuestionRe: File download help Pin
David Crow10-Sep-12 2:38
David Crow10-Sep-12 2:38 
AnswerRe: File download help Pin
Sunil P V10-Sep-12 19:04
Sunil P V10-Sep-12 19:04 
GeneralRe: File download help Pin
_Flaviu10-Sep-12 21:01
_Flaviu10-Sep-12 21:01 
QuestionRe: File download help Pin
David Crow11-Sep-12 3:06
David Crow11-Sep-12 3:06 
QuestionHow to set Image' Document Size ? Pin
002comp9-Sep-12 22:18
002comp9-Sep-12 22:18 
AnswerRe: How to set Image' Document Size ? Pin
pasztorpisti9-Sep-12 23:10
pasztorpisti9-Sep-12 23:10 
GeneralRe: How to set Image' Document Size ? Pin
002comp9-Sep-12 23:32
002comp9-Sep-12 23:32 
GeneralRe: How to set Image' Document Size ? Pin
Chris Losinger10-Sep-12 1:11
professionalChris Losinger10-Sep-12 1:11 
QuestionHighlighting some text in CEdit Pin
Hadi Dayvary9-Sep-12 21:57
professionalHadi Dayvary9-Sep-12 21:57 
AnswerRe: Highlighting some text in CEdit Pin
_Flaviu10-Sep-12 19:31
_Flaviu10-Sep-12 19:31 
GeneralRe: Highlighting some text in CEdit Pin
Hadi Dayvary10-Sep-12 22:33
professionalHadi Dayvary10-Sep-12 22:33 
QuestionNON-SCALAR TYPE CONVERSION!? Pin
Jorgmen9-Sep-12 8:58
Jorgmen9-Sep-12 8:58 
AnswerRe: NON-SCALAR TYPE CONVERSION!? Pin
enhzflep9-Sep-12 9:40
enhzflep9-Sep-12 9:40 
AnswerRe: NON-SCALAR TYPE CONVERSION!? Pin
pasztorpisti9-Sep-12 9:52
pasztorpisti9-Sep-12 9:52 
AnswerRe: NON-SCALAR TYPE CONVERSION!? Pin
Jorgmen9-Sep-12 10:52
Jorgmen9-Sep-12 10:52 
GeneralRe: NON-SCALAR TYPE CONVERSION!? Pin
enhzflep9-Sep-12 12:33
enhzflep9-Sep-12 12: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.