Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

Disable dialog cancel box

How can I disable the cancel box of a dialog on the upper right corner?
0
shibai
Asked:
shibai
  • 3
  • 2
  • 2
1 Solution
 
shogiCommented:
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
 
shibaiAuthor Commented:
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
 
tflaiCommented:
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
Technology Partners: 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!

 
shogiCommented:
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
 
tflaiCommented:
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
 
shogiCommented:
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
 
shibaiAuthor Commented:
Thanks, tflai! Thanks, shogi, you are great!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now