hi,
I tried implementing a tab control in an SDI document using a CFormView class but I am getting an assertion error:
This is the code I am using:
Code:
// RemoteView.cpp : implementation of the CRemoteView class
//
#include "stdafx.h"
#include "Remote.h"
#include "RemoteDoc.h"
#include "RemoteView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CRemoteView
IMPLEMENT_DYNCREATE(CRemoteView, CFormView)
BEGIN_MESSAGE_MAP(CRemoteView, CFormView)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnTabChange)
END_MESSAGE_MAP()
// CRemoteView construction/destruction
CRemoteView::CRemoteView()
: CFormView(CRemoteView::IDD)
{
// TODO: add construction code here
CRect r;
TCITEM tci;
// get dimensions of client area
GetClientRect(&r);
// create tab control
theTabControl.Create(WS_VISIBLE | WS_CHILD,r, this, IDC_TAB1);
tci.mask = TCIF_TEXT;
tci.iImage = -1;
tci.pszText = "One";
theTabControl.InsertItem(0, &tci);
tci.pszText = "Two";
theTabControl.InsertItem(1, &tci);
tci.pszText = "Three";
theTabControl.InsertItem(2, &tci);
}
CRemoteView::~CRemoteView()
{
}
void CRemoteView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
}
BOOL CRemoteView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CRemoteView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit(false);
//initializeTabs();
}
// CRemoteView message handlers
afx_msg void CRemoteView::OnTabChange(NMHDR *hdr,LRESULT *NotUsed)
{
CClientDC DC(this);
char str[255];
wsprintf(str, "Changed to Tab %d ",
theTabControl.GetCurSel()+1);
DC.SetBkColor(RGB(200, 200, 200));
DC.TextOut(40, 100, str, strlen(str));
}
The assertion is occuring in the constructor when GetClientRect(&r) is run.
The assertion error is occuring here:
Code:
_AFXWIN_INLINE void CWnd::GetClientRect(LPRECT lpRect) const
{ ASSERT(::IsWindow(m_hWnd)); ::GetClientRect(m_hWnd, lpRect); }
It seems it can't find m_hWnd. I was wondering if anybody knew a way around that or could explain why it is so. Thanks
Amish