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

This is a discussion on Owner Drawn Group Box "Eats" children on re-draw. - Programmer ; 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://groups.google.com/groups?q=pD...sbbsa04&rnum=4 ...

+ Reply to Thread
Results 1 to 5 of 5

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

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

    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://groups.google.com/groups?q=pD...sbbsa04&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!

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

    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.

    "Ryan J. Geyer" wrote in message
    news:bcefb87e.0311112026.7279b974@posting.google.c om...
    > 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://groups.google.com/groups?q=pD...sbbsa04&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!




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

    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. :-)

    "Ali R." wrote in message news:...
    > 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.
    >
    > "Ryan J. Geyer" wrote in message
    > news:bcefb87e.0311112026.7279b974@posting.google.c om...
    > > 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://groups.google.com/groups?q=pD...sbbsa04&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!


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

    I 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" wrote in message
    news:bcefb87e.0311122051.1a8d48d0@posting.google.c om...
    > 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. :-)
    >
    > "Ali R." wrote in message

    news:...
    > > 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.
    > >
    > > "Ryan J. Geyer" wrote in message
    > > news:bcefb87e.0311112026.7279b974@posting.google.c om...
    > > > 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://groups.google.com/groups?q=pD...sbbsa04&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!




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

    Alright!

    Yup, that did the trick perfectly!

    Thanks a ton!

    "Ali R." wrote in message news:...
    > I 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" wrote in message
    > news:bcefb87e.0311122051.1a8d48d0@posting.google.c om...
    > > 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. :-)
    > >
    > > "Ali R." wrote in message

    > news:...
    > > > 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.
    > > >
    > > > "Ryan J. Geyer" wrote in message
    > > > news:bcefb87e.0311112026.7279b974@posting.google.c om...
    > > > > 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://groups.google.com/groups?q=pD...sbbsa04&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!


+ Reply to Thread