zoukankan      html  css  js  c++  java
  • CMFCButton导致PropertySheet窗口关闭

    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.0Samples1033VC2010Samples.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!

  • 相关阅读:
    hdu 1402 大数A*B模板(FFT)
    ccpc 哈尔滨L题 LRU Algorithm
    今年得慢慢学的
    Codeforces Round #629 (Div. 3) E. Tree Queries(LCA)
    Codeforces Global Round 7 D2. Prefix-Suffix Palindrome (Hard version) -- manacher
    hdu 3068 (manacher算法)
    用Socket API建立简易tcp服务端和客户端
    Win下建立Socket时注意事项
    线段树(Segment Tree)
    Codeforces Round #643 (Div. 2)
  • 原文地址:https://www.cnblogs.com/kevinzhwl/p/3896562.html
Copyright © 2011-2022 走看看