error on second dialog Create

This is a discussion on error on second dialog Create within the C++ Programming forums, part of the General Programming Boards category; when i create a window, destroy it then create it again i get error pointing to: Code: BOOL CGdiObject::Attach(HGDIOBJ hObject) ...

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

    Question error on second dialog Create

    when i create a window, destroy it then create it again i get error pointing to:
    Code:
    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:
    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());
    		m_CTS.ShowWindow(SW_SHOW);
    	}
    	else
    	{
    		m_CTS.ShowWindow(SW_RESTORE);
    		m_CTS.SetForegroundWindow();
    	}
    }
    anybody know why do i get this error? Thanks.

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

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,752
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    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, 01:49 PM
  3. Dialog Box Resources
    By Mecnels in forum Windows Programming
    Replies: 2
    Last Post: 04-28-2003, 06:57 AM
  4. Dialog Box & Property Sheet :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 02:33 PM
  5. Simple Dialog Box (noob)
    By tegwin in forum Windows Programming
    Replies: 6
    Last Post: 06-30-2002, 07:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21