CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Oct 2002
    Posts
    209

    Modeless Property Sheet causing crash

    Hi All,

    I have a CPropertySheet class with 3 tabs.
    I have put in the workaround below to make it modeless.
    Howver when I press Alt+Tab to change application it crashes.
    Has anyone seen anything similiar?

    Many thanks.

    Code:
    	m_bModeless = FALSE;
    	m_nFlags |= WF_CONTINUEMODAL;
    
    	BOOL bResult = CPropertySheet::OnInitDialog();
    
    	m_bModeless = TRUE;
    	m_nFlags &= ~WF_CONTINUEMODAL;

  2. #2
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Modeless Property Sheet causing crash

    Why did you have to do that? Call Create member instead.
    If your property sheet is a child of another window you problem most likely due to infinite loop that property sheet is entering trying to restore focus, not a crush.

    If that is a case it can be fixed by specifying extended style: WS_EX_CONTROLPARENT passed in Create function.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  3. #3
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: Modeless Property Sheet causing crash

    m_bModeless = FALSE;
    m_nFlags |= WF_CONTINUEMODAL;

    BOOL bResult = CPropertySheet::OnInitDialog();

    m_bModeless = TRUE;
    m_nFlags &= ~WF_CONTINUEMODAL;
    Oh, good reasons why not to make member variables public or even protected. Don't let those who derive from you shoot themselves in the foot.

    I don't think you're supposed to call OnInitDialog() implicitly. It gets called from a DoModal call. (Would be best if the method were private).

  4. #4
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Modeless Property Sheet causing crash

    Quote Originally Posted by NMTop40
    I don't think you're supposed to call OnInitDialog () implicitly.
    NMTop40 calls CPropertySheet implementation of OnInitDialog and this call is essential. This holds true also for property pages and dialogs. Base class implementation make necessary calls to initialize all created controls and calls UpdateData to transfer data and subclass controls by invoking DDX.
    Quote Originally Posted by NMTop40
    It gets called from a DoModal call. (Would be best if the method were private).
    I do not agree.
    Firstly, OnInitDialog is not called from DoModal but from WM_INITDIALOG message handler. WMINITDIALOG message is send to a dialog by the system as a result of any API call that creates modal or non modal dialog, after dialog and controls are created.
    DoModal is sole MFC implementation of creating modal dialog box that is not really modal. WM_INITDIALOG is a system generated message.

    Secondly, OnInitDialog virtual override gives derived class chance to initialize own data and controls. Making virtual function as private defeats its purpose.

    As you can see encapsulating everything is not always the best idea.

    Nevertheless the way NMTop40 created modeless property sheet remains a mystery.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  5. #5
    Join Date
    Oct 2002
    Posts
    209

    Re: Modeless Property Sheet causing crash

    The seems to be where it crashes

    BOOL CWnd::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)

    const AFX_MSGMAP* pMessageMap; pMessageMap = GetMessageMap();

    BOOL CWnd::OnWndMsg(6, 0, 0, pointer to 0)

  6. #6
    Join Date
    Oct 2002
    Posts
    209

    Re: Modeless Property Sheet causing crash

    BTW This is a Microsoft fix http://support.microsoft.com/kb/q146916/
    How do I know what message == 6 means above?

  7. #7
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Modeless Property Sheet causing crash

    I fail to understand what this article has to do with crashing problem.
    WM_ACTIVATE = 6.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  8. #8
    Join Date
    Oct 2002
    Posts
    209

    Re: Modeless Property Sheet causing crash

    I thought people suggested it was not a good way to make a property sheet modeless. I was just saying it is the MS way.

    When is WM_ACTIVATE called?
    Can I override this in someway?

  9. #9
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Modeless Property Sheet causing crash

    Why would you want to?
    You are creating modeless property sheet by calling Create instead of DoModal.
    The code is for inserting default buttons that modeless property sheet does not have by fooling property sheet into thinking it creates modal.
    Do you really need buttons in non modal propery sheet?

    I am pretty sure your problem is elsewhere and if you read my previous post and apply extended style change, your problem most likely will go away. Did you try it?

    If after that you still have problem post your entire project here.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  10. #10
    Join Date
    Oct 2002
    Posts
    209

    Re: Modeless Property Sheet causing crash

    Code:
    void 
    CStrainInterfaceView::OnHardwareSetup()
    {
    	CStrainInterfaceDoc* pDoc = GetDocument();
    	
    	if(m_pHwSetupSheet != NULL)
    	{
    		m_pHwSetupSheet->DestroyWindow();
    		delete m_pHwSetupSheet;
    		m_pHwSetupSheet = NULL;
    	}	
    
    	if(m_pHwSetupSheet == NULL)
    	{
    		m_pHwSetupSheet = new CHardwareSetupTab;	
    		if(m_pHwSetupSheet != NULL)
    		{
    			m_pHwSetupSheet->ShowObjectiveLens(true);
    			m_pHwSetupSheet->ShowLightSource(true);
    			m_pHwSetupSheet->ShowPeltierSettling(true);
    			
    			m_pHwSetupSheet->SetDocumentName(pDoc->GetTitle());
    			m_pHwSetupSheet->BuildSheet();
    			if(m_pHwSetupSheet->Create(this, WS_EX_CONTROLPARENT) == false)
    			{
    				TRACE0("Failed to create hardware dialog\n");
    			}
    		}
    		else
    		{
    			TRACE0("Failed to 'new' hardware dialog\n");
    		}
    	}
    	
    	m_pHwSetupSheet->ShowWindow(SW_SHOW);
    Now it crashes at this line in creation

    if(m_pHwSetupSheet->Create(this, WS_EX_CONTROLPARENT) == false)

  11. #11
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Modeless Property Sheet causing crash

    What do you mean CRASHES?

    Are you getting any error messages?

    Besides all, you are trying to create property sheet with no windows style (WS_OVERLAPPED). You are passing extended style instead window style.

    You should pass extended style as third parameter of Create.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  12. #12
    Join Date
    Oct 2002
    Posts
    209

    Re: Modeless Property Sheet causing crash

    Ok I fixed the create so that the extended style is the 3rd param.

    Code:
    	if(m_pHwSetupSheet->Create(this, WS_SYSMENU | WS_POPUP | WS_CAPTION | DS_MODALFRAME | DS_CONTEXTHELP | WS_VISIBLE, 
    				WS_EX_CONTROLPARENT) == false)
    			{
    				TRACE0("Failed to create hardware dialog\n");
    			}
    but when I Alt-Tab I still get
    Attached Images Attached Images  

  13. #13
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Modeless Property Sheet causing crash

    I am afraid that I have exhausted my ability to guide you and without actually debugging your code I will not be able to assist you further.
    Are you running debug build? You should see similar message and button, allowing for debugging. After that you can step into a code, follow stack to the point in your code that causes this problem.
    Another way is to post your entire project here to allow debugging.

    Before you do, try to find any un-initialized or NULL pointer that usually is a culprit.
    Write test application as bare as possible using property sheet in the same manner and see if you can reproduce error.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured