Link to home
Start Free TrialLog in
Avatar of Thomas Stockbruegger
Thomas StockbrueggerFlag 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
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Sara for your answer.
The code will not work.... with your code every prozent, the text is in blue.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Thank you for your time
hmm, I thought atof() uses the locales correctly, doesn't it?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Sara for the explanation in detail !