Solved

problem in SetTextColor function

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 115
SNMP error No Such Object available on this agent at this OID 3 298
GUI: DIalog Stacking and Popping in MS C++ 4 81
I could not build boost code, 10 94
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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

839 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