Solved

Disable dialog cancel box

Posted on 1998-02-09
7
348 Views
Last Modified: 2013-11-19
How can I disable the cancel box of a dialog on the upper right corner?
0
Comment
Question by:shibai
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:shogi
ID: 1315845
If you don't need : delete it.  

If you need for futur use put in the OnInitDialog() function :

   GetDlgItem(IDCANCEL)->EnableWindow ( FALSE );

this instruction will put your cancel in gray (false disabled and
true enabled)


0
 

Author Comment

by:shibai
ID: 1315846
I don't mean the cancel button. I mean the little box with an "X" on it on the upper right corner of a dialog.
0
 
LVL 4

Accepted Solution

by:
tflai earned 50 total points
ID: 1315847
1)  Add DefWindowProc() message handler to your dialog box.
2)  Catch message=WM_SYSMENU and wparam=SC_CLOSE and don't call the default handler.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:shogi
ID: 1315848
Sorry Shibai I mistaken your question

THE Answer of tflai, it's for C and not for MFC programming, and don't remove or GRAY the 'X' button.

In MFC you have many solutions for your problems, just choose the  one you need, because it's not clear :

1) If you use the DialogBox in resource :  Go in the dialog box   properties in Styles and remove the check in System menu.

2) If it's just a disable (gray) X button you what, put in your     OnInitDialog() function :

   CMenu * ptr_system;
   ptr_system = GetSystemMenu(FALSE);
   ptr_system->EnableMenuItem(1, MF_GRAYED | MF_BYPOSITION);


If you need something else, like for create modeless dialog, let me know...
0
 
LVL 4

Expert Comment

by:tflai
ID: 1315849
This is for MFC (disabling SC_CLOSE):

void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
  {
    if (nID == SC_CLOSE)
      return;
    else
      CDialog::OnSysCommand(nID, lParam);
  }

And yes, the following grayed it out:
    pSysMenu = GetSystemMenu(FALSE);
    pSysMenu->EnableMenu(SC_CLOSE,MF_GRAYED |                                                           MF_BYCOMMAND);

0
 
LVL 2

Expert Comment

by:shogi
ID: 1315850
tflai,

if you use this in OnSysCommand(), in the if you have on error
you need to write :

if ((nID & 0xfff0) == SC_CLOSE)
  return;
else
  CDialog::OnSysCommand(nID, lParam)

Just becarefull all the SC_ constant need a mask 0xfff0, otherwise you will have some surprise.

0
 

Author Comment

by:shibai
ID: 1315851
Thanks, tflai! Thanks, shogi, you are great!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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