Solved

Disable "close" menu items

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 106
Expand data scrubbing tool 13 32
List out all word 7 261
fizzArray  challenge 1 63
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

15 Experts available now in Live!

Get 1:1 Help Now