Solved

problem in SetTextColor function

Posted on 2003-10-24
3
470 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
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 150 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

948 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now