Solved

problem in SetTextColor function

Posted on 2003-10-24
3
462 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

708 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

16 Experts available now in Live!

Get 1:1 Help Now