Solved

How do I set the background color of a CPropertyPage

Posted on 2006-06-11
6
709 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

756 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