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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC set Control color question [Solved]

MFC set Control color question [Solved]

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++databasequestion
4 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.
  • E Offline
    E Offline
    econy
    wrote on last edited by
    #1

    Hi, I want to change a control's color, for example, static text. logic like:

    if test == 0 then
    static text color = Red
    else
    static text color = Green
    endif

    first I try to do it in OnCtlColor() function, in timer function, I declared a global variable.

    BOOL test = 0;
    OnTimer() {
    test ^= 1;
    }

    OnCtlColor() {
    if (test == 0 ) {
    pDC->SetTextColor(RGB(0,100,0));
    }
    else {
    pDC->SetTextColor(RGB(255,0,0));
    //pDC->SetBkMode(TRANSPARENT);
    }
    }

    But, the color always be green, not swap.
    I knew OnCtlColor need to be trigger with invalidate().

    but I don't know how to invalidate a control, not affect it's parent window.

    CPalliniC 1 Reply Last reply
    0
    • E econy

      Hi, I want to change a control's color, for example, static text. logic like:

      if test == 0 then
      static text color = Red
      else
      static text color = Green
      endif

      first I try to do it in OnCtlColor() function, in timer function, I declared a global variable.

      BOOL test = 0;
      OnTimer() {
      test ^= 1;
      }

      OnCtlColor() {
      if (test == 0 ) {
      pDC->SetTextColor(RGB(0,100,0));
      }
      else {
      pDC->SetTextColor(RGB(255,0,0));
      //pDC->SetBkMode(TRANSPARENT);
      }
      }

      But, the color always be green, not swap.
      I knew OnCtlColor need to be trigger with invalidate().

      but I don't know how to invalidate a control, not affect it's parent window.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      You could try to call CStatic's Invalidate and UpdateWindow methods.

      Veni, vidi, vici.

      In testa che avete, signor di Ceprano?

      E 1 Reply Last reply
      0
      • CPalliniC CPallini

        You could try to call CStatic's Invalidate and UpdateWindow methods.

        Veni, vidi, vici.

        E Offline
        E Offline
        econy
        wrote on last edited by
        #3

        Thanks

        CPalliniC 1 Reply Last reply
        0
        • E econy

          Thanks

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          You are welcome.

          Veni, vidi, vici.

          In testa che avete, signor di Ceprano?

          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