Thread: Disable the X button

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    215

    Disable the X button

    Does anyone know how to disable the X button at the top of the screen so the user cannot exit the program through that route?

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Code:
    case WM_CLOSE:
      if (MessageBox(hwnd,_T("sure?"),_T("Quit"),MB_YESNO|MB_APPLMODAL)==IDYES)
        {
        DestroyWindow(hwnd);
        }
      return 0;
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Quote Originally Posted by Ken Fitlike
    if (MessageBox(hwnd,_T("sure?"),_T("Quit"),MB_YESNO|M B_APPLMODAL);
    I often see: _T("some string"). Is this because of UNICODE?.
    If it is why not using TEXT("some string")??

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    17
    _T does the same thing as TEXT if I remember correctly and I think people use _T because it's shorter.

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can also add CS_NOCLOSE to the class style when you register the window class (with RegisterClassEx).

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    215
    Hey anon, I tried doing it for my dialog box, but it wont work

    Code:
    IDD_CHANNEL_TIME DIALOG 0, 0, 400, 200
    STYLE DS_SYSMODAL | DS_MODALFRAME |WS_POPUP| WS_VISIBLE | WS_CAPTION | WS_MINIMIZEBOX|WS_SYSMENU|CS_NOCLOSE
    CAPTION "Channels"
    LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
    FONT 8, "MS Sans Serif"
    Last edited by osal; 08-12-2004 at 04:50 PM.

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    CS_NOCLOSE is a class style. You can specify it in the WNDCLASSEX structure when you register a window class.
    Code:
    WNDCLASSEX wc = { 0 };
    wc.style = CS_NOCLOSE;
    ...
    RegisterClassEx(&wc);
    Since you don't register a class for dialog boxes, you won't be able to use CS_NOCLOSE.

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    215
    What can i use for a dialog box then?

  9. #9
    Registered User
    Join Date
    May 2004
    Posts
    215
    nevermind, i got it!

    here's the code:

    Code:
    hMenu = GetSystemMenu(hwnd, FALSE);
     EnableMenuItem (hMenu , SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);

  10. #10
    Banned
    Join Date
    May 2004
    Posts
    55
    Here is one easy..
    WM_CLOSE:
    break;
    lol.. works for me

  11. #11
    Registered User
    Join Date
    May 2004
    Posts
    215
    Yeah But i wanted the close button to be grayed out when the program is doing something, and then when it is done enabled once again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to disable the application close button?
    By e66n06 in forum Windows Programming
    Replies: 8
    Last Post: 01-05-2008, 11:33 AM
  2. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 11:32 AM
  3. Disable button on toolbar - MFC
    By bennyandthejets in forum Windows Programming
    Replies: 0
    Last Post: 05-10-2004, 03:31 AM
  4. HowTo disable button in MFC app
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 01-04-2002, 02:15 AM
  5. disabling button in another prog
    By timmygax in forum Windows Programming
    Replies: 11
    Last Post: 10-29-2001, 03:40 PM