Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » How can I disable items on the window menu ? Collapse All
Subject Author Date
Adrian Constantin Aug 26, 2004 - 6:44 AM


Hello

I have prof-uis 2.20 and I need to disable the Close command
in the system menu of a modal dialog. I use

ON_UPDATE_COMMAND_UI(SC_CLOSE, OnUpdateSystemClose)

macro in the message map definition as I do for items in my Context Menu
However my update handler function, OnUpdateSystemClose, is never called
as I can see with the debugger.

Can you please tell me how can I enable and disable the menu items on the window menu with prof-uis 2.20

I know there are new versions, but my manager can’t affort to migrate,
because our application is about to ship now

Thank you
Constantin Adrian

Sergiy Lavrynenko Aug 26, 2004 - 11:54 AM

Hi,

You have added the command updating handler for the WM_COMMAND message with SC_CLOSE identifier. But SC_CLOSE is the system command which is sent via WM_SYSCOMMAND message. So, your method will never be invoked by the MFC framework.

To handle system commands you should add the WM_SYSCOMMAND message handler like this:

    ON_WM_SYSCOMMAND()
 
    void CYourFrameOrDialoig::OnSysCommand(
        UINT nID,
        LPARAM lParam
        ) 
    {
        if(nID == SC_CLOSE )
        {
            if( bDoNotCloseThisWindow )
                return;
        }
        CParentClass::OnSysCommand(nID, lParam);
    }


There are no way to use MFC’s command updating mechanism within system commands. You should get the system menu and disable the SC_CLOSE item.

    CMenu * pSysMenu =
        GetSystemMenu( FALSE );
    if( pSysMenu != NULL )
        pSysMenu->EnableMenuItem(
            SC_CLOSE,
            MF_DISABLED
                |MF_GRAYED
                |MF_BYCOMMAND
            );

Adrian Constantin Aug 27, 2004 - 12:24 AM


I disabled the Close item with just MF_GRAYED and the Prof-UIS 2.20 menu did not follow.

I had to look into the sources and I found out that Prof-UIS knows about system commands in a menu and for them it doesn’t send update UI commands.

I ended up changing the command ID from SC_CLOSE to ID_FILE_CLOSE whenever I wanted to disable the Close item and changing it back from ID_FILE_CLOSE to SC_CLOSE to have the close box of the dialog window enabled back when I wanted to enable the ’Close’ menu item.

However I lost the small icon of the menu item with this aproach

I’ve seen Prof-UIS 2.20 disables some system menu items (restore, maximize) but however I did not have the time to further dig into the sources

Thank you anyway

Adrian Constantin

Technical Support Aug 29, 2004 - 1:02 PM

This is fixed in the later Prof-UIS versions. The popup menu analyzes the MF_DISABLED flag of the SC_CLOSE system command.