?
Solved

problem in SetTextColor function

Posted on 2003-10-24
3
Medium Priority
?
512 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 how to clear a vector as well as how to detect empty vectors in C++.

650 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