Disabling Window "X" button?(PLEASE HELP!)

This is a discussion on Disabling Window "X" button?(PLEASE HELP!) within the Windows Programming forums, part of the Platform Specific Boards category; Ok. I am making a program. It is pretty cool. It is a window manager. You can close, disable, enable, ...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question Disabling Window "X" button?(PLEASE HELP!)

    Ok. I am making a program. It is pretty cool. It is a window manager. You can close, disable, enable, hide, show, set caption, send keys, etc.

    I want a function to disable the close("X") button of a window. I have EnumWindows called. All the others work fine. How would I disable a window's close("X") button?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    There is a certain Window Style (WS_*) that you are to specify when you create the window with CreateWindow(). I just can't remember the specification.

    I can't remember what it is, but I'll continue to look for the link.

    --Garfield
    1978 Silver Anniversary Corvette

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Well, that...

    Thanks for looking for it. I know there's WS_CLOSEBOX or something like that, but I'm not sure. I know that in the class there's a CS_NOCLOSE that does it, but I'm not sure how to create that class style to a window.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    You might want to try the WS_MINIMIZEBOX. I'm not sure it that shows the "X", but it might disable it.

    --Garfield
    1978 Silver Anniversary Corvette

  5. #5
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question How would I do that?

    How??
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  6. #6
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    >> not sure how to create that class style to a window. <<

    You would specify it in type WNDCLASS. In the style field.
    1978 Silver Anniversary Corvette

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    >> How?? <<

    To create the window out of a window class just:

    hwnd = CreateWindow(szAppName, "Test", WS_MINIMIZEBOX, etc., etc., etc.)

    I can't remember the rest of the params off my head, but I could have sample code if you like.

    I have to go now, but I'll wip up a window with a disabled "X" button, okay?

    --Garfield
    1978 Silver Anniversary Corvette

  8. #8
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Noooo...not...

    I want to disable an X of another window. Not mine. Cause I used EnumWindows() and I want to disable the X of a selected window. I know how to use FindWindow(). I know I can disable the X in my own.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  9. #9
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    you can use SetWindowLong to change the windows winproc. trap the WM_CLOSE and just do a return 0; and pass all other messages to the old winproc.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  10. #10
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Please give...

    Say the window name is "Example". Will you show me some code to what you mean, Stoned_Coder?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  11. #11
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    Why do you want to disable the Close of some OTHER exe?

    Why would the user (you in this case) try to close an exe and not want it to close? (except by mistake)

    Do you have a big wooden horse to give me? Looking for Helen?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  12. #12
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Well, no...

    No, I'm not making a trojan. It's just a project for a Window Manager just for fun. I never have taken classes on C++ either. So none of mine are homework, just self-wanted projects.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  13. #13
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    >> Do you have a big wooden horse to give me? Looking for Helen? <<

    LOL That is definitely classic!
    1978 Silver Anniversary Corvette

  14. #14
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Well if there IS a WS_CLOSEBOX or something, in CreateWindow do something like

    WS_OVERLAPPEDWINDOW |~ WS_CLOSEBOX

    or

    (WS_OVERLAPPEDWINDOW - WS_CLOSEBOX)

    may work.

  15. #15
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    This code prevents Dev C++ from being closed from the 'X' button or the system menu.

    Code:
    #include <windows.h>
    
    int main()
    {
    	HWND hwnd = NULL;
    	
    	while (hwnd==NULL)
    		hwnd = FindWindow(0,"Dev-C++ 4.01");
    
    	HMENU hmenu= GetSystemMenu(hwnd,FALSE);
    	DeleteMenu(hmenu,SC_CLOSE,MF_BYCOMMAND );
    	LONG style = GetWindowLong(hwnd,GWL_STYLE);
    	style ^= WS_SYSMENU;
    	SetWindowLong(hwnd,GWL_STYLE,style);
    	return 0;
    }
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

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