Solved

Disable "close" menu items

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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: 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 …
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

813 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

11 Experts available now in Live!

Get 1:1 Help Now