Problem using static solidbrush in GDI+ [modified]
-
If I setup a static variable like this: [CODE] // .h file class DisplayLine { static SolidBrush s_solidBrush; ... }; [/CODE] and initialize it like this: [CODE] // .cpp file SolidBrush DisplayLine::s_solidBrush(Color(255, 0, 255, 0)); [/CODE] and then in the draw() routine do this: [CODE] void DisplayLine::Draw(Graphics *pGraphics) { // Draw the text pGraphics->DrawString(buf, -1, &font_big, lineRect, &sFormat, &s_solidBrush); } [/CODE] that the text will not draw due to the brush. Weird. What am I doing wrong? Why is the brush not getting initialized? I even tried adding this: s_solidBrush.SetColor(Color(255, 0, 255, 0)); but that didn't help. -- modified at 18:51 Monday 9th October, 2006
-
If I setup a static variable like this: [CODE] // .h file class DisplayLine { static SolidBrush s_solidBrush; ... }; [/CODE] and initialize it like this: [CODE] // .cpp file SolidBrush DisplayLine::s_solidBrush(Color(255, 0, 255, 0)); [/CODE] and then in the draw() routine do this: [CODE] void DisplayLine::Draw(Graphics *pGraphics) { // Draw the text pGraphics->DrawString(buf, -1, &font_big, lineRect, &sFormat, &s_solidBrush); } [/CODE] that the text will not draw due to the brush. Weird. What am I doing wrong? Why is the brush not getting initialized? I even tried adding this: s_solidBrush.SetColor(Color(255, 0, 255, 0)); but that didn't help. -- modified at 18:51 Monday 9th October, 2006
>>the text will not draw due to the brush. Weird. How do you know this?? Mark
-
>>the text will not draw due to the brush. Weird. How do you know this?? Mark
Because if I creat a brush in the draw() method it works fine. This works: void DisplayLine::Draw(Graphics *pGraphics) { Font font_big(L"FIXEDSYS", 18, FontStyleBold, UnitPixel); Font font_small(L"FIXEDSYS", 12, FontStyleBold, UnitPixel); StringFormat sFormat = new StringFormat(); sFormat.SetAlignment(textAlign); sFormat.SetLineAlignment(lineAlign); SolidBrush a_solidBrush(Color(255, 0, 255, 0)); // Set text to display wchar_t buf[20+1] = { 0 }; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lineText.c_str(), (int)lineText.length(), buf, 20); // Draw the text pGraphics->DrawString(buf, -1, &font_big, lineRect, &sFormat, &a_solidBrush); } } Even if I make the s_solidbrush public, it still does not work.
-
Because if I creat a brush in the draw() method it works fine. This works: void DisplayLine::Draw(Graphics *pGraphics) { Font font_big(L"FIXEDSYS", 18, FontStyleBold, UnitPixel); Font font_small(L"FIXEDSYS", 12, FontStyleBold, UnitPixel); StringFormat sFormat = new StringFormat(); sFormat.SetAlignment(textAlign); sFormat.SetLineAlignment(lineAlign); SolidBrush a_solidBrush(Color(255, 0, 255, 0)); // Set text to display wchar_t buf[20+1] = { 0 }; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lineText.c_str(), (int)lineText.length(), buf, 20); // Draw the text pGraphics->DrawString(buf, -1, &font_big, lineRect, &sFormat, &a_solidBrush); } } Even if I make the s_solidbrush public, it still does not work.
is this... [CODE] // .h file class CduLine { static SolidBrush s_solidBrush; ... }; actually this? (what is the CduLine class?) [CODE] // .h file class DisplayLine { static SolidBrush s_solidBrush; ... }; In CPP file, outside of any function... SolidBrush DisplayLine::s_solidBrush(Color(255, 0, 255, 0));
-
is this... [CODE] // .h file class CduLine { static SolidBrush s_solidBrush; ... }; actually this? (what is the CduLine class?) [CODE] // .h file class DisplayLine { static SolidBrush s_solidBrush; ... }; In CPP file, outside of any function... SolidBrush DisplayLine::s_solidBrush(Color(255, 0, 255, 0));
-
Yes... My mistake... I was changing names to make things clear. the definition is at the top of the file outside of any functions.
Geez at least SetColor should have worked :) Beats me but I'll keep looking at it...I would expect it to work! Mark