Disabling "X" button on Window

This is a discussion on Disabling "X" button on Window within the Windows Programming forums, part of the Platform Specific Boards category; hi there, I was told it was better to move this question here: I've done a bit of research on ...

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

    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:

    Code:
    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);
    DrawMenuBar(EditMain);
    the above code works great for the most part...it 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 NT...my 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
    Boomba,

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    what happens if you use the line
    PHP Code:
    case WM_DESTROY:
         break; 
    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.
    Away.

  3. #3
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    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
    Posts
    3,230
    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? http://beta.experts-exchange.com/Pro..._20304144.html

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, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21