Solved

Disable "close" menu items

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 96
Complete beginner needs help making a cron job 9 125
EvenOdd challenge 10 128
wordcount challenge 11 134
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

821 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