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. color new

color new

Scheduled Pinned Locked Moved C / C++ / MFC
questioncom
2 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
    sidkraft
    wrote on last edited by
    #1

    I am trying to create a color fill that will change relative to a new value being input from the "OnHScroll" function. When I input a new value for the red color variable in the RGB function and re-display, the color never changes to the new value. See code segment below. How do I change? ... ... int a=0,b=190,c=230,x; CMainFrame::CMainFrame() { //Set color frame colorbar.CreateSolidBrush(RGB (a, b, c)); }; void CMainFrame::OnPaint() { CPaintDC dc(this); dc.TextOut (5,40,"Red Color Is:"); //Output color frame colorbar.DeleteObject(); colorbar.CreateSolidBrush(RGB(a,b,c)); dc.SelectObject(colorbar); CRect rc(100,150,150,200); dc.Rectangle (&rc); } void CMainFrame::OnHScroll(UINT nSBCode, UINT nPos, CWnd* pCtrl) { //Convert pointer to slider pointer CSliderCtrl *pSld; pSld = (CSliderCtrl*)pCtrl; //Get new position x = pSld->GetPos(); a = x; CString s; s.Format("%d",x); //Output value for red stcred.SetWindowText(s); } Note that: 1.) Initialize the colorbar to have values RGB(a,b,c) 2.) Variable "a" read in from the "OnHScroll" function and set to a new value. 3.) "OnPaint" deletes the old colorbar and re-creates with new "a" variable value, should display as output with the new color but doesn't, still displays as original a,b,c values. Please advise, Sid kraft sid_kraft@msn.com Thanks in advance, Sid Kraft. Sid

    L 1 Reply Last reply
    0
    • S sidkraft

      I am trying to create a color fill that will change relative to a new value being input from the "OnHScroll" function. When I input a new value for the red color variable in the RGB function and re-display, the color never changes to the new value. See code segment below. How do I change? ... ... int a=0,b=190,c=230,x; CMainFrame::CMainFrame() { //Set color frame colorbar.CreateSolidBrush(RGB (a, b, c)); }; void CMainFrame::OnPaint() { CPaintDC dc(this); dc.TextOut (5,40,"Red Color Is:"); //Output color frame colorbar.DeleteObject(); colorbar.CreateSolidBrush(RGB(a,b,c)); dc.SelectObject(colorbar); CRect rc(100,150,150,200); dc.Rectangle (&rc); } void CMainFrame::OnHScroll(UINT nSBCode, UINT nPos, CWnd* pCtrl) { //Convert pointer to slider pointer CSliderCtrl *pSld; pSld = (CSliderCtrl*)pCtrl; //Get new position x = pSld->GetPos(); a = x; CString s; s.Format("%d",x); //Output value for red stcred.SetWindowText(s); } Note that: 1.) Initialize the colorbar to have values RGB(a,b,c) 2.) Variable "a" read in from the "OnHScroll" function and set to a new value. 3.) "OnPaint" deletes the old colorbar and re-creates with new "a" variable value, should display as output with the new color but doesn't, still displays as original a,b,c values. Please advise, Sid kraft sid_kraft@msn.com Thanks in advance, Sid Kraft. Sid

      L Offline
      L Offline
      Laxman Auti
      wrote on last edited by
      #2

      sidkraft wrote:

      //Output value for red stcred.SetWindowText(s);

      Use InvalidateRect(...) with your colorfill rect as a parameter after stcred.SetWindowText(s); which fires the Onpaint Message and you will get the result Knock out 't' from can't, You can if you think you can :cool:

      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