Solved

How do I set the background color of a CPropertyPage

Posted on 2006-06-11
6
689 Views
Last Modified: 2013-11-20
The title sums up my problem.  I have a tab control and each tab displays a different property page.  I need to be able to set the page color on tab selection.
Also, I've seen use of the OnCtrlClr method and was wondering if this when the page color is changed.

Thanks for your help.
0
Comment
Question by:alexatsearidge
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16882974
you may put code like following on your WM_ERASEBACKGROUND handler :

::OnEraseBkgnd(CDC *pDC)
{
  CRect rect;
  GetClientRect(&rect);
  CBrush myBrush(RGB(255,0,0)); // Solid RED for instance
  CBrush *pOld = pDC->SelectObject(&myBrush);
  BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
  pDC->SelectObject(pOld); // Have to restore old brush
  return bRes;
}

-MAHESH
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 16883236
mahesh is correct in handling the WM_ERASEBKGND message, unfortunately the code sample contained mistakes.

CMyPage::OnEraseBkgnd(CDC *pDC)
{
  CRect rect;
  GetClientRect(&rect);
  pDC->FillSolidRect(RGB(255, 0, 0));  //Fill the background with red for example

  //return TRUE to inform the system you have redrawn the background yourself.
  return TRUE;
}
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 16883260
Sorry - the PatBlt ought to work even without a bitmap or bitmapped brush, treat my comment as an alternative for a solid colour.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 16883266
I'm not having a good morning so far

pDC->FillSolidRect(RGB(255, 0, 0));  //Fill the background with red for example

should be

pDC->FillSolidRect(&rect, RGB(255, 0, 0));  //Fill the rectangle (background area) with red for example
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16883281
Well you may use anyone PatBlt() or FillSolidRect()
In my code pattern built is used to copy pattern to destination rectangle to make it solid fill.. which works.

-MAHESH
0
 

Author Comment

by:alexatsearidge
ID: 16885748
Thanks guys for all the help.  Really appreciate it.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

757 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

20 Experts available now in Live!

Get 1:1 Help Now