CMFCButton致使PropertySheet窗口關閉

google keyword: CMFCButton breaks MFC applications with CPropertySheetapp

背景:

在CPropertySheet中使用了CMFCButton或者其餘MFCxx系列的控件ssh

現象:

窗口一閃而過,馬上關閉ide

問題:

目前認定這是 vs2010 sp1 的一個bugoop

  • 對於其餘MFCx系列的控件,存在一樣的問題
  • 不管模態窗口仍是非模態窗口都存在該問題。

解決:

  • 使用 vs2012 進行構建
  • 不要在PropertSheet中使用MFCButton,改用CButton

http://social.msdn.microsoft.com/Forums/vstudio/en-US/9b45fd05-bfe2-4215-a1fb-8c16b7c5b33d/cmfcbutton-breaks-mfc-applications-with-cpropertysheet?forum=vclanguageui

Q

I am pretty new to MFC, but I am having a problem which I can reproduce on all samples I've tried so far. For instance, a perfect sample is the one located in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Samples\1033\VC2010Samples.zip/C++/MFC/controls/cmnctrlthis

If I just start that up and try to add a CMFCButton control to any of the sheets in the tab by simply dragging one from the toolbox and dropping it on any surface of for instance the IDD_COMMAND_LINK_CONTROL dialog resource window, and then try to run the application, it immediately shuts down. It compiles just fine.google

When debugging I can see that the problem lies in DoModal() of the CPropertySheet called allcontrolssheet:idea

BOOL CCmnCtrl3App::InitInstance()
{
    AfxEnableControlContainer();

    // Standard initialization

    CAllControlsSheet   allcontrolssheet(_T("Common Controls Sample"));
    m_pMainWnd = &allcontrolssheet;
    allcontrolssheet.DoModal();
    return FALSE;
}

More specifically, if I step into the DoModal() code, ending up in the dlgprop.cpp file, I can see that the code execution never enters the following if-clause on line 948, since the ContinueModal() function returns 0 or false:debug

if (ContinueModal())
{
    // enter modal loop
    DWORD dwFlags = MLF_SHOWONIDLE;
    if (GetStyle() & DS_NOIDLEMSG)
        dwFlags |= MLF_NOIDLEMSG;
    nResult = RunModalLoop(dwFlags);
}

However, as soon as the CMFCButton is removed, the application runs perfectly again. Also, it seems like if I do not use tabs (CPropertySheet), but instead just put a CMFCButton directly on a dialog window, everythiong works fine...3d

Can anyone try this and see if you also get this error, or if you have any ideas or know something from experience that I do not know yet? Would be very thankful for help.

(Using VS2010)

UPDATE:

However, I noticed that if I create a CButton instead in the designer and then create a control variable for it and finally programmatically change the type from CButton to CMFCButton the program does not close immediately(or if having multiple tabs, the tab with the button does not close in this case)

A

If I just start that up and try to add a CMFCButton control to any of the sheets in the tab by simply dragging one from the toolbox and dropping it on any surface of for instance the IDD_COMMAND_LINK_CONTROL dialog resource window, and then try to run the application, it immediately shuts down. It compiles just fine.

I don't see the same problem you mention.

When built with VS2010 SP1 the property sheet shows up, but as soon as I try to show the page that I've added the CMFCButton to (the IDD_COMMAND_LINK_CONTROL dialog as per your description), that page disappears.

Rebuilding the same sources with VS2012 and all is OK, so it's likely to be something MS are aware of and have subsequently fixed.

Confirm

Thanks for trying it out and helping! Yep, I am using VS2010 SP1 (haven't tried 2012). It seems that you get the same problem in VS2010. Good, then at least it is "confirmed".

Thanks for your time and effort!

相關文章
相關標籤/搜索