Console Application und Fenster gleichzeitig öffnen
-

es ist zum verzweifeln, ich will ein leeres fenster und eine console gleichzeitig öffnen, geht so weit auch, bloss ich kann die console nicht beschreiben, nur das normale fenster. ich öffne die console überAllocConsole();warscheinlich brauch ich ne funktion wie z.b. WindowProc() fürs normale fensteer. aber was muss ich bei der console machen?
ich hoffe mir kann jemand weiterhelfen, schon mal danke...

-
Dieser Thread wurde von Moderator/in Jansen aus dem Forum VCL/CLX (Borland C++ Builder) in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
du musst die std::cout std::cerr usw. auf die Konsole lenken
google mal nach Console WinAPI oder sowas...
-
hab ich mir mal irgendwann gespeichert (danke an den unbekannten autor..)
#include <windows.h> #include <stdio.h> #include <fcntl.h> #include <io.h> #include <iostream> #include <string> VOID CreateConsole() { AllocConsole(); HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hConsoleInput = GetStdHandle(STD_INPUT_HANDLE); HANDLE hConsoleError = GetStdHandle(STD_ERROR_HANDLE); #ifdef __BORLANDC__ dup2(_open_osfhandle(reinterpret_cast<LONG>(hConsoleInput), _O_TEXT), 0); setvbuf(stdout, NULL, _IONBF, 0); dup2(_open_osfhandle(reinterpret_cast<LONG>(hConsoleOutput), _O_TEXT), 1); setvbuf(stdout, NULL, _IONBF, 0); dup2(_open_osfhandle(reinterpret_cast<LONG>(hConsoleError), _O_TEXT), 2); setvbuf(stdout, NULL, _IONBF, 0); #else FILE* NewStandardInput = _fdopen(_open_osfhandle(reinterpret_cast<LONG>(hConsoleInput), _O_TEXT), "r"); if(NewStandardInput != NULL) { *stdin = *NewStandardInput; } setvbuf(stdin, NULL, _IONBF, 0); FILE* NewStandardOutput = _fdopen(_open_osfhandle(reinterpret_cast<LONG>(hConsoleOutput), _O_TEXT), "w"); if(NewStandardOutput != NULL) { *stdout = *NewStandardOutput; } setvbuf(stdout, NULL, _IONBF, 0); FILE* NewStandardError = _fdopen(_open_osfhandle(reinterpret_cast<LONG>(hConsoleError), _O_TEXT), "w"); if(NewStandardError != NULL) { *stderr = *NewStandardError; } setvbuf(stderr, NULL, _IONBF, 0); #endif std::ios::sync_with_stdio(); } ///////////////////////////////////////////////////// // Prototypes ///////////////////////////////////////////////////// LRESULT CALLBACK MainWindowProcedure(HWND hWindowHandle, UINT uMessage, WPARAM wParam, LPARAM lParam); ///////////////////////////////////////////////////// // The application's entry point ///////////////////////////////////////////////////// int WINAPI WinMain(HINSTANCE hInstanceHandle, HINSTANCE hPreviousInstanceHandle, LPSTR lpszCommandLine, INT nShowState) { ///////////////////////////////////////////////////// // Register main window class ///////////////////////////////////////////////////// WNDCLASSEX MainWindowClass = {0}; MainWindowClass.cbSize = sizeof(WNDCLASSEX); MainWindowClass.hInstance = hInstanceHandle; MainWindowClass.lpszClassName = "MainWindow"; MainWindowClass.lpfnWndProc = MainWindowProcedure; MainWindowClass.style = CS_HREDRAW | CS_VREDRAW; MainWindowClass.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH); MainWindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); MainWindowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); MainWindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); MainWindowClass.lpszMenuName = NULL; MainWindowClass.cbClsExtra = 0; MainWindowClass.cbWndExtra = 0; if(RegisterClassEx(&MainWindowClass) == FALSE) { MessageBox(NULL, "Can't register MainWindowClass!", "Information", MB_OK); return EXIT_FAILURE; } ///////////////////////////////////////////////////// // Create main window ///////////////////////////////////////////////////// HWND hMainWindow = CreateWindowEx( 0, "MainWindow", "Simple Window Application", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, NULL, GetModuleHandle(NULL), NULL); if(hMainWindow == NULL) { MessageBox(NULL, "Can't create main window!", "Information", MB_OK); return EXIT_FAILURE; } ///////////////////////////////////////////////////// // Create a console and do some console i/o ///////////////////////////////////////////////////// CreateConsole(); std::cout << "Hello World!" << std::endl; std::cout << "Eingabe: "; std::string s; std::getline(std::cin, s); std::cout << "Ausgabe: " << s; ///////////////////////////////////////////////////// // Do the message loop ///////////////////////////////////////////////////// MSG Message = {0}; while(GetMessage(&Message, NULL, 0, 0)) { TranslateMessage(&Message); DispatchMessage(&Message); } return Message.wParam; } ///////////////////////////////////////////////////// // Callback function for the main window ///////////////////////////////////////////////////// LRESULT CALLBACK MainWindowProcedure(HWND hWindowHandle, UINT uMessage, WPARAM wParam, LPARAM lParam) { switch(uMessage) { case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWindowHandle, uMessage, wParam, lParam); } return 0; }vielleicht hilfts.
-
mit freopen gehts auch.
freopen("con:", "w", stdout);
-
kann ich auch ein console application über
ShellExecute(...); //oder WinExec(...);öffnen und dann halt die eingaben in einer datei speichern?
-
unter MS Visual Studio 2005 gibts da eine Compileroption:
Quellcode ist hier zu finden:
http://turing.fh-landshut.de/~jamann/IMB/IMB.html
-
danke, damit bekomm ichs hin!!!
