Solved

How do I set the background color of a CPropertyPage

Posted on 2006-06-11
6
693 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generic progress indicator 6 113
iSeries DB2 Query 2 91
Doc'in system (example?) BA 7 89
either24  challenge 19 90
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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

13 Experts available now in Live!

Get 1:1 Help Now