Synchronize OnSize() call.

Hello

I have a view Class called CTableView derived from the MFC class CListView. I am implementing the method 'OnSize()', that is called by the framework, that looks like.

void CTableView::OnSize(UINT nType, int cx, int cy)
{
m_nWndWidth = cx;

// check if the table has to be adapted to the window size.
if(m_nWndWidth < m_nTableWidth)
{
AdjustTable();
}

OnUpdate( 0, 0, 0 );

BASE::OnSize(nType, cx, cy);
}

If the window is resized with the mouse 'OnSize() is called, I adapt the number of Columns of theCListCtrl of the View to the Wnd width in the method 'AdjustTable(), so that all columns are visible.
But when the height of the CListCtrl is bigger then the height of the Wnd, the 'OnSize()' method is called because a vertical scrollbar has been added to the View.
This can cause problems, because the OnSize() has not been finished processing when the same OnSize() method is called again by the framework.
How I can prevent that OnSize() is called again, before it has finished processing.
I have Already tried using CRITICAL_SECTION in the method OnSize(), that was not working!

thanks.
Rolf
[1265 byte] By [rgwerder] at [2007-11-18 13:41:31]
# 1 Re: Synchronize OnSize() call.
Hello Rolf,
Does it mean you have a multithread application/control which is several time instanciated ? It looks that MFC doesn't like this.

I had this kind of problem with a MFC ActiveX when it was displayed several times in the same HTML frame.
The solution I found : rewrite this ActiveX not using MFC, building a DLL ActiveX using ATL in static.

Maybe your problem is similar ??

regards
Luc
Luck Duke at 2007-11-11 2:09:18 >
# 2 Re: Synchronize OnSize() call.
I don't think you can prevent OnSize from being called, so you need to do something else to prevent recursion.

MFC has a few of these situations itself, and it tends to use member variables (usually BOOLs) to prevent recursion. Try something like:

// in each constructor
CTableView::CTacleView():m_bInOnSize(FALSE){...}

// in OnSize
void CTableView::OnSize(UINT nType, int cx, int cy)
{
if ( !m_bInOnSize )
{
m_bInOnSize = TRUE;
m_nWndWidth = cx;

// check if the table has to be adapted to the window size.
if(m_nWndWidth < m_nTableWidth)
{
AdjustTable();
}

OnUpdate( 0, 0, 0 );
}

BASE::OnSize(nType, cx, cy);
}
MikeAThon at 2007-11-11 2:10:15 >
# 3 Re: Synchronize OnSize() call.
You can actually prevent OnSize from re-entering.

Firstly I'd suggest you move your call to base upwards first.

Anyway, to call the windows standard on size message use

DefWindowProc(WM_SIZE etc etc)

which bypasses the message mapping in MFC and just calls the window's procedure.

Darwen.
darwen at 2007-11-11 2:11:17 >
# 4 Re: Synchronize OnSize() call.
Sorry, what I meant to say was call base before calling all your reorganisation code.

If you look up WM_SIZE in MSDN it'll tell you what the WPARAM and LPARAM values should be.

Then you call DefWindowProc with WM_SIZE and these parameters if you don't want OnSize(...) to be called.

Darwen.
darwen at 2007-11-11 2:12:22 >
# 5 Re: Synchronize OnSize() call.
Originally posted by darwen
Sorry, what I meant to say was call base before calling all your reorganisation code.

If you look up WM_SIZE in MSDN it'll tell you what the WPARAM and LPARAM values should be.

Then you call DefWindowProc with WM_SIZE and these parameters if you don't want OnSize(...) to be called.

Darwen.

Hi Darwen,

this sounds very interesting, could you please send me any example code, which shows what I have to do exactely.

thanks a lot
rgwerder
rgwerder at 2007-11-11 2:13:24 >