Konsole



  • Sers,

    Also ich habe mir eine Klasse geschrieben. Damit soll es möglich sein Text auf der Konsole auszugeben und Strings einzulesen.
    Das mit dem Ausgeben klappt schon. Nur mit dem Einlesen hagelts noch Probleme.
    Hier einwenig Code:

    Klasse "CConsole"

    // includes
    #include "CConsole.h"
    
    // constructor
    CConsole::CConsole(char *szTitle)
    {
        // allocate
        AllocConsole();
    
        // set title
        SetConsoleTitle(szTitle);
    
        // save handles
        hConsoleOutput  = GetStdHandle(STD_OUTPUT_HANDLE);
        hConsoleInput   = GetStdHandle(STD_INPUT_HANDLE);
        hConsoleError   = GetStdHandle(STD_ERROR_HANDLE);
    }
    
    // destructor
    CConsole::~CConsole()
    {
        // cleanup
        FreeConsole();
    }
    
    // function to give out a text
    void CConsole::ConsoleWrite(char *szString)
    {
        // print out text
        WriteConsole(hConsoleOutput, szString, strlen(szString), NULL, NULL);
    }
    
    // function read in a text
    void CConsole::ConsoleInput(char *szString, int iLen)
    {
        // print out text
        ReadConsole(hConsoleInput, szString, iLen, NULL, NULL);
    }
    

    main.cpp

    // alloc space for console
            myConsole = new CConsole("Lunatic - server");
    
            char test[55];
            myConsole->ConsoleInput(test, 16);
            myConsole->ConsoleWrite(test);
    

    Ich kann à la myConsole->ConsoleWrite("Hello World"); Text ohne Probleme ausgeben. Nur so klappt es nicht!

    Wo ist der Fehler?

    cu para
    😃



  • Hallo,

    liegt wohl daran, das du NULL beim 4. Parameter angibst.



  • Stimmt! Hatte das in diversen Beispielen so aufgeschnappt.
    Sorry!

    cu para
    😃



  • Sers,
    Hätt da nochne Frage bez. der Konsole.
    Wie bekomm ich es mit, wenn sie geschlossen wird?

    danke!
    cu para
    😃



  • Garnicht. 😃



  • Glaub ich nicht!
    Wieso wird eigentlich gleich meine ganze Anwendung geschlossen, wenn ich die Konsole schließe??? ICh hab doch ansonsten noch alles, also Fenster, Message-Loop, etc



  • SetConsoleCtrlHandler



  • Also ich habs jetzt so:

    [edit]bGUI ist true[/edit]
    // control handler
    BOOL CsleHndler(DWORD dwCtrlType)
    {
        if(dwCtrlType==CTRL_CLOSE_EVENT){
            if(bGUI){
                char szConsoleTitle[MAX_PATH];
                GetConsoleTitle(szConsoleTitle, MAX_PATH);
                HWND hConsole =   FindWindow (NULL, szConsoleTitle);
                ShowWindow ( hConsole , SW_HIDE );
                return TRUE;
            }else
                return FALSE;
        }
    
        return FALSE;
    }
    

    Dass funtioniert aber leider nicht! Erst hängt sich die Konsole auf, dann kommt (nach ~10Sekunden) dieser Dialog von Windows "Der Prozess reagiert nicht... Soll er geschlossen werden bla bla..." und dann (ohne klicken) wird die Konsole automatisch geschlossen. Mein Prozess läuft dann zwar weiter aber die Konsole ist futsch, dabei will ich sie ja nur verstecken

    cu para
    😃

    Hoffe ihr könnt helfen

    [ Dieser Beitrag wurde am 15.02.2003 um 13:55 Uhr von paranoiac.org editiert. ]



  • OK, hab mich geirrt, die Konsole ist nicht futsch. Trotzdem dauert es ca 10-15 Sekunden bis die Konsole "sich versteck" und der Windows Dialog kommt auch jedesmal.



  • The CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT signals give the process an opportunity to clean up before termination. A HandlerRoutine can perform any necessary cleanup, then take one of the following actions:

    - Call the ExitProcess function to terminate the process.
    - Return FALSE. If none of the registered handler functions returns TRUE, the default handler terminates the process.
    - Return TRUE. In this case, no other handler functions are called, and the system displays a pop-up dialog box that asks the user whether to terminate the process. The system also displays this dialog box if the process does not respond within a certain time-out period (5 seconds for CTRL_CLOSE_EVENT, and 20 seconds for CTRL_LOGOFF_EVENT or CTRL_SHUTDOWN_EVENT)

    Also sehe ich da keine Möglichkeit für dein Vorhaben.

    Entweder muss man da selber ExitProcess aufrufen, oder der default-handler schließt die Anwendung, oder es kommt dieser von dir genannte Dialog.



  • Ach menno!
    Ich wollt doch nur die Console verstecken und bei Bedarf wieder zeigen!


Anmelden zum Antworten