Solved

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

Posted on 2006-07-14
16
765 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
  • 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
 

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 500 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
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.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
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.
This video discusses moving either the default database or any database to a new volume.

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