Avatar of Thomas Stockbruegger
Thomas Stockbruegger
Flag for Germany asked on

Need some help to C++ if statement to catch the -0.01 to -0.99

Need some help to C++ if Statement.
I will not catch the -0.01 to -0.99 with this if statement.
The crText will be blue and not red
prozent= double variable
                  
                   if(prozent<0)
                   {
                          crText = RGB(255,0,0);      //red
                     }
                   else
                   {
                         crText = RGB(0,0,255);      //blue
                     }
Please let me know how I can fix this simple statement.
Thank you.
Best regards,
Thomas
C++* MFC

Avatar of undefined
Last Comment
Thomas Stockbruegger

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Thomas Stockbruegger

ASKER
void CStatistik_UMA::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
 {
	 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );

    // Take the default processing unless we set this to something else below.
    *pResult = 0;

    // First thing - check the draw stage. If it's the control's prepaint
    // stage, then tell Windows we want messages for every item.

    if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
        {
        *pResult = CDRF_NOTIFYITEMDRAW;
        }
    else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
        {
        // This is the notification message for an item.  We'll request
        // notifications before each subitem's prepaint stage.

        *pResult = CDRF_NOTIFYSUBITEMDRAW;
        }
    else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
        {
        // This is the prepaint stage for a subitem. Here's where we set the
        // item's text and background colors. Our return value will tell 
        // Windows to draw the subitem itself, but it will use the new colors
        // we set here.
        
    
            COLORREF crText, crBkgnd;

			//------------------verschiedene Reihen in Farbe ----------------------
			//MemberVariable m_bAnzeige_Typen = true ->Typen Auswahl    false->alle anderen
			int iCol = pLVCD->iSubItem;
			int iRow = pLVCD->nmcd.dwItemSpec;

			CString str_help=m_List.GetItemText(iRow,14);//Reihe 14 und 17 grauer Balken
			
			//-------------------------------------------------------------------------------
	   		if(m_bAnzeige_Typen==false && m_bAnzeige_KundenUmsatz==false)//also nicht bei Typen
			{
                if(pLVCD->nmcd.dwItemSpec==14 ||pLVCD->nmcd.dwItemSpec==17)
			    {
				
		          crBkgnd = RGB(192,192,192);     //grau
			    }
			    else
		     	{
				
		          crBkgnd = RGB(255,255,224); //beige
			    }
			}
           //---------------------------------------------------------------------------

			
			 
			//-------------------------------------------------------------------------------
            if(m_bAnzeige_Typen==false && m_bAnzeige_KundenUmsatz==true)//KundenUmsatz
			{
				CString str_help=m_List.GetItemText(iRow,0);
				if(str_help=="Ges.")
				{
					 crText = RGB(0,0,255);   //blau  
   				     crBkgnd = RGB(0,191,255);//hellblau  
				}
				else if(str_help=="Ges.:")//Gesamt Total am Ende
				{
					  crText = RGB(0,0,255);      //blau
					  crBkgnd = RGB(255,255,0);   //gelb
				}
				else  
				{
					  crText = RGB(0,0,255);      //blau
					  crBkgnd = RGB(255,255,224); //beige
				}

			}
           		
			//-------------------------------------------------------------------------------
			if(m_bAnzeige_Typen==true)// Typen
			{
				int fabwechsel = pLVCD->iSubItem;
				if(fabwechsel %2!=0)//alle Columns die durch 2 teilbar sind (module Operator)
				{
					 crBkgnd = RGB(255,255,224);     //beige
			    }
			    else
		     	{
				
		          crBkgnd = RGB(255,255,255); //weiß
				  
				}
				if(pLVCD->iSubItem==0)//erste Spalte auch in beige
				{
					crBkgnd = RGB(255,255,224);     //beige
				}


                if(pLVCD->nmcd.dwItemSpec==m_Anzahl_der_Typen+2||pLVCD->nmcd.dwItemSpec==m_Anzahl_der_Typen)
			    {
				
		          crBkgnd = RGB(192,192,192);     //grau Balken
			    }
			  
			}

         [b]   //--------------------- negative Zahlen in rot -----------------------------
			 str_help=m_List.GetItemText(iRow,iCol);
			 double prozent;
			 prozent=atof(str_help);

			
			 if(prozent<0)
			 {
				  crText = RGB(255,0,0);      //rot
		  	 }
			 else
			 {
				 crText = RGB(0,0,255);      //blau
	      	 }[/b]
		     //--------------------------- High / Low Werte in Farbe ----------------------
			 // MemberVariablen
			 // m_highWert_Zeile   m_highWert_Spalte
		    //  m_lowWert_Zeile    m_lowWert_Spalte
			if(m_highWert_Spalte!=99999999 && 	m_lowWert_Spalte!=99999999)
			{

			    if(m_bAnzeige_KundenUmsatz ==false)
			    {
                     if(pLVCD->nmcd.dwItemSpec==m_highWert_Zeile && pLVCD->iSubItem==m_highWert_Spalte)
			         {
                          crBkgnd = RGB(191,239,255);     // HighWert blau
			         }
			
			         if(pLVCD->nmcd.dwItemSpec==m_lowWert_Zeile && pLVCD->iSubItem==m_lowWert_Spalte)
			         { 
                          crBkgnd =RGB(255,193,193);     // LowWert rot RGB(255,64,64);     // LowWert rot
			        }
			    }
			}
			//-------------------------------------------------------------------------------
			 if(m_bAnzeige_Typen==true)// Typen  Graue Zahlen bei % Anteil
			{
				int fabwechsel = pLVCD->iSubItem;
				if(fabwechsel>0 && fabwechsel %2==0)//alle Columns die durch 2 teilbar sind (module Operator)
				{
					 crText = RGB(105,105,105);     //dunkel grau
			    }
			}
            //-------------------------------------------------------------------------------
			UpdateData(TRUE);
			bool bTypen= m_checkbox_Typen.GetCheck();
			if(m_SteuerungTypen==1)
			{
                if(4==pLVCD->iSubItem)//Typenspalte andere Farbe
				{
					crText = RGB(0,205,102);       
					 
				}
			}

                 
	    // Store the colors back in the NMLVCUSTOMDRAW struct.
        pLVCD->clrText = crText;
        pLVCD->clrTextBk = crBkgnd;

        // Tell Windows to paint the control itself.
        *pResult = CDRF_DODEFAULT;
        }
}
 //-------------------------------------------------------------------------------

Open in new window


The code is in OnCustomdrawList.
SOLUTION
sarabande

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Thomas Stockbruegger

ASKER
Thank you Sara for your answer.
The code will not work.... with your code every prozent, the text is in blue.
SOLUTION
phoffric

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Thomas Stockbruegger

ASKER
I found the solution....very simple it was my mistake (today is Monday)
                         str_help=m_List.GetItemText(iRow,iCol);
                   double prozent;
                   str_help.Replace(',',',.');
                   prozent=atof(str_help);



In my List View the data is in German writing : with a "," f.e.  0,33  -0,33
I have to replace the "," with "." then it works
Sorry to bother you.
Best regards,
Thomas
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Thomas Stockbruegger

ASKER
Thank you for your time
ste5an

hmm, I thought atof() uses the locales correctly, doesn't it?
SOLUTION
sarabande

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Thomas Stockbruegger

ASKER
Thank you Sara for the explanation in detail !
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.