Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Disable "close" menu items

Posted on 2002-04-12
5
Medium Priority
?
225 Views
Last Modified: 2013-11-20
I have a MDI window applications. Each child window have it's own set of thread and if these thread are running and user close window (by click on the cross button of system menu, or  on menu File_Exit) it may lead to an error cos some my threads are not completly stopped.

How to disable the system menu buttons and File_Exit, I want to avoid user close program until they stop the processing threads ?
0
Comment
Question by:ahTri
  • 3
5 Comments
 
LVL 2

Expert Comment

by:manojbkumar
ID: 6936242
Write the WM_SYSCOMMAND handler in your CChildFrame class and check for SC_CLOSE

In ChildFrm.h add
///////////////////////////////////////////////////
protected:
     //{{AFX_MSG(CChildFrame)
          // NOTE - the ClassWizard will add and remove member functions here.
          //    DO NOT EDIT what you see in these blocks of generated code!
     //}}AFX_MSG
     DECLARE_MESSAGE_MAP()
     afx_msg void OnSysCommand( UINT nID, LPARAM lParam );
/////////////////////////////////////

In ChildFrm.cpp
//////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
     //{{AFX_MSG_MAP(CChildFrame)
          // NOTE - the ClassWizard will add and remove mapping macros here.
          //    DO NOT EDIT what you see in these blocks of generated code !
     //}}AFX_MSG_MAP
     ON_WM_SYSCOMMAND()
END_MESSAGE_MAP()
/////////////////////////////////////////////

//////////////////////////////////
void CChildFrame::OnSysCommand( UINT nID, LPARAM lParam )
{
     if(nID == SC_CLOSE )
     {
          //Close button pressed
                //Close your threads or
          return;
     }
     CMDIChildWnd::OnSysCommand( nID,lParam );
}
///////////////////////////////////////
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 200 total points
ID: 6939644
Alternative: disable the button and the menu command:

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


-- Dan
0
 

Author Comment

by:ahTri
ID: 6940862
Although manojbkumar's comment gave me a fair bit of useful information , DanRollins' comment is more directly answer my question.

Thanks
0
 

Author Comment

by:ahTri
ID: 6943754
Hi DanRollins,

I can get the system menu from CChildFrame, but how to get the system menu from a sub class of CDocument or CView ? Say my classes are CDifarDocument and CDifarView

From CDifarDocument I get the CDifarView, and from CDifarView get the system menu but fail the ASSERT(pSysMenu != NULL);

0
 

Author Comment

by:ahTri
ID: 6943770
Or how to get the CChildFrame from CDifarDocument or CDifarView ?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question