Crash when using embedded CPropertySheet (focus issue). 
Author Message
 Crash when using embedded CPropertySheet (focus issue).

Hi All,

I've got an application that uses a CPropertyPage in a CDialog.

The property page contains a CListCtrl. I use items on the list
control to open another (modeless) dialog. Users can either double
click on an item, or select the item and click on a button.

Both methods of navigation work fine in the debug version, without any
warnings or errors. The second method also works fine in the release
version, but double clicking on a list item (in the release version)
will get as far as opening the window and populating it with data from
the DB, then, as soon as control passes back to the main message loop,
the application crashes.

I've already had focus problems with this setup - I had to set the
properties of the CPropertySheet to prevent it from getting stuck in
an infinite loop when relinquishing focus (see code below).

If this is a focus issue, what is the right way of opening the window?

- Nick.

BOOL CAccountDetailsRelated::PreTranslateMessage(MSG* pMsg)
{
        // since CPropertySheet::PreTranslateMessage will eat frame window
        // accelerators, we call all frame windows' PreTranslateMessage
first.
        CFrameWnd* pFrameWnd = GetParentFrame();   // start with first parent
frame
        while (pFrameWnd != NULL)
        {
                // allow owner & frames to translate before IsDialogMessage does
                if (pFrameWnd->PreTranslateMessage(pMsg))
                        return TRUE;

                // try parent frames until there are no parent frames
                pFrameWnd = pFrameWnd->GetParentFrame();
        }

        // otherwise, just let the sheet translate the message  
        return CPropertySheet::PreTranslateMessage(pMsg);

Quote:
}

BOOL CAccountDetailsRelated::OnInitDialog()
{
        // Prevent the CPropertySheet from recursively looping, when trying
to
        // find the control that previously had the focus.
        //
        // NOTE: This bug is the result of a CPropertySheet assuming that
        // CPropertySheet will always have the focus within itself (which
        // is not true if it is embeded in another dialog box.)
        ModifyStyleEx( 0, WS_EX_CONTROLPARENT );

        BOOL bResult = CPropertySheet::OnInitDialog();

        return bResult;

Quote:
}



Fri, 16 Apr 2004 05:45:42 GMT  
 Crash when using embedded CPropertySheet (focus issue).
Hi, Nicholas!

Do you by any chance use any ON_MESSAGE macros in your MESSAGE_MAP, and if so are they all
prototyped like...

    LRESULT memberfxn(WPARAM, LPARAM);

If so, MSDN Article Q195032, "PRB: Incorrect Function Signatures May Cause Problems in Release",
might provide a bit more info. Anyway...

HTH,

Jeff...
--
Please post all follow-ups to the newsgroup only.


Quote:
> Hi All,

> I've got an application that uses a CPropertyPage in a CDialog.

> The property page contains a CListCtrl. I use items on the list
> control to open another (modeless) dialog. Users can either double
> click on an item, or select the item and click on a button.

> Both methods of navigation work fine in the debug version, without any
> warnings or errors. The second method also works fine in the release
> version, but double clicking on a list item (in the release version)
> will get as far as opening the window and populating it with data from
> the DB, then, as soon as control passes back to the main message loop,
> the application crashes.

> I've already had focus problems with this setup - I had to set the
> properties of the CPropertySheet to prevent it from getting stuck in
> an infinite loop when relinquishing focus (see code below).

> If this is a focus issue, what is the right way of opening the window?

> - Nick.

> BOOL CAccountDetailsRelated::PreTranslateMessage(MSG* pMsg)
> {
> // since CPropertySheet::PreTranslateMessage will eat frame window
> // accelerators, we call all frame windows' PreTranslateMessage
> first.
> CFrameWnd* pFrameWnd = GetParentFrame();   // start with first parent
> frame
> while (pFrameWnd != NULL)
> {
> // allow owner & frames to translate before IsDialogMessage does
> if (pFrameWnd->PreTranslateMessage(pMsg))
> return TRUE;

> // try parent frames until there are no parent frames
> pFrameWnd = pFrameWnd->GetParentFrame();
> }

> // otherwise, just let the sheet translate the message
> return CPropertySheet::PreTranslateMessage(pMsg);
> }

> BOOL CAccountDetailsRelated::OnInitDialog()
> {
> // Prevent the CPropertySheet from recursively looping, when trying
> to
> // find the control that previously had the focus.
> //
> // NOTE: This bug is the result of a CPropertySheet assuming that
> // CPropertySheet will always have the focus within itself (which
> // is not true if it is embeded in another dialog box.)
> ModifyStyleEx( 0, WS_EX_CONTROLPARENT );

> BOOL bResult = CPropertySheet::OnInitDialog();

> return bResult;
> }



Fri, 16 Apr 2004 06:44:05 GMT  
 Crash when using embedded CPropertySheet (focus issue).
Hi Jeff,

Quote:
> Do you by any chance use any ON_MESSAGE macros in your MESSAGE_MAP, and if so
> are they all prototyped like...

>    LRESULT memberfxn(WPARAM, LPARAM);

Thanks for the tip, I wasn't aware of that one, and bet I've commited
that sin before. Unfortunately I only have one ON_MESSAGE handler
defined and, ironcially, I added it as an attempt to work around the
original crash!

The actual error is an access violation (0xC0000005) so this may be
unrelated, though anything that happens consistently in the release
build, and never in the debug build must come from a small sub-set of
possible bugs.

Can anyone tell me what the dis-advantages of deploying the debug
build would be, if it comes to that?

- Nick.



Sat, 17 Apr 2004 04:36:02 GMT  
 Crash when using embedded CPropertySheet (focus issue).
Hi Jeff,

You were exactly right. The problem was definately caused by function
signatures.

What I actually did was allowed two ways of navigating to a different
screen. Users could either double click on a list item, or select a
list item and then click a button on the dialog.

However BOTH functions called the same message call back. Even though
the function did not use any of the input parameters, and both
functions return void, the release version was most unhappy about
calling the same function from different handlers.

Fair enough, the signatures are a little different...

void CRelatedPartiesPP::OnButtonClick();

vs.

void CRelatedPartiesPP::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)

Oh God! I probably even set that pResult.  Slaps on the hand for me!

:]

Cheers,
Nick.



Sat, 17 Apr 2004 06:58:01 GMT  
 Crash when using embedded CPropertySheet (focus issue).
You can't deploy any of the debug DLLs. They are not redistributable.
Hint: NEVER create an app that requires being compiled in debug mode
to function correctly! It means you have a deep and serious bug that
is simply being masked by some random feature of the debug build. A
trivial change in your code could make it a problem, but six months
later when you have forgotten you had a problem.

See my essay on Surviving the Release Build on my MVP Tips site.
                        joe



Quote:
>Hi Jeff,

>> Do you by any chance use any ON_MESSAGE macros in your MESSAGE_MAP, and if so
>> are they all prototyped like...

>>    LRESULT memberfxn(WPARAM, LPARAM);

>Thanks for the tip, I wasn't aware of that one, and bet I've commited
>that sin before. Unfortunately I only have one ON_MESSAGE handler
>defined and, ironcially, I added it as an attempt to work around the
>original crash!

>The actual error is an access violation (0xC0000005) so this may be
>unrelated, though anything that happens consistently in the release
>build, and never in the debug build must come from a small sub-set of
>possible bugs.

>Can anyone tell me what the dis-advantages of deploying the debug
>build would be, if it comes to that?

>- Nick.

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Sat, 24 Apr 2004 00:56:07 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Crashes When Using CPropertySheet as Main Window - Help!

2. Child CPropertySheet Focus Problem

3. Embed modeless CPropertySheet object in a view

4. Embedding: CPropertySheet in CPropertyPage

5. CPropertySheet's caption focused - doesnt catch accelerator messages for main frame

6. Losing focus with CPropertySheet

7. CPropertySheet/Page Button Focus problem

8. ActiveX with CPropertySheet and focus problem

9. CPropertySheet - focus of the Back button

10. Embedded CPropertySheet - CTabCtrl doesn't reflect EnableWindow(FALSE)

11. CPropertySheet and Focus

12. Embedded CPropertySheet and tab order

 

 
Powered by phpBB® Forum Software