Thread: Closing the window!

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    4

    Closing the window!

    Hi all,

    I'm using Borland C++ 4.52, I've got a very simple program and a very simple question

    I want to close the command window...It's easy I think, but I can't find the solution...I tried searching on my different spots but I can't find anything!!

    Please help me out :s

    Sample code:
    Code:
    #include <stdio.h>
    
    int main (void)
    	{
    	char c;
    
    	printf("Hello, this is the end, lol\n");
    	printf("Press any key to exit the window");
    	scanf("%c", &c)
    
    							//Shut down the window here
    	window.close;     //???
    
    	return 0;
    	}

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    What do you mean "close" ?

    If you're running the program inside the IDE, then all you need do is run into the "return 0;" and the temporary console window the IDE created to run your executable will disappear automatically (just see lots of other posts which complain about how to stop this happening, and the FAQ).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    4
    By close I mean "Exit" the window...And by adding return 0; the window won't close in Borland...It'll just stop running, waiting for you to press the X button

  4. #4
    Registered User kishore's Avatar
    Join Date
    Jan 2007
    Location
    bangalore
    Posts
    6
    Did You Try
    Code:
    exit(1);

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by anarchypower
    By close I mean "Exit" the window...And by adding return 0; the window won't close in Borland...It'll just stop running, waiting for you to press the X button
    So it is a problem of the Borland IDE... You should study the project Options... Not modifying the code
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Dec 2006
    Posts
    4
    I tried exit(1); but it has no effect...

    I'm looking at the project options, vart...thanks for the tip

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    You are using windows? Then you can use Win32 API. There is a stupid way to do this...
    Code:
    #include <stdio.h>
    #include <windows.h>
    int main(){
        getchar();
        SetConsoleTitle("unique");
        SendMessage(FindWindow(NULL,"unique"),WM_CLOSE,0,0);
        return 0;
    }
    It really is a stupid way...
    Last edited by maxorator; 01-07-2007 at 11:31 AM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 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. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM