CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 6 of 7 FirstFirst ... 34567 LastLast
Results 76 to 90 of 92

Thread: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

  1. #76
    Join Date
    Oct 2019
    Posts
    82

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    UpdataData get Called
    m_ok has a valid m_hwnd after call
    Steeping into DDX call resulted in just moving to the next line.
    Yes m_hwnd has valid handler after methods stated above

  2. #77
    Join Date
    Oct 2019
    Posts
    82

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    I am able to find out the issue and now button is colored..Issue is ,i am using OnDrawItem() in MyPropertysheet class to color the tab controls as soon as i remove this code of OnDrawItem my button gets colored.But now issue is how would i color my tab controls if it is not working in conjunction with code of button Color..Code for OnDrawItem() is as follows:

    Code:
    void MyPropertySheet :: OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
    {
       CDC dc;
       dc.Attach(lpDrawItemStruct->hDC);
       RECT rect = lpDrawItemStruct->rcItem;
    
       CTabCtrl * tab = GetTabControl();
       
       TCHAR buffer[256] = { 0 } ;
       TC_ITEM tabItem;
    
        tabItem.pszText = buffer;
        tabItem.cchTextMax = 256;
      
        int nTabIndex = lpDrawItemStruct->itemID;
        If(!tab->GetItem(nTabIndex, &tabItem))
        return;
    
        CBrush brush;
        If((lpDrawItemStruct-> itemState & ODS_SELECTED)&&(lpDrawItemStruct- >itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
            {
              brush.CreateSolidBrush(RGB(255,102,0));
              dc.SetBkMode(TRANSPARENT);
              dc.SetTextColor(RGB(255, 255, 255));
              dc.DrawText(tabItem. pszText, &lpDrawItemStruct- >rcitem, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
        
        }
    
       else
       {
    brush.CreateSolidBrush(RGB(255,255,255));
              dc.SetBkMode(TRANSPARENT);
              dc.SetTextColor(RGB(33, 33, 33));
              dc.DrawText(tabItem. pszText, &lpDrawItemStruct- >rcitem, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
        }
    
       dc.SetBkMode(TRANSPARENT);
       dc.SelectObject(&brush);
       dc.FillRect(&lpDrawItemStruct- >rcItem, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
       
       dc.Detach();
     
     }

  3. #78
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,732

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    Have a look at CMFCTabCtrl class (its base class CMFCBaseTabCtrl has the methods to set text and background colors)
    Victor Nijegorodov

  4. #79
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,587

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    I created an app from scratch and experienced the same results as the OP. Not sure why modifying an existing app worked. Anyway, here is code in my new app that works.

    In OnInitDialog in your CPropertySheet derived class
    Code:
    	UpdateData(FALSE);
    	m_OK.EnableWindowsTheming(FALSE);
    	m_OK.m_bTransparent = false;
    	m_OK.SetFaceColor(RGB(255, 0, 0), true);
    	m_OK.SetTextColor(RGB(0, 0, 255));
    	BOOL bResult = CPropertySheet::OnInitDialog();

  5. #80
    Join Date
    Oct 2019
    Posts
    82

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    How to get GetTabCtrl() using CMFCTabCtrl because CTabCtrl *tabCtrl = GetTabCtrl() is right but CMFCTabCtrl *tabCtrl = GetTabCtrl() gives compilation error
    Note: I have included <afxtabctrl.h> for CMFCTabCtrl

  6. #81
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,732

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    If you mean the tab control of the CPropertySheet sheet then you should move to CMFCPropertySheet used with the CMFCPropertyPage pages.
    Victor Nijegorodov

  7. #82
    Join Date
    Oct 2019
    Posts
    82

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    What is m_bTransparent?

  8. #83
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,587

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    Quote Originally Posted by Beginner_MFC View Post
    What is m_bTransparent?
    Google it. Did you try the code?

  9. #84
    Join Date
    Oct 2019
    Posts
    82

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    I have to try above with keeping onDrawItem() as it is in MyPropertysheet class?

  10. #85
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,587

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    Quote Originally Posted by Beginner_MFC View Post
    I have to try above with keeping onDrawItem() as it is in MyPropertysheet class?
    Did you try the code I posted a few posts back?

  11. #86
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,732

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    Quote Originally Posted by Beginner_MFC View Post
    What is m_bTransparent?
    https://docs.microsoft.com/en-us/cpp...m_btransparent
    You must read the Microsoft documentation.
    Victor Nijegorodov

  12. #87
    Join Date
    Oct 2019
    Posts
    82

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    Mess up.keeping it simple..My button background color issue was solved when i used UpdateData(FALSE) And i removed onDrawItem() which is used for coloring tabs ..so now question is how to color Tabs means if i have to remove onDrawItem() from MyPropertysheet class than how will i achieve it

  13. #88
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,587

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    I would assume you want to use your custom code for the tab control and the base class implementation for everything else, including the buttons.

  14. #89
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,732

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    Quote Originally Posted by GCDEF View Post
    I would assume you want to use your custom code for the tab control and the base class implementation for everything else, including the buttons.
    Alternatively you could do what I wrote in the post#81
    Victor Nijegorodov

  15. #90
    Join Date
    Oct 2019
    Posts
    82

    Re: Changing background Color of standard buttons (ok,cancel,help) of Cpropertysheet

    I am able to achieve it by deriving MyCTabCtrl from CTabCtrl and using OnPaint() method and than subclassing it in MyPropertysheet class.Everything resolved ,just one issue,i got the tabs colored but also got the border area colored(Image is attached for reference),i dont want border lines to get colored.How can i modify my code..Code for OnPaint() is as follows:

    Code:
    void CMyTabCtrl::OnPaint()
    {
        CPaintDC dc(this);
    
        dc.SelectObject(GetFont());
    
        CPen pen, pen_active;
        COLORREF color_off = RGB(240, 240, 240);
        COLORREF color_active = RGB(255, 102, 0);
        CBrush brush_off, brush_active;
        brush_off.CreateSolidBrush(color_off);
        brush_active.CreateSolidBrush(color_active);
        pen.CreatePen(PS_SOLID, 1, RGB(200, 200, 200));
        pen_active.CreatePen(PS_SOLID, 1, color_active);
    
        CRect rcitem;
        GetItemRect(0, &rcitem);
    
        CRect rc;
        GetClientRect(&rc);
        rc.bottom = rcitem.bottom;
        dc.FillSolidRect(&rc, GetSysColor(COLOR_3DFACE));
    
        GetClientRect(&rc);
        rc.top = rcitem.bottom - 1;
        dc.SelectObject(&pen);
        dc.SelectObject(&brush_active);
        dc.Rectangle(&rc);
    
        for(int i = 0; i < GetItemCount(); i++)
        {
            dc.SelectObject(&pen);
            if(i == GetCurSel())
            {
                dc.SelectObject(&brush_active);
                dc.SetBkColor(color_active);
            }
            else
            {
                dc.SelectObject(&brush_off);
                dc.SetBkColor(color_off);
            }
    
            GetItemRect(i, &rcitem);
            rcitem.right++;
            dc.Rectangle(&rcitem);
    
            if(i == GetCurSel())
            {
                dc.SelectObject(pen_active);
                dc.MoveTo(rcitem.left+1, rcitem.bottom - 1);
                dc.LineTo(rcitem.right, rcitem.bottom - 1);
            }
    
            TCITEM item = { 0 };
            wchar_t buf[32];
            item.pszText = buf;
            item.cchTextMax = 32;
            item.mask = TCIF_TEXT;
            GetItem(i, &item);
            dc.DrawText(buf, &rcitem, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
        }
    }
    Attached Images Attached Images  

Page 6 of 7 FirstFirst ... 34567 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)