Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem using static solidbrush in GDI+ [modified]

Problem using static solidbrush in GDI+ [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpc++winformsquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stick
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • S Stick

      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

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      >>the text will not draw due to the brush. Weird. How do you know this?? Mark

      S 1 Reply Last reply
      0
      • M Mark Salsbery

        >>the text will not draw due to the brush. Weird. How do you know this?? Mark

        S Offline
        S Offline
        Stick
        wrote on last edited by
        #3

        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.

        M 1 Reply Last reply
        0
        • S Stick

          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.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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));

          S 1 Reply Last reply
          0
          • M Mark Salsbery

            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));

            S Offline
            S Offline
            Stick
            wrote on last edited by
            #5

            Yes... My mistake... I was changing names to make things clear. the definition is at the top of the file outside of any functions.

            M 1 Reply Last reply
            0
            • S Stick

              Yes... My mistake... I was changing names to make things clear. the definition is at the top of the file outside of any functions.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Geez at least SetColor should have worked :) Beats me but I'll keep looking at it...I would expect it to work! Mark

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups