Thread: AllocConsole dos box shuts down main prog

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    76

    AllocConsole dos box shuts down main prog

    When i use AllocConsole for my GUI program i get a nice dos box. This box is used to run programs in batch mode. The problems is that when i close the dos box with the x in the right top my main program also shuts down. Is there anything i can do about this?

    I tried it with SetConsoleCtrlHandler but this didnt help.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    I believe all you can do is handle CTRL+CLOSE signals using SetConsoleCtrlHandler().

    Just make your own console window.

    gg

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    76
    I dont know exactly what you mean but this is from msndn:

    When a CTRL_CLOSE_EVENT signal is received, the control handler returns TRUE, causing the system to display a dialog box that gives the user the choice of terminating the process and closing the console or allowing the process to continue execution. If the user chooses not to terminate the process, the system closes the console when the process finally terminates.

    So i cant just ignore CTRL_CLOSE_EVENT.

    I tried to disable the close button but i dont know how.

    And how do i create my own window? I need to get the output from it so that is why i used AllocConsole.

  4. #4

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    76

    Been there, seen it, and even tried it => way to complex
    There is also a little problem with that example. DuplicateHandle is only available on win NT.

    But thx for the suggestion.

    Whats easier is to use:

    ReadConsoleOutputCharacter in combination with AllocConsole

    Only very few lines and works just as good (for me).

    I have diasable the close button with:
    Code:
    HMENU  hm = GetSystemMenu(hConsole,false);
    DeleteMenu(hm, SC_CLOSE, MF_BYCOMMAND);
    I hate it when such a small problem takes way WAY to long to solve .

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    DuplicateHandle() is available on all Windows platforms.

    >> I have diasable the close button with:
    Neat.

    gg

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    76
    I just found out there are 2 DuplicateHandle's . I must say, i was supriced the example would only work on NT. But fortunately you corrected me

    Code:
    NTSTATUS DuplicateHandle(
      HANDLE SourceHandle,
      PHANDLE DestinationHandle
    );
    Requirements
    Client: Included in Windows XP, Windows 2000 Professional.
    Server: Included in Windows Server 2003, Windows 2000 Server.
    Header: Declared in Ntsecpkg.h.
    Code:
    BOOL DuplicateHandle(
      HANDLE hSourceProcessHandle,
      HANDLE hSourceHandle,
      HANDLE hTargetProcessHandle,
      LPHANDLE lpTargetHandle,
      DWORD dwDesiredAccess,
      BOOL bInheritHandle,
      DWORD dwOptions
    );
    
    Requirements
    Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, and Windows 95.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  2. int main (), main (), main (void), int main (void) HELP!!!
    By SmokingMonkey in forum C++ Programming
    Replies: 7
    Last Post: 05-31-2003, 09:46 PM
  3. Creepy DOS and BIOS functions (need help!!!)
    By James00 in forum C Programming
    Replies: 9
    Last Post: 05-05-2003, 12:40 AM
  4. real mode dos & win dos
    By scott27349 in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 08-19-2002, 06:15 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM