Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » CExtWA & CFormView Collapse All
Subject Author Date
Leon Miller Jan 12, 2007 - 4:17 PM

Can CExtWA be used with CFormView? i.e:

class CSampleView : public CExtWS < CExtWA < CExtAFV < CFormView > > > ??

I am trying to get a CExtTabPageContainerFlatWnd to consume all of the space occupied by the CFormView. It does resizes when the frame window is resized, but it does not use all the available space.

I am really not sure where to place the AddAnchor(...) function call, other than it cannot be placed in the CFormView::OnInitialUpdate()!

Using VC 7.1, with ProfUIS 2.54(full version)...

Here is what I am trying to do:


class CSampleView: public CExtWS < CExtWA < CExtAFV < CFormView > > >

{
protected: // create from serialization only
    CSampleView();
    DECLARE_DYNCREATE(CSampleView)

    CExtTabPageContainerFlatWnd m_wndTabPageContainerFlat;
    CExtResizableDialog m_wndDlg1, m_wndDlg2, m_wndDlg3;

public:
    enum{ IDD = IDD_SAMPLE_FORM };

// Attributes
public:
    CSampleDoc* GetDocument() const;

// Operations
public:

// Overrides
    public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    virtual void OnInitialUpdate(); // called first time after construct

// Implementation
public:
    virtual ~CSampleView();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
    DECLARE_MESSAGE_MAP()
public:
    afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
};

#ifndef _DEBUG // debug version in SampleView.cpp
inline CSampleDoc* CSampleView::GetDocument() const
{ return reinterpret_cast<CSampleDoc*>(m_pDocument); }
#endif





// SampleView.cpp : implementation of the CSampleView class
//

#include "stdafx.h"
#include "Sample.h"

#include "SampleDoc.h"
#include "SampleView.h"
#include ".\sampleview.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CSampleView

IMPLEMENT_DYNCREATE(CSampleView, CFormView)

BEGIN_MESSAGE_MAP(CSampleView, CFormView)
    ON_WM_HSCROLL()
    ON_WM_SIZE()
    ON_WM_VSCROLL()
END_MESSAGE_MAP()

// CSampleView construction/destruction

CSampleView::CSampleView()
    : CExtWS < CExtWA < CExtAFV < CFormView > > > (CSampleView::IDD, (CWnd*) NULL)
{
    // TODO: add construction code here

}

CSampleView::~CSampleView()
{
}

void CSampleView::DoDataExchange(CDataExchange* pDX)
{
    CFormView::DoDataExchange(pDX);
    DDX_Control( pDX, IDC_TAB_PAGE_CONTAINER, m_wndTabPageContainerFlat );

}

BOOL CSampleView::PreCreateWindow(CREATESTRUCT& cs)
{
    BOOL bPreCreated = TRUE;
    bPreCreated = CFormView::PreCreateWindow(cs);
    if( !bPreCreated )
        return FALSE;

    // TODO: Modify the Window class or styles here by modifying
    // the CREATESTRUCT cs

    cs.style |= WS_CLIPSIBLINGS;


    return bPreCreated;
}

void CSampleView::OnInitialUpdate()
{
    CExtWS<CExtWA<CExtAFV<CFormView> > >::OnInitialUpdate();
//    CFormView::OnInitialUpdate();
    ShowSizeGrip(false);

    if( !m_wndDlg1.Create(
        IDD_DIALOG1,
        &m_wndTabPageContainerFlat
        )
        )
    {
        TRACE0("Failed to create m_wndDlg1\n");
    }
    m_wndDlg1.ShowSizeGrip( FALSE );
    if( !m_wndDlg2.Create(
        IDD_DIALOG2,
        &m_wndTabPageContainerFlat
        )
        )
    {
        TRACE0("Failed to create m_wndDlg2\n");
    }
    m_wndDlg2.ShowSizeGrip( FALSE );
    if( !m_wndDlg3.Create(
        IDD_DIALOG3,
        &m_wndTabPageContainerFlat
        )
        )
    {
        TRACE0("Failed to create m_wndDlg3\n");
    }
    m_wndDlg3.ShowSizeGrip( FALSE );

    VERIFY( m_wndTabPageContainerFlat.PageInsert( &m_wndDlg1, _T("Dialog 1") ) );
    VERIFY( m_wndTabPageContainerFlat.PageInsert( &m_wndDlg2, _T("Dialog 2") ) );
    VERIFY( m_wndTabPageContainerFlat.PageInsert( &m_wndDlg3, _T("Dialog 3") ) );
    GetParentFrame()->RecalcLayout();
    ResizeParentToFit();
}


// CSampleView diagnostics

#ifdef _DEBUG
void CSampleView::AssertValid() const
{
    CFormView::AssertValid();
}

void CSampleView::Dump(CDumpContext& dc) const
{
    CFormView::Dump(dc);
}

CSampleDoc* CSampleView::GetDocument() const // non-debug version is inline
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSampleDoc)));
    return (CSampleDoc*)m_pDocument;
}
#endif //_DEBUG


// CSampleView message handlers

void CSampleView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    // TODO: Add your message handler code here and/or call default

//    CExtWS<CExtWA<CExtAFV<CFormView> > >::OnHScroll(nSBCode, nPos, pScrollBar);
    CView::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CSampleView::OnSize(UINT nType, int cx, int cy)
{
//    CExtWS<CExtWA<CExtAFV<CFormView> > >::OnSize(nType, cx, cy);
    CView::OnSize(nType, cx, cy);
    // TODO: Add your message handler code here
}

void CSampleView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    // TODO: Add your message handler code here and/or call default

//    CExtWS<CExtWA<CExtAFV<CFormView> > >::OnVScroll(nSBCode, nPos, pScrollBar);
    CView::OnVScroll(nSBCode, nPos, pScrollBar);
}


int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    ...


    if (CExtNCW < CFrameWnd >::OnCreate(lpCreateStruct) == -1)
        return -1;

// create a view to occupy the client area of the frame
    CCreateContext _cc;
    _cc.m_pCurrentDoc = NULL;
    _cc.m_pCurrentFrame = this;
    _cc.m_pLastView = NULL;
    _cc.m_pNewDocTemplate = NULL;
    _cc.m_pNewViewClass = RUNTIME_CLASS( CSampleView );
    CWnd * pWndView = CreateView( &_cc );
    if( pWndView == NULL )
    {
        TRACE0("Failed to create view window\n");
        return -1;
    }
    ASSERT_KINDOF( CSampleView, pWndView );
    CSampleView * pChildView =    STATIC_DOWNCAST( CSampleView, pWndView );
    SetActiveView( pChildView );
    pWndView->ModifyStyleEx( WS_EX_CLIENTEDGE|WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME, 0, SWP_FRAMECHANGED );


    ...


    RecalcLayout();
    pChildView->AddAnchor(IDC_TAB_PAGE_CONTAINER, __RDA_LT, __RDA_RB);

    return 0;
}


I can send sample project and/or screen shots if necessary!!!
Thanks!

Suhai Gyorgy Jan 15, 2007 - 6:30 AM

The problem relates to the fact that the CChildView::OnSize is called even during running of CreateView in CMainFrame’s OnCreate. Surely before that point AddAnchor cannot be called as View is not even created yet. I examined the situation in Prof-UIS FunnyBars sample, I just had to added CExtWA template to generate the same situation as yours. I put a breakpoint in OnSize and stepped through the calls of CMainFrame::OnCreate to see when OnSize is called. It is called twice during CreateView and a couple of more times during ProfileBarStateLoad (when Toolbars’ states are set). CChildView::OnInitialUpdate is called after CMainFrame::OnCreate.

The solution that I found (there are probably more than one): In your .rc file set form’s and IDC_TAB_PAGE_CONTAINER’s height and width to 0, control’s top and left to 0 as well. Call pChildView->AddAnchor(IDC_TAB_PAGE_CONTAINER, __RDA_LT, __RDA_RB); right after CSampleView * pChildView = STATIC_DOWNCAST( CSampleView, pWndView ); The last call of OnSize before this AddAnchor changes the form’s size to (0,0) so size of control is the same as size of form at this point.

But actually why don’t you use CExtTabPageContainerFlatWnd as your CChildView’s base class? You can see how it’s done in SimpleGrid sample.