Solved

Disable "close" menu items

Posted on 2002-04-12
5
218 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 50 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now