Issue in drawing color on propertysheet footer?

366 Views Asked by At

I designed a property sheet and painted its footer to some gradient in the OnPaint() event. The footer looks like as below.Observe the button area circled in red colour. enter image description here

In the OnPaint I was doing as follows,

//CMySheet is derived from CPropertySheet.
void CMySheet::OnPaint()
{

if(IsIconic())
    {
        CPaintDC dc(this); // device context for painting
        SendMessage(WM_ICONERASEBKGND,reinterpret_cast<WPARAM>(dc.GetSafeHdc()),0);

        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);

        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1)/2;
        int y = (rect.Height() - cyIcon + 1)/2;

    }
    else
    {
        CPaintDC dc(this);

        UpdateData(false);

        CRect Clientrect;
        GetClientRect(&Clientrect);

        LONG RectDifference = ((Clientrect.bottom - m_PageRectBottom)-2);//m_pageRectBottom is of page bottom rect

        CRect rectFooter(Clientrect.top,(Clientrect.bottom - RectDifference),Clientrect.right,Clientrect.bottom);//638//520
        //CRect rectFooter(0,390,640,445);
        FillGradation(&dc,rectFooter,RGB(150,150,150),RGB(0,0,0),true);

    }

}
}

void CMySheet::OnPaint(CDC* pDC, CRect rc, COLORREF colBegin, COLORREF colEnd, bool bV)
{
    TRIVERTEX av[2] = {rc.left,rc.top,GetRValue(colBegin) << 8,GetGValue(colBegin) << 8,GetBValue(colBegin) << 8 ,0xff00,
        rc.right,rc.bottom,GetRValue(colEnd) << 8 ,GetGValue(colEnd) << 8,GetBValue(colEnd) << 8,0xff00,};

    GRADIENT_RECT gr = {0,1};
    ULONG ulMode;
    if(bV){
        ulMode = GRADIENT_FILL_RECT_V;
    }
    else{
        ulMode = GRADIENT_FILL_RECT_H;       
    }
    GradientFill(pDC->GetSafeHdc(),av,2,&gr,1,ulMode);

}

The buttons are not transparent in the above image ,but actually the background of the button should look like as in below image.

enter image description here

The wizard buttons background or the footer area should look like the above image.But if you can have a look at the first image in that there is some white colour around the Back button ,Next and cancel buttons.

HBRUSH CMySheet::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CPropertySheet::OnCtlColor(pDC, pWnd, nCtlColor);

    if((pWnd->GetDlgCtrlID() == ID_WIZBACK) || (pWnd->GetDlgCtrlID() == ID_WIZNEXT) ||
        (pWnd->GetDlgCtrlID() == ID_WIZFINISH) || (pWnd->GetDlgCtrlID() == IDCANCEL))
    {
        return CreateSolidBrush(RGB(130,130,130));
    }

  return hbr;
}

If I am doing like this ,the Image is as follows with gray colour .But that colour should be gradient right,I am not able to create a Gradient brush.

enter image description here

I tried returning NULL in CtlColor but I could not see any difference.

Derived my own classes from CPropertySheet and CButton ,

//Overrided the DrawItem and PreSubclassWindow
    void CPropSheetButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {

        CDC* pDC   = CDC::FromHandle(lpDrawItemStruct->hDC);
        CRect rect = lpDrawItemStruct->rcItem;
        UINT state = lpDrawItemStruct->itemState;


        if (state & ODS_SELECTED)
            pDC->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH | DFCS_PUSHED);
           else
               pDC->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH);

        UINT uStyle = DFCS_BUTTONPUSH;
        HTHEME hTheme = OpenThemeData(m_hWnd, L"BUTTON");
        HRESULT hr = DrawThemeBackground(hTheme, lpDrawItemStruct->hDC, BP_PUSHBUTTON, PBS_DEFAULTED, &lpDrawItemStruct->rcItem, NULL);

        // Get the button's text.
        CString strText;
        GetWindowText(strText);


        CloseThemeData(hTheme);
        ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
            &lpDrawItemStruct->rcItem, DT_SINGLELINE | DT_VCENTER | DT_CENTER);


            int nMode = pDC->SetBkMode(TRANSPARENT);
            pDC->SetBkMode(nMode);

    }

    void CPropSheetButton::PreSubclassWindow() 
    {
        CButton::PreSubclassWindow();

        ModifyStyle(0, BS_OWNERDRAW);   // make the button owner drawn
    }
    //In the Sheet derived class OnInitDialog ,
    BOOL CMySheetWizard::OnInitDialog()
    {

        CPropertySheet::OnInitDialog();
        CMyButton backbutton;
        BOOL bRet = backbutton.SubclassDlgItem(ID_WIZBACK,this);
    }

Can anyone please let me know how I can remove the border around those buttons.

1

There are 1 best solutions below

6
On

Using your painting code to render the background and some extra classes, I was able to achieve this...

enter image description here

I think this was what you were trying to achieve. I was able to accomplish this by doing the following:

  • Derive my own CPropertySheet and CButton classes.
  • Subclass the property sheet buttons and make them owner drawn.

And here's the code that draws the buttons from the button class.

void SheetButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
    {
    UINT uStyle = DFCS_BUTTONPUSH;
    HTHEME hTheme = OpenThemeData(m_hWnd, L"BUTTON");
    DrawThemeBackground(hTheme, lpDrawItemStruct->hDC, BP_PUSHBUTTON, PBS_DEFAULTED, &lpDrawItemStruct->rcItem, NULL);

    // Get the button's text.
    CString strText;
    GetWindowText(strText);

    // Draw the button text using the text color red.
    COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255, 0, 0));
    ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
        &lpDrawItemStruct->rcItem, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
    ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);

    CloseThemeData(hTheme);
    }

BTW...you still need to add code to return a null brush for the buttons. I did not, however, account for the different states of the buttons in the drawing code. I left that up to you as an exercise.