Thread: error on second dialog Create

  1. #1
    Registered User
    Join Date
    Dec 2004

    Question error on second dialog Create

    when i create a window, destroy it then create it again i get error pointing to:
    BOOL CGdiObject::Attach(HGDIOBJ hObject)
    this line ->	ASSERT(m_hObject == NULL);      // only attach once, detach on destroy
    	if (hObject == NULL)
    		return FALSE;
    	CHandleMap* pMap = afxMapHGDIOBJ(TRUE); // create map if not exist
    	ASSERT(pMap != NULL);
    	pMap->SetPermanent(m_hObject = hObject, this);
    	return TRUE;
    this is my code:
    header file:
    CCTS m_CTS;
    cpp file in a menu command event:
    void CChateXDlg::OnMCTS() 
    	if(IsWindow(m_CTS.GetSafeHwnd()) == FALSE)
    		m_CTS.Create(IDD_CTS_DIALOG, GetDesktopWindow());
    anybody know why do i get this error? Thanks.

    edit: doesnt matter i fixed it
    Last edited by eXistenZ; 08-16-2005 at 03:49 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Do you
    m_hObject = NULL;
    Immediately after you free it?
    Otherwise, it may think you've still got the old one when you're trying to get a new one.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2004
    its fixed look what happened i have a class CLabel derived CStatic that is on the CTS dialog and on PreSubclassWindow i create a font which is declared in the header, problem is i didnt think that when destroying the dialog the class is not destroyed so the font was created 2 times that was the error i just used m_font.DeleteObject(); and that fixed it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  2. Dialog Boxes
    By Thantos in forum Windows Programming
    Replies: 7
    Last Post: 08-26-2003, 12:49 PM
  3. Dialog Box Resources
    By Mecnels in forum Windows Programming
    Replies: 2
    Last Post: 04-28-2003, 05:57 AM
  4. Dialog Box & Property Sheet :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 01:33 PM
  5. Simple Dialog Box (noob)
    By tegwin in forum Windows Programming
    Replies: 6
    Last Post: 06-30-2002, 06:04 PM