• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 820
  • Last Modified:

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

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
alexatsearidge
Asked:
alexatsearidge
  • 7
  • 4
  • 4
  • +1
1 Solution
 
alexatsearidgeAuthor Commented:
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
 
smidgie82Commented:
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
 
mahesh1402Commented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
alexatsearidgeAuthor Commented:
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
 
mahesh1402Commented:
what if you try that with GetActivePage().. ? Something like :


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

-MAHESH

0
 
mahesh1402Commented:
oops it shld just : CPropertyPage* pActivePage = GetActivePage();

-MAHESH
0
 
smidgie82Commented:
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
 
alexatsearidgeAuthor Commented:
No I haven't been setting any styles at all.  How would I set the style to invisible/visible?
0
 
alexatsearidgeAuthor Commented:
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
 
alexatsearidgeAuthor Commented:
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
 
alexatsearidgeAuthor Commented:
> oops it shld just : CPropertyPage* pActivePage = GetActivePage();

Intellisense cannot find the method GetActivePage.  Which class does it belong to?
0
 
mahesh1402Commented:
sorry alexatsearidge  that belongs to CPrpoertySheet class
0
 
smidgie82Commented:
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
 
smidgie82Commented:
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
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
 
alexatsearidgeAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now