Owner Drawn Group Box "Eats" children on re-draw.

Owner Drawn Group Box "Eats" children on re-draw.

Post by qwikre » Thu, 13 Nov 2003 13:26:44


Okay, I admit, the title sounds like a headline on Inquirer but, the
problem I have is real.

I've got a Group Box control that I've colorized using the method
outlined in another post found at the following URL.

http://www.yqcomputer.com/ %2Bcbutton%2Bbackground%2Bcolor&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=ufKqETDPAHA.244%40cppssbbsa04&rnum=4

Now, in my dialog I put this in my OnCrlColor method (snipped a bit).

HBRUSH CCRMMockMSDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if((pWnd->GetDlgCtrlID() == IDC_myGroup) ||) {
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(255,170,127));
return m_brush;

}
}

It works fine, but the first time anything in the dialog is redrawn
everything inside of my group box disappears, and all I see is my
background color. If I move the window, it redraws properly, and
everything is fine, and it doesn't happen again.

Any idea why this happens?

My app is "perfect" other than this little oddity. Thanks in advance!
 
 
 

Owner Drawn Group Box "Eats" children on re-draw.

Post by Ali R » Fri, 14 Nov 2003 05:22:56

I looked at the post, that guy is doing things the very hard way. A couple
of pointer, a Groupbox is a static, not a button.
If you aren't changing the shape of the box, or the color of the pen for the
rect then you can simply inherit from a CStatic
override the OnEraseBkGrnd and the OnCtrlColor and set the WS_EX_TRANSPARENT
of the group box.

BEGIN_MESSAGE_MAP(CMyGroup, CStatic)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()

BOOL CMyGroup::OnEraseBkgnd(CDC* pDC)
{
CRect Rect;
GetClientRect(&Rect);
CBrush Brush(RGB(255,255,0));
pDC->FillRect(&Rect,&Brush);
return TRUE;
}

HBRUSH CMyGroup::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetBkColor(RGB(255,255,0));
pDC->SetTextColor(RGB(255,0,0));
return CreateSolidBrush(RGB(255,255,0));
}

Ali R.



http://www.yqcomputer.com/ %2Bcbutton%2Bbackground%2Bcolor&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=ufKqETDPAHA.244%40cppssbbsa04&rnum=4

 
 
 

Owner Drawn Group Box "Eats" children on re-draw.

Post by qwikre » Fri, 14 Nov 2003 13:51:31

Hey Ali!

Thanks!

However, I'm a bit confused.

When I open ClassView, and attempt to assign a variable to my group
box, it only allows me to assign one for a button, or a class derived
from a button.

Also, I'm not sure where to put the code you proposed below. Am I
supposed to modify the code for the dialog that the group box is a
member of, or creating a new class?

I guess, I'm just asking for a bit more detail, cause I'm still lost.

Thanks in advance. :-)
 
 
 

Owner Drawn Group Box "Eats" children on re-draw.

Post by Ali R » Sat, 15 Nov 2003 01:15:48

am not sure why your classwizard does that. But anyhow, the code below is
to go into a new class which inherits from a CStatic. Then get a variable
to your group object, make sure it has a valid ID (Doesn't matter if it is a
CButton at first). Goto the h file of the dialog and change the type of the
variable to your new class. I hope that works for you.

Ali R.

"Ryan J. Geyer" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
news:<AEwsb.300$ XXXX@XXXXX.COM >...
couple
the
WS_EX_TRANSPARENT
http://groups.google.com/groups?q=pDC%2Bcbutton%2Bbackground%2Bcolor&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=ufKqETDPAHA.244%40cppssbbsa04&rnum=4


 
 
 

Owner Drawn Group Box "Eats" children on re-draw.

Post by qwikre » Sat, 15 Nov 2003 10:25:20

lright!

Yup, that did the trick perfectly!

Thanks a ton!

"Ali R." < XXXX@XXXXX.COM > wrote in message news:<U6Osb.606$ XXXX@XXXXX.COM >...