Thread: Disabling close button

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    6

    Disabling close button

    Can anyone help me on how to disable the close button in C programming? , or just anyway that you can't close the program manually.

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    You mean in a window you create? What OS?

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    6
    Yeah, probably XP or w7.
    Like, http://img197.imageshack.us/img197/7796/3232m.png

  4. #4
    Registered User
    Join Date
    Dec 2009
    Posts
    6
    In summary, i just want my program to be a trap, I mean, like, you can't close it by pressing the X button on the upper right hand corner, alt+f4, or what so ever.

    Maybe the only way in closing is is through task manager.
    Thanks.

  5. #5
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Using WinAPI I guess. Well, there should be able to override "OnClose" event handler or signal handler or whatever the terminology is. So it doesn't do nothing when the X is pressed (the signal won't be handled).

    Another way is to simply take of the bar that has X button (by making borders to 0 or the bar size to 0). But then you would have to do something about ALT+F4 as well. It is better to do both, so users know that it cannot be closed.

    Anyhow, don't know exactly how, so you will have to wait for somebody else Never used WinAPI my self.

  6. #6
    Registered User
    Join Date
    Dec 2009
    Posts
    6
    Well, I hope so, haven't tried it too. I found some codes but it is only for C#, How sad. Anyway, how do you apply making borders to 0 and the bar size?

  7. #7
    Registered User
    Join Date
    Dec 2009
    Posts
    6
    So? No one can still help me here with this?

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    100
    Disable the close button with your window styles, and also subclass all windows of your application and handle the WM_CLOSE message.

    Leave a way (password perhaps) to re-enable WM_CLOSE processing if you ever want a clean termination.

  9. #9
    Registered User
    Join Date
    Dec 2009
    Posts
    6
    How do I do that then? I'm a beginner with C. I just want a code to disable the button or what else.

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by dissidia
    In summary, i just want my program to be a trap, I mean, like, you can't close it by pressing the X button on the upper right hand corner, alt+f4, or what so ever.
    I wanted to move this to the appropriate forum, but this sounds malicious, so sorry, I am closing this thread.

    The question would have been far more convincingly valid if you knew some GUI programming to begin with.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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. Disabling a button
    By TheMajorRager in forum C# Programming
    Replies: 0
    Last Post: 10-14-2005, 05:09 PM
  3. Disabling "X" button on Window
    By Boomba in forum Windows Programming
    Replies: 3
    Last Post: 06-14-2003, 01:53 PM
  4. disabling button in another prog
    By timmygax in forum Windows Programming
    Replies: 11
    Last Post: 10-29-2001, 03:40 PM
  5. Ghost in the CD Drive
    By Natase in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-12-2001, 05:38 PM