change color of the backround of an ocx

Posted on 2009-04-28
Medium Priority
Last Modified: 2012-05-06
I am using an ocx developed in VC++.net
I had given the backround color as white
Windows having only the four colors to change
I am using it in the ASP.net 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
  • 3

Author Comment

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

Author Comment

ID: 24249384
the color can vary dynamically

Accepted Solution

tulasisiva earned 200 total points
ID: 24251171
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

ID: 24258142
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

862 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