Thread: Disabling "X" button on Window

  1. #1
    Registered User Boomba's Avatar
    Join Date
    Jun 2003

    Disabling "X" button on Window

    hi there,

    I was told it was better to move this question here:

    I've done a bit of research on how to disable the exit (X) button on the win32 app

    this is what i came up with:

    HMENU hMenuHandle; //declare HMUNU handle
    long lngItemCount;     //declare item count storage
    int c, style;	   //declare c and style storage
    //disable for EditMain
    hMenuHandle = GetSystemMenu(EditMain, false);
    lngItemCount = GetMenuItemCount(hMenuHandle);
    //disable maximize button	
    style = GetWindowLong(EditMain, GWL_STYLE);
    style &= ~WS_MAXIMIZEBOX;
    SetWindowLong(EditMain, GWL_STYLE, style);
    //disable 'X' button
    c = lngItemCount;
    while(c > lngItemCount - 4)
    RemoveMenu(hMenuHandle, c--, MF_BYPOSITION | MF_DISABLED);
    the above code works great for the most disables the maximize button and the "X" button but it casues my window (EditMain) to not be movable and it wont let my window minimize in windows windows can minimize in XP but still it is not movable around the screen.. I want my user to be able to move the window around and minimize.

    what is it about my above code that is causing this?
    or is there and even simpler way?

    thanx in advance

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    what happens if you use the line
    PHP Code:
    case WM_DESTROY:
    and don't post a quit message? I haven't tried it, but I think the X button just wouldn't work. You would have to PostQuitMessage(); somewhere else, though.

  3. #3
    Registered User
    Join Date
    May 2003
    That would be VERY bad; WM_DESTROY is sent when Windows is already prepared to deallocate resources.

    You could intercept and ignore WM_CLOSE, though, and use DestroyWindow() elsewhere. WM_CLOSE is the last place you can stop a window's death; after DestroyWindow() is called (which is the default handler's action upon WM_CLOSE) you're past the point of no return; the window MUST die.

  4. #4
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    I'm sure there's a simple way to do it with SetWindowLong, but I just can't think of it .

    //edit: does this help?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM