15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Disabling/Greying Close button (X) in MDI Child window

Tiago Gons -- tiago@ellips.nl
Friday, August 16, 1996

Environment:VC++ 4.2 , NT4.0 beta 2

The following in the PrecreateWindow routine in a CMDIChildWnd derived
class gives an assert:

CMenu* pMenu = GetSystemMenu(FALSE);

I can't remove WS_SYSMENU from cs.style because I want a minimize box.

    Tiago



Klaus Guetter -- 100031.1400@CompuServe.COM
Monday, August 19, 1996

[Mini-digest: 4 responses]

Tiago,

PreCreateWindow (as the name suggests...) is called before the window is
created.
Since the window is not yet there, GetSystemMenu can't possibly work.
A better place for this kind of work would be in OnCreate.

- Klaus

-----From: Lawrence_Chan@pcmailgw.ml.com

     Add a handler to OnInitMenuPopup and gray the CLOSE menu item:
     
                
     
     void CFrameEx::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL 
     bSysMenu) 
     {
        CMDIFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
        
        pPopupMenu->EnableMenuItem(SC_CLOSE,MF_DISABLED|MF_GRAYED);
        
     }
     

-----From: CMANNING@derwent.co.uk

     I had this problem too . I got round it by registering my own window 
     class with CS_NOCLOSE style set. You can do this by providing a 
     Create() override in your MDI child frame class, e.g:
     
     BOOL CCompFrame::Create(LPCTSTR lpszClassName, 
                             LPCTSTR lpszWindowName, 
                             DWORD dwStyle, 
                             const RECT& rect, 
                             CMDIFrameWnd* pParentWnd, 
                             CCreateContext* pContext) 
     {
        static CString strClass;
        if (strClass.GetLength() == 0)
            strClass = AfxRegisterWndClass(CS_DBLCLKS | CS_HREDRAW |
                                           CS_VREDRAW | CS_NOCLOSE, 
                                           ...); 
        return CMDIChildWnd::Create(strClass, lpszWindowName, 
                                    dwStyle, rect, pParentWnd, 
                                    pContext);
     }
     
     Then you get a greyed close box, but max and min work.
     
     Colin
-----From: Mario Contestabile

I implemented such a feature, when only one document exists, the 'X' is grayed,
else, it is enabled. The feature also had to work in the NT 3.51 interface,
and several hicks popped up while implementing the feature.
If you can't find the solution in the archive, I'll dig up the code and send
you a copy.

mcontest@universal.com

[Moderator's note: Several "hicks"?  Were any of them relatives of mine?  ;-]




| Вернуться в корень Архива |