rickatseasoft
asked on
Is a call to CBrush::DeleteObject a good/bad/neutral idea in this case
I am using a function that draws text on the screen, and, based on mouse input, some portion of the screen needs to be highlighted by the use of a user selected(previously) background color. This function also decides what color the text will be.
My specific question: is the cb.DeleteObject line necessary, prohibited, or otherwise?
Secondary Questions: Is there a significantly better way to accomplish what I want to accomplish?
Is there a dead solid way to determine when a DeleteObject is required?
int Index;
static COLORREF StdBK;
COLORREF cr,cf;
CBrush cb;
Index=scr->Color;
if(!StdBK)StdBK=pDC->GetBk Color();
if(Index<0)Index=0;
else if (Index>(SCH_COLOR_COUNT-1) )Index=SCH _COLOR_COU NT-1;
cr=RGB(m_SchCol.Red[Index] ,m_SchCol. Green[Inde x],m_SchCo l.Blue[Ind ex]);
cf=RGB(m_SchCol.Red[SCHFOC US],m_SchC ol.Green[S CHFOCUS],m _SchCol.Bl ue[SCHFOCU S]);
if(pDC){
pDC->SetTextColor(cr);
pDC->FillRect(scr->ScrnAre a,&cb);
if(Focus){
cb.CreateSolidBrush(cf);
pDC->SetBkColor(cf);
}else{
cb.CreateSolidBrush(StdBK) ;
pDC->SetBkColor(StdBK);
}
// cb.DeleteObject();
}
return cr;
I should add that this function is called probably 100 times on a typical OnDraw();
thanks in advance, Rick
My specific question: is the cb.DeleteObject line necessary, prohibited, or otherwise?
Secondary Questions: Is there a significantly better way to accomplish what I want to accomplish?
Is there a dead solid way to determine when a DeleteObject is required?
int Index;
static COLORREF StdBK;
COLORREF cr,cf;
CBrush cb;
Index=scr->Color;
if(!StdBK)StdBK=pDC->GetBk
if(Index<0)Index=0;
else if (Index>(SCH_COLOR_COUNT-1)
cr=RGB(m_SchCol.Red[Index]
cf=RGB(m_SchCol.Red[SCHFOC
if(pDC){
pDC->SetTextColor(cr);
pDC->FillRect(scr->ScrnAre
if(Focus){
cb.CreateSolidBrush(cf);
pDC->SetBkColor(cf);
}else{
cb.CreateSolidBrush(StdBK)
pDC->SetBkColor(StdBK);
}
// cb.DeleteObject();
}
return cr;
I should add that this function is called probably 100 times on a typical OnDraw();
thanks in advance, Rick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Created - OK.
Necessary - ? - you could use FillSolidRect (unless it is a pattern brush) and so no need for the CBrush at all.
Necessary - ? - you could use FillSolidRect (unless it is a pattern brush) and so no need for the CBrush at all.
ASKER
Thanks guys:
AlexFM: I suspected that was the case, but wanted verification.
Andy: An excellent idea that I will try today.
Thanks again! Rick
AlexFM: I suspected that was the case, but wanted verification.
Andy: An excellent idea that I will try today.
Thanks again! Rick
ASKER
You are absolutely correct! I did some cutting and pasting to remove code that was exterraneous to the problem, and screwed that one up. In the real code, the cb has been created.
Rick