?
Solved

problem in SetTextColor function

Posted on 2003-10-24
3
Medium Priority
?
505 Views
Last Modified: 2012-08-14
Hi
in formview class,i have a bitmap having random data displaying at different positions of bitmap on runtime.I have four fields in my binary table from where this random data is comming.Now i have to give diffrent colors to that random numbers by applying different conditions.Problem is that when i run program and then by right clicking on that number ,then my conditions are applied on that.whereas in my right click event,only information of that variable is shown on the screen.How can i overcome this problem.My condition should work at run time.Is there any problem in SetTextColor function.
void CPPCView::OnTimer(UINT nIDEvent)
{
    CDC* my_cdc;
CTime curTime=CTime::GetCurrentTime();
      switch(nIDEvent)
      {
      
      case 1:

        my_cdc=m_ctrlBmp.GetDC ();
          my_cdc->SetTextColor(RGB(0x00,0xFF,0x00));
        my_cdc->SetBkColor(RGB(0,0,0));
if(!LLAlarm[varNew] && !LowAlarm[varNew] && !HighAlarm[varNew] && !HHAlarm[varNew])         //if fields are empty
            {
 m_sCount.Format("%.1f",fCurrValue);//fcurrvalue is random number
        my_cdc->SetTextColor(RGB(0x00,0xFF,0x00));            //color green
          my_cdc->TextOut((ptA.x-25),(ptA.y-5), m_sCount);
            }
            else
            {
            if((fCurrValue<LLAlarm[varNew]) && (fCurrValue>=LScale[varNew]))   //LLAlarm and LScale are name of fields
      {
      m_sCount.Format("%.1f",fCurrValue);

  my_cdc->SetTextColor(RGB(255,0,0));  //color red
  my_cdc->TextOut((ptA.x-25),(ptA.y-5), m_sCount);
                    }
else if((fCurrValue>=LLAlarm[varNew]) && (fCurrValue<m_lAlarm))  //m_lAlarm is name of field
                    {
      m_sCount.Format("%.1f",fCurrValue);
       my_cdc->SetTextColor(RGB(255, 0, 255)); //color magenda
     my_cdc->TextOut((ptA.x-25),(ptA.y-5), m_sCount);
                    }
      
   else if((fCurrValue>=HHAlarm[varNew]) && (fCurrValue<HScale[varNew]))
                    {
m_sCount.Format("%.1f",fCurrValue);
 
my_cdc->SetTextColor(RGB(255,0,0));
       
my_cdc->TextOut((ptA.x-25),(ptA.y-5), m_sCount);
                    }
else if((fCurrValue>=m_hAlarm) && (fCurrValue<HHAlarm[varNew]))
                    {
      m_sCount.Format("%.1f",fCurrValue);
       my_cdc->SetTextColor(RGB(255, 0, 255));//magenda
       
      my_cdc->TextOut((ptA.x-25),(ptA.y-5), m_sCount);
                    }
      else
                    {

          m_sCount.Format("%.1f",fCurrValue);
      my_cdc->SetTextColor(RGB(0x00,0xFF,0x00));//green
     my_cdc->TextOut((ptA.x-25),(ptA.y-5), m_sCount);
                  }
                    }
               
                    }  
//             }
                  }
           
      
            UpdateData(false);
            break;

cancermcs
0
Comment
Question by:cancermcs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 600 total points
ID: 9613718
All drawing code should be only in OnPaint function or in functions called from it. In OnTimer and any other message handler you should only set some member variables and invalidate window. After window is invalidated OnPaint function redraws it according to current state.

void CPPCView::OnTimer(UINT nIDEvent)
{
    // set here text coordinates, colors etc. keeping them in the class members

    Invalidate();
    UpdateWindow();    // indirect call to OnDraw

    CView::OnTime(nIDEvent);
}

void CPPCView::OnDraw( CDC* pDC )
{
    pDC->...

   // All drawing code should be here
}
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10546101
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: AlexFM {http:#9613718}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question