Solved

Disable dialog cancel box

Posted on 1998-02-09
7
345 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

706 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

17 Experts available now in Live!

Get 1:1 Help Now