Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 659031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:59:55+00:00 2026-05-13T22:59:55+00:00

I made an MFC application, and now i want to turn off the window’s

  • 0

I made an MFC application, and now i want to turn off the window’s close button during i do my copy operations. I did it successfull with this code:

BOOL bEnable = FALSE;    // To disable

UINT menuf = bEnable ? (MF_BYCOMMAND) : (MF_BYCOMMAND | MF_GRAYED | MF_DISABLED);

CMenu* pSM = GetSystemMenu(  , FALSE );
if ( pSM )
{
  pSM->EnableMenuItem( SC_CLOSE, menuf );
}

But now, at the end of my program in my thread ( UINT CopyThread( LPVOID pParam ) ) i want to reenable it, but i can’t. I passed earlier to my thread the m_hWnd, and now i wan’t to pass this to the GetSystemMenu function but i get a compiler error : error C2440: ‘initializing’ : cannot convert from ‘HMENU’ to ‘CMenu *’. I’m sure that this is an easy question, but i’m a beginner, so please help, but i can’t figure it out, what i’m doing worng!

Thanks in advance!

kampi

Update:
I tried this way, which almost works. The Close “X” will be black again, but if i press it, my program doesn’t exists. Am i doing something wrong, or this is because something else?

BOOL bEnable = TRUE;     // To enable
UINT menuf = bEnable ? (MF_BYCOMMAND) : (MF_BYCOMMAND | MF_GRAYED | MF_DISABLED);

HMENU pSM = ::GetSystemMenu( Test->hWnd, FALSE );
if ( pSM )
{
    ::EnableMenuItem(pSM, SC_CLOSE, menuf );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:59:56+00:00Added an answer on May 13, 2026 at 10:59 pm
    1. There is an easy way to disable ‘close’ menu in the system. Please add the bit of CS_NOCLOSE into the class style. You may change the class style by using SetClassLong.

    2. Why don’t you just use Win32 API, not MFC function? For example, just use ::GetSystemMenu that returns HMENU. In general, you can create CMenu from the HMENU by CMenu::FromHandle, but in such simple case, it’s much better to use directly Win32 API.

    Please note that the mapping between MFC objects (e.g., CMenu, CWnd) and Win32 Handles (e.g., HMENU, HWND) is somewhat complex. The reason why I said it complex is there are two types of the mapping: temporal and permanent. If you make CMenu by calling CMenu::FromHandle, it is a temporary mapping; the mapping will be disconnected (i.e., CMenu object will be deleted) when the idle handler (OnIdle) is called next time. On the contrary, if you create a CWnd object and create an actual Window (note that MFC doesn’t automatically create a real Window object by just creating CWnd), then there is a permanent mapping between CWnd and HWND.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a MFC SDI application in Visual Studio 2010 and want to
I'm doing an application using MFC. I just made a class that is derived
I have a normal Windows GUI application (made using the API, not MFC) and
I'm working on an MFC application, I want to make a global string variable
Made a custom post type, Events, great. Now I want to get a second
How can I print a document using MFC Dialog Based Application? I have made
I made an application that passes trough an XML file and extracts the entries
I'm trying to rebuild an old metronome application that was originally written using MFC
I am building a textEdit application with MFC. Is there a way to create
I want to pop up a window to show that a program is busy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.