CMFCButton导致PropertySheet窗口关闭

用户遇到在CPropertySheet中使用CMFCButton控件导致应用程序立即关闭的问题,该问题在VS2010 SP1中出现,通过使用VS2012或改为CButton解决了此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

google keyword: CMFCButton breaks MFC applications with CPropertySheet

背景:

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

现象:

窗口一闪而过,立刻关闭

问题:

目前认定这是 vs2010 sp1 的一个bug

  • 对于其他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=vclanguage

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/cmnctrl

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.

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

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:

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...

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!

转载于:https://www.cnblogs.com/kevinzhwl/p/3896562.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值