Daten eingabe in einem Fenster
-
Hi, ich wollte ein Chat programmieren aber irgendwie kriege ich keine 2 konsolenfenster hin und steige nun auf grafisch um was ich eh über kurz oder lang vorhatte.
Da Ich das noch nie gemacht habe bitte ich um hilfe.
Erstmal will ich etwas hinbekommen was text einliest ein Consolen fenster öffnet und dort irgendetwas wieder ausgibt.
// Chat fenster.cpp : Definiert den Einstiegspunkt für die Anwendung. // #include "stdafx.h" #include "Chat fenster.h" #include <WinUser.h> #include <iostream> #include <windows.h> using namespace std; int main() { HANDLE Buffer; AllocConsole(); Sleep(1000); Buffer=CreateConsoleScreenBuffer(GENERIC_WRITE,0x00000002,NULL,CONSOLE_TEXTMODE_BUFFER,NULL); WriteConsole(Buffer,"HAlLO",NULL,NULL,NULL); cout<<"test"; } LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { main(); MSG msg; HWND hWnd; WNDCLASS wc; const char szAppName[] = "Texte einlesen"; const char szTitelName[] = "Test"; TCHAR Titel[5]; LoadString(hInstance,NULL,(LPWSTR)szTitelName,5); wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = (LPCWSTR)szAppName; wc.lpszMenuName = NULL; wc.style = CS_HREDRAW | CS_VREDRAW; RegisterClass(&wc); hWnd = CreateWindowExW( WS_EX_APPWINDOW, (LPCWSTR)szAppName, Titel, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static RECT rect; static char cBuffer[100]; static int iActLen; switch (message) { case WM_SIZE: { rect.left = 20; rect.right = LOWORD(lParam) - 20; rect.bottom = HIWORD(lParam); return 0; } case WM_CHAR: { switch (wParam) { case '\r': iActLen = 0; InvalidateRect(hWnd, NULL, TRUE); break; case '\b': if (iActLen <= 0) break; iActLen--; InvalidateRect(hWnd, NULL, TRUE); break; case '\t': case '\n': case 27 : break; default: if (iActLen < sizeof(cBuffer)) { cBuffer[iActLen++] = wParam; InvalidateRect(hWnd, NULL, FALSE); } break; } return 0; } case WM_PAINT: { PAINTSTRUCT ps; HDC hDC; hDC = BeginPaint(hWnd, &ps); { DrawTextW(hDC, (LPCWSTR)cBuffer, iActLen, &rect, DT_SINGLELINE | DT_VCENTER); } EndPaint(hWnd, &ps); return 0; } case WM_KEYDOWN: { if (wParam == VK_ESCAPE) { SendMessage(hWnd, WM_CLOSE, 0, 0); } return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); }
-
versuch halt einfach ma mit ner mdi vll klappts
-
was ist eine mdi?

Ich habe gerade erst angefangen
-
Matyr schrieb:
Erstmal will ich etwas hinbekommen was text einliest ein Consolen fenster öffnet und dort irgendetwas wieder ausgibt.
Und deine Frage lautet?
Matyr schrieb:
pat94 schrieb:
versuch halt einfach ma mit ner mdi vll klappts
was ist eine mdi?

Matyr schrieb:
Ich habe gerade erst angefangen
Dann würd' ich von Netzwerkprogrammierung und der WinAPI erstmal die Finger lassen, bis du in C halbwegs sattelfest bist.
Matyr schrieb:
int main()und
Matyr schrieb:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)kann's schonmal nicht sein.
cheers, Swordfish
-
Nicht mit C angefangen sondern mit WINAPI und wieso kann das nicht sein und frage ist wo die fehler liegen,
-
Swordfish schrieb:
Matyr schrieb:
int main()und
Matyr schrieb:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)kann's schonmal nicht sein.
cheers, Swordfish
Hmm ich hab es jetzt selber nicht ausprobiert ob der Compiler/Linker hier nen Fehler bringt, dennoch die Funktion int main() ist der Einstiegspunkt für eine Konsolenanwendung, die Funktion int WINAPI WinMain (...) ist der Einstiegspunkt für eine GUI-Anwendung. Auch wenn es geht, solltest du keine (normale) Funktion main oder WinMain nennen.
-
Aber um vielleicht mal auf dein Problem einzugehen, versuch mal das hier:
int hCrt = 0; FILE *hfOutput = NULL; AllocConsole(); // Set output handle to allocated console hCrt = _open_osfhandle (reinterpret_cast<intptr_t> (GetStdHandle (STD_OUTPUT_HANDLE)), _O_TEXT); hfOutput = _fdopen (hCrt, "w"); *stdout = *hfOutput; setvbuf (stdout, NULL, _IONBF, 0);
-
ok