mehrere Wörter aus Edit Windows Lesen WinApi
-
[cpp]
Ich dachte mir zum üben der WinApi in c++ dachte ich könnte ich einen Vokabel Trainer basteln. Jetzt habe ich aber ein Problem und zwar wenn ich die richtige übersetzung für "der Busch('Wildes' Land in Afrika)" und zwar "the bush" eingebe
kommt Falsch bei einzelen Wörtern aber nicht.Abspeichern tu ich das was ich in ein Edit Window schreibe mit:
GetWindowText( hWndEditE, (LPSTR)Var, sizeof( Var ));
(Var ist ein char array mit 100 Zeichen)die chars vergleiche ich mit:
if( strcmp(Var, eVar1) == 0)
{
// weiterer code der Richtig oder Falsch aus gibt und
// zur nächsten Vokabel springt
}Hoffe auf hilfen
und alle ideenGruß cppfan
-
Dieser Thread wurde von Moderator/in SeppJ aus dem Forum C++ (auch C++0x und C++11) 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.
-
... und was sollen wir hier sehen?
Ich sehe nur einen If Zweig für den Fall "richtig" einen else Zweig sehe ich nicht...
Wenn es mehrere Worte sind und die Worte auch einzeln speicherst musst Du natürlich auch diese Zeile zerlegen. Aber wie das machst beschreibst Du ja leider nicht.Was hat das mit WinAPI zu tun?
-
Ok hab mich etwas dumm ausgedrückt.
hier der Code:#include "stdafx.h" #include <Windows.h> #include <string.h> //init static char eVar1[] = "shock"; static char eVar2[] = "magical"; static char eVar3[] = "the bush"; static char eVar3s[] = "bush"; static char eVar4[] = "bush"; static char eVar5[] = "(to) be about to do sth."; static char eVar5s[] = "be about to do sth."; static char eVar5ss[] = "be about to do"; static char eVar5sss[] = "be about to do something"; static char eVar5ssss[] = "(to) be about to do something"; static char eVar6[] = "sleeping bag"; static char eVar7[] = "wave"; static char eVar8[] = "(to) carry"; static char eVar8s[] = "carry"; static char eVar9[] = "barbecue"; static char eVar10[] = "alcohol"; static char eVar11[] = "common"; static char eVar12[] = "at someone's place"; static char eVar12s[] = "at someone`s place"; static char eVar12ss[] = "at someone´s place"; static char eVar13[] = "gallery"; static char eVar14[] = "the outback"; static char gVar1[] = "Schock, Schreck"; static char gVar2[] = "zauberhaft, wundervoll"; static char gVar3[] = "der Busch('Wildes' Land in Afrika)"; static char gVar4[] = "Busch, Strauch"; static char gVar5[] = "im Begriff sein, etwas zu tun"; static char gVar6[] = "Schlafsack"; static char gVar7[] = "Welle"; static char gVar8[] = "tragen"; static char gVar9[] = "Grillfest, Grillparty"; static char gVar10[] = "Alkohol"; static char gVar11[] = "weit verbreitet, häufig"; static char gVar12[] = "bei jemandem zu Hause"; static char gVar13[] = "(Bilder-)Galerie"; static char gVar14[] = "(Australien)das Hinterland"; char Var[100]; int iGleich; int iNum = 1; enum eId{ ID_BUTTON = 100, }id; LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ); int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, PSTR szCmdLine, int iCmdShow ) { static char szClassName[] = "WndClass"; MSG msg; HWND hWnd; WNDCLASS WndClass; WndClass.cbClsExtra = NULL; WndClass.cbWndExtra = NULL; WndClass.hbrBackground = ( HBRUSH ) GetStockObject ( WHITE_BRUSH ); WndClass.hCursor = LoadCursor( NULL, IDC_ARROW ); WndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION ); WndClass.hInstance = hInst; WndClass.lpfnWndProc = WndProc; WndClass.lpszClassName = szClassName; WndClass.lpszMenuName = NULL; WndClass.style = CS_VREDRAW | CS_HREDRAW; if ( !RegisterClass( &WndClass )) { MessageBox( NULL, "Register error.", "Fatal error", MB_ICONERROR | MB_OK ); return false; } hWnd = CreateWindow( szClassName, "Unit 1 - Australia", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL ); if (hWnd == NULL) { MessageBoxA( NULL, "Fenster konnte nicht erstellt werden", "Error", MB_OK); return false; } ShowWindow( hWnd, iCmdShow ); UpdateWindow( hWnd ); while( GetMessage( &msg, hWnd, NULL, NULL ) > NULL) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return 0; } HWND hWndEditE; HWND hWndEditG; HWND hWndEditB; HWND hWndEdit; HWND hWndEdit1; HWND hWndEditS; HWND hWndEditZ; HINSTANCE hInstEditE; HINSTANCE hInstEditG; HINSTANCE hInstEditB; HINSTANCE hInstEdit; HINSTANCE hInstEdit1; HINSTANCE hInstEditS; HINSTANCE hInstEditZ; LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch ( msg ) { case WM_CREATE: hWndEditG = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "", ES_READONLY | WS_CHILD | WS_VISIBLE, 50, 50, 250, 20, hWnd, NULL, hInstEditG, NULL); hWndEditE = CreateWindowEx( WS_EX_CLIENTEDGE, "Edit", NULL, WS_CHILD | WS_VISIBLE, 350, 50, 250, 20, hWnd, NULL, hInstEditE, NULL); hWndEdit = CreateWindowEx( WS_EX_CLIENTEDGE, "Edit", NULL, ES_READONLY | WS_CHILD | WS_VISIBLE, 600, 50, 100, 20, hWnd, NULL, hInstEdit, NULL); hWndEdit1 = CreateWindowEx( WS_EX_CLIENTEDGE, "static", " = ", ES_CENTER | WS_CHILD | WS_VISIBLE, 300, 50, 50, 20, hWnd, NULL, hInstEdit1, NULL ); hWndEditB = CreateWindowEx(WS_EX_CLIENTEDGE, "Button","Korektur", ES_CENTER | WS_CHILD | WS_VISIBLE, 200, 100, 225, 30, hWnd, (HMENU) ID_BUTTON, hInstEditB, NULL); SetWindowText( hWndEditG, (LPCSTR) gVar1); break; case WM_COMMAND: switch ( wParam ) { case ID_BUTTON: GetWindowText( hWndEditE, (LPSTR)Var, sizeof( Var )); switch( iNum ) { case 1: if( strcmp(Var, eVar1) == 0) { SetWindowText( hWndEdit, (LPCSTR) "Richtig"); SetWindowText( hWndEditE, NULL ); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar2); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar2); iNum++; } break; case 2: if( strcmp(Var, eVar2) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar3); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar3); iNum++; } break; case 3: if( strcmp(Var, eVar3) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar4); } if( strcmp(Var, eVar3s) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar4); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar4); iNum++; } break; case 4: if( strcmp(Var, eVar4) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar5); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar5); iNum++; } break; case 5: if( strcmp(Var, eVar5) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar6); } if( strcmp(Var, eVar5s) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar6); } if( strcmp(Var, eVar5ss) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar6); } if( strcmp(Var, eVar5sss) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar6); } if( strcmp(Var, eVar5ssss) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar6); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar6); iNum++; } break; case 6: if( strcmp(Var, eVar6) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar7); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar7); iNum++; } break; case 7: if( strcmp(Var, eVar7) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar8); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar8); iNum++; } break; case 8: if( strcmp(Var, eVar8) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar9); } if( strcmp(Var, eVar8s) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar9); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar9); iNum++; } break; case 9: if( strcmp(Var, eVar9) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar10); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar10); iNum++; } break; case 10: if( strcmp(Var, eVar10) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar11); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar11); iNum++; } break; case 11: if( strcmp(Var, eVar11) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar12); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar12); iNum++; } break; case 12: if( strcmp(Var, eVar12) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar13); } if( strcmp(Var, eVar12s) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar13); } if( strcmp(Var, eVar12ss) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar13); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar13); iNum++; } break; case 13: if( strcmp(Var, eVar13) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; SetWindowText( hWndEditG, (LPCSTR) gVar14); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, (LPCSTR) gVar14); iNum++; } break; case 14: if( strcmp(Var, eVar14) == 0) { SetWindowText( hWndEditE, NULL ); SetWindowText( hWndEdit, (LPCSTR) "Richtig"); iNum++; hWndEditS = CreateWindowEx( WS_EX_CLIENTEDGE, "Edit", "Super Du hast 14 Vokabeln geübt", ES_READONLY | WS_CHILD | WS_VISIBLE, 0, 300, CW_USEDEFAULT, 30, hWnd, NULL, hInstEditS, NULL); } else { SetWindowText( hWndEdit, (LPCSTR) "Falsch"); SetWindowText( hWndEditG, NULL); iNum++; } break; } break; } break; case WM_QUIT: DestroyWindow( hWnd ); break; case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc( hWnd, msg, wParam, lParam ); }
( Zeichensatz auf nicht festgelegt setzen und SubSystem auf
Windows (/SUBSYSTEM:WINDOWS) )könnt ihr dann ja selber aus probieren.