Thread: Assertion error when looking for window handle

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    Assertion error when looking for window handle

    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

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    This is because you are trying to get the window size before the window has been created. If you over-rode OnInitDialog(), you could then call GetClientRect() in the OnCreate() handler with a valid m_hWnd.
    Last edited by bithub; 02-03-2005 at 03:40 PM.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Oops, I dont think you can over-ride OnInitDialog() for a CFormView. I think the correct function to over-ride is OnInitialUpdate().

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    that works. Thanks
    Amish

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with setting text into LTEXT using Window Handle
    By jasperleeabc in forum Windows Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM