Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I cause the OnEraseBackground message for a PropertyPage. RedrawWindow does not work

Posted on 2006-07-14
16
Medium Priority
?
816 Views
Last Modified: 2013-11-20
Hello,

I have a dialog with a tab control that has a 1:1 relationship with its tabs and property pages multiple property pages stored in a map.
In the OnSize of my main dialog I call SizeTabControl which will properly size the tab control and call MoveWindow for each property page to position and size it.
When the program is running if I resize the dialog I always get the same background colour; the colour of the last page in the map.

What I want to do is show the colour of the currently selected tab.  I think the solution is to call a method that would cause an
OnEraseBackground for that PropertyPage.  I've tried to RedrawWindow but it does not cause OnEraseBackground.

I have read a couple of topics that mention InvalidateRect.  Is this the proper solution and if it is how do you use it?
0
Comment
Question by:alexatsearidge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 4
  • +1
16 Comments
 

Author Comment

by:alexatsearidge
ID: 17108355
I could also just update the colour on my timer but I can't have my display blinking every second.  Unless there is a more efficient way to do it.
0
 
LVL 9

Expert Comment

by:smidgie82
ID: 17108522
Hi alexatsearidge,

Calling InvalidateRect will cause the OnPaint method for the window class to be called, but I don't know about OnEraseBackground.  You could certainly call the tab view's OnEraseBackground method from the window's OnPaint method when it's run after the InvalidateRect call, if you wanted to do it that way.

Cheers!
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17108875
you may override OnEraseBkgnd of your property page like following to fil color with red

CMyPage::OnEraseBkgnd(CDC *pDC)
{
  CRect rect;
  GetClientRect(&rect);
  pDC->FillSolidRect(&rect, RGB(255, 0, 0));  //Fill the background
  return TRUE;
}

OR even you may use pattern built like following :

CMyPage::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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:alexatsearidge
ID: 17110202
Hey smidgie,

Using the InvalidateRect to cause OnPaint in the propertypage works great.  I realize now that my problem goes deeper though.
I have a CMapStringToPtr pageMap member that is a map of tab names to property page pointers.

My goal is to call InvalidateRect for the currently selected page but that causes OnPaint for every property page.
I'm writing from memory but my code is like this:

MainDlg::OnSize() {
    CString tab = GetSelectedTab();
    // Get the pointer for the page, then call InvalidateRect()
    (CMyPage*)pageMap[tab]->GetPagePtr()->InvalidateRect();
}

Any idea why it would call OnPaint for each Property Page?
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17110386
what if you try that with GetActivePage().. ? Something like :


CPropertyPage* pActivePage = CMyPage->GetActivePage();
pActivePage->InvalidateRect();

-MAHESH

0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17110417
oops it shld just : CPropertyPage* pActivePage = GetActivePage();

-MAHESH
0
 
LVL 9

Accepted Solution

by:
smidgie82 earned 2000 total points
ID: 17110938
Are you seting style to WS_VISIBLE for only the active property page when selected through the tab control?  Or are you just modifying the stacking order?  With the others not set to visible, they shouldn't call OnPaint, whereas if they're all visible and stacked, they will all call OnPaint when InvalidateRect() is called.
0
 

Author Comment

by:alexatsearidge
ID: 17111142
No I haven't been setting any styles at all.  How would I set the style to invisible/visible?
0
 

Author Comment

by:alexatsearidge
ID: 17111380
Ok so I think it would be ShowWindow(SW_HIDE or SW_SHOW) I'm testing it but I'm getting odd results.
I'll continue this topic on Monday if that is ok with you guys.  Your help has been invaluable.

Have a great weekend.
0
 

Author Comment

by:alexatsearidge
ID: 17149387
Ok I'm back on this problem guys.  Nothing I seem to be doing works.  
I've tried to hide all the other windows and then invalidate the page currently selected but it is still calling OnPaint for every property page.
I have 5 and no matter what I do the 5 property page is all I see since everytime it paints it paints them on top of eachother.
How can I hide those other pages?
0
 

Author Comment

by:alexatsearidge
ID: 17153735
> oops it shld just : CPropertyPage* pActivePage = GetActivePage();

Intellisense cannot find the method GetActivePage.  Which class does it belong to?
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17153949
sorry alexatsearidge  that belongs to CPrpoertySheet class
0
 
LVL 9

Expert Comment

by:smidgie82
ID: 17154028
That's right, you wouldn't find it under CPropertyPage, because instances of CPropertyPage only represent a single page in the property sheet.  Use object that represents the entire property sheet.  It should be derived from CPropertySheet, which exposes the GetActivePage() method.
0
 
LVL 9

Expert Comment

by:smidgie82
ID: 17154057
How are you hiding the other windows?  Are you using the ModifyStyle method exposed by the CWnd base class?  Or are you using some other method?
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 17159264
Override the OnSetActive function in the property PAGE.
There call InvalidateRect  (To be honest I would have expected it to be invalidated by the system but...)
Also in the PAGE have code like that from mahesh to perform the colouring that you require.
0
 

Author Comment

by:alexatsearidge
ID: 17170347
Turns out all along it was because all the property pages were shown.  Now I hide them all at start up and when a tab is selected I show that page and hide the previous one.  This way if OnEraseBackground is called it will only be called for the shown page.

Thanks for all your help guys.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

722 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