[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Unable close button at window screen...

How to unable a "close button" at window screen at my program? TQ!
0
DannyGan9
Asked:
DannyGan9
  • 2
  • 2
1 Solution
 
bcsonkaCommented:
Hi,

Give this a shot in your OnInitDialog or OnInitialUpdate method:

=================================================================================

CMenu* systemMenu = GetSystemMenu(FALSE);

if(systemMenu)
{
      systemMenu->EnableMenuItem(SC_CLOSE, MF_BYCOMMAND | MF_DISABLED);
}

=================================================================================

I hope that helps.
0
 
DannyGan9Author Commented:

      CMenu* systemMenu = GetSystemMenu(FALSE);

      if(systemMenu)
      {
            systemMenu->EnableMenuItem(SC_CLOSE, MF_BYCOMMAND | MF_DISABLED);
      }


This shot i put at OnInitialUpdate() there, the window close button still can close....
Erm...i'm using MFC Single Form .....
Got any solution....
TQ!
0
 
bcsonkaCommented:
Hi,

Sorry about that.  Instead of adding that code to OnInitialUpdate, add it to CMainFrame::OnCreate().  Also, instead of MF_BYCOMMAND | MF_DISABLED for the second parameter in EnableMenuItem, change it to MF_BYCOMMAND | MF_GRAYED | MF_DISABLED.  This will gray out and disable the option to close from the taskbar as well.

I hope that helps.
0
 
DannyGan9Author Commented:
My solution is:

//add this at

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{

     CMenu *pmenu = GetSystemMenu(FALSE);
     pmenu->EnableMenuItem(SC_CLOSE, MF_BYCOMMAND | MF_DISABLED|MF_GRAYED);
}


It can work...anywhere thanks!
0

Featured Post

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!

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