change color of the backround of an ocx

Posted on 2009-04-28
Last Modified: 2012-05-06
I am using an ocx developed in
I had given the backround color as white
Windows having only the four colors to change
I am using it in the page and also in other platforms
So i want to change the color of it by selecting the color dialog my code is

void CNoteTakerCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)


	if (!pdc)


	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(LTGRAY_BRUSH)));



Open in new window

Question by:PBCHANDRAN

    Author Comment

    change the color without erasing the drawings made above.
    That is i have drawn some lines without changing that change the color.

    Author Comment

    the color can vary dynamically
    LVL 1

    Accepted Solution

    Use the CColorDialog class to call the common color dialog box;
     eg: CColorDialog dlgClr(RGB(190, 0, 190), CC_FULLOPEN);
    and get the selected color from the dialog;
    and try using the above received color in the below mentioed way
         CBrush brBkgnd(RGB(190,190,190));      // Any RGB Color
          pdc->FillRect(&rcBounds, &brBkgnd);

    Author Comment

    i got ur code.but problem is how to erase the previous backcolor and how to give new color without the erase in drawings made by pen.

    if i am using a function say

          CColorDialog c;
          if (c.DoModal()==1)
         CBrush brBkgnd(c.getcolor());      // Any RGB Color
          pdc->FillRect(&rcBounds, &brBkgnd);

    how to initialise pdc ,rcbounds

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now