Falsche Fenster werden aufgerufen
-
Hallo
also ich will euch hier nicht mit meinem 400zeilen langen code belästigen, aber dennoch habe ich eine Frage.
Ich habe drei Funktionen die jeweils ein Fenster darstellen. 2 dieser Fenster sind als Child deklarierte Fenster zu dem Hauptfenster. So jetzt die Problematik. Wenn ich in meinem Hauptfenster einen button drücke welcher mich zu meinem einer 2 anderen Fenster leitet funktioniert das soweit gut. Kehre ich jedoch zu meinem Hauptfenster zurück nachdem ich in einem der Childfenster war und rufe das Fenster auf was ich beim ersten aufruf nicht aufgerufen habe. So nimmt das neuaufgerufe Fenster komischer weiße genau das alles an was in dem vorherigen Fenster auch drinne war. Es hat alle EditFelder, alle Buttons, das Menü. Das einzigste was unterschiedlich ist, ist der WindowText der ist so richtig wie er sein soll.
Wie kann es nun also sein das ein Fenster was eigentlich völlig andere Buttons und editfelder hat, aufeinmal die Buttons und Editfelder eines anderen Fensters annimmt??
-
Ohne Code kann Dir das wohl niemand beantworten... Du vermuschelst wahrscheinlich irgendwelche Handles...
-
ok ihr wollts nicht anders...:D dann muss ich den code posten.
hier das hauptfenster
#include "Includes.h" LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); HINSTANCE hinst; /* Make the class name into a global variable */ char szClassName[ ] = "Kontosimulation"; int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nCmdShow) { RECT ScreenCoords; if(!SystemParametersInfo(SPI_GETWORKAREA,NULL,&ScreenCoords,NULL) ) { MessageBox(NULL,"Achtung","Ein Fehler",MB_ICONWARNING | MB_OK | MB_DEFBUTTON1); ScreenCoords.right = 1024; ScreenCoords.bottom = 768; } HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_HREDRAW|CS_VREDRAW; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = MAKEINTRESOURCE(302); /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default colour as the background of the window */ wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH); /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ "Kontosimulation", /* Title Text */ WS_CAPTION|WS_SYSMENU|WS_DLGFRAME|WS_MINIMIZEBOX, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ HEIGHT-200, /* The programs width */ WIDTH-200, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Make the window visible on the screen */ ShowWindow (hwnd, nCmdShow); hinst = hThisInstance; /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; } LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HWND EBenutzername; HWND EKundennummer; HWND Anmelden; HWND Bbeenden; int width; int height; string benutzer_array[1024]; switch (message) /* handle the messages */ { case WM_DESTROY: PostQuitMessage (0); DestroyWindow(hwnd); break; case WM_SIZE: { width = LOWORD(lParam); height = HIWORD (lParam); } case WM_PAINT: { PAINTSTRUCT ps; RECT ClientArea; GetClientRect(hwnd,&ClientArea); HDC hDc = BeginPaint(hwnd,&ps); { SetBkMode(hDc,TRANSPARENT); TextOut(hDc, 10, 5*VABSTAND, "Benutzer:", 9); TextOut(hDc, 8, 10*VABSTAND, "Kundennummer:",13); //DrawLine(hwnd,PS_SOLID,1,RGB(122,122,122),0,height-40,width,height-40); } } case WM_CREATE: { EBenutzername = CreateWindow("edit", "", WS_CHILD | WS_VISIBLE | WS_BORDER, 5*HABSTAND+80, 5*VABSTAND, 170, 20, hwnd, (HMENU)BENUTZERNAME, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE), NULL); EKundennummer = CreateWindow("edit", "", WS_CHILD | WS_VISIBLE | WS_BORDER, 5*HABSTAND+80, 5*VABSTAND+50, 170, 20, hwnd, (HMENU)BENUTZERNUMMER, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE), NULL); Anmelden= CreateWindow("button", "Anmelden", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, 5*HABSTAND+170, 5*VABSTAND+90, 80, 20, hwnd, (HMENU)BT_ANMELDEN, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE), NULL); } case WM_COMMAND: { switch(LOWORD(wParam)) { case IDM_SCHLIESSEN: { DestroyWindow(hwnd); PostQuitMessage(0); break; } case BT_ANMELDEN: { fstream benutzerdaten; stringstream str,str2; string Benutzername; string Benutzernummer; string daten; string temp; string merke; bool istvorhanden = false; char name[1024]; char nummer[1024]; /////////auslesen und zusammenführen des namens und der nummer GetDlgItemText(hwnd,BENUTZERNAME,name,1024); GetDlgItemText(hwnd,BENUTZERNUMMER,nummer,1024); str<<name; str>>Benutzername; str2<<nummer; str2>>Benutzernummer; if(Benutzernummer.length() != 6) { MessageBox(hwnd,"Die Kundennummer/Benutzername ist nicht korrekt","Fehler!",MB_ICONWARNING); SetDlgItemText(hwnd,BENUTZERNUMMER,""); } daten = Benutzername + Benutzernummer; //////////////////////////Zusammenschneiden beendet benutzerdaten.open("Benutzerdaten.txt",ios::in); while(benutzerdaten>>temp) { if(daten == temp) { istvorhanden = true; } } if(istvorhanden) { MessageBox(hwnd,"Sie haben sich erfolgreich angemeldet, ihnen stehen nun weitere Möglichkeiten zur verfügung","Hinweis",MB_ICONINFORMATION); ShowWindow(hwnd,SW_HIDE); Neue_Ueberweisung_Fenster((HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),hwnd); benutzerdaten.close(); break; } else { MessageBox(hwnd,"Dieser Benutzername/Kundennummer ist ungültig","Fehler!",MB_ICONWARNING); SetDlgItemText(hwnd,BENUTZERNAME,""); SetDlgItemText(hwnd,BENUTZERNUMMER,""); break; } break; } case IDM_NEUER_BENUTZER: { neuer_benutzer((HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),hwnd); break; } }//ende switch(LOWORD(wparam) }//ende WM_COMMAND default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }dann kommt hier das fenster was aufgerufen wird, wenn man auf den neue_überweisen button klickt.
#include "Includes.h" LRESULT CALLBACK New_Window_Procedure (HWND , UINT , WPARAM , LPARAM ); int Neue_Ueberweisung_Fenster(HINSTANCE ParentInstance,HWND ParentWindow) { char ChildWindowClassName[ ] = "ChildWindow"; HWND ChildWindow; /* This is the handle for our window */ MSG ChildWindowMsg; /* Here messages to the application are saved */ WNDCLASS ChildWindowClass; /* Data structure for the windowclass */ //HBRUSH background = CreateSolidBrush(RGB(255,222,173)); if( !GetClassInfo(ParentInstance,ChildWindowClassName,&ChildWindowClass) ) { ChildWindowClass.cbClsExtra = 0; ChildWindowClass.cbWndExtra = 0; ChildWindowClass.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH); ChildWindowClass.hCursor = LoadCursor(NULL,IDC_ARROW); ChildWindowClass.hIcon = LoadIcon(NULL,IDI_APPLICATION); ChildWindowClass.hInstance = ParentInstance; ChildWindowClass.lpfnWndProc = New_Window_Procedure; ChildWindowClass.lpszClassName = ChildWindowClassName; ChildWindowClass.lpszMenuName = MAKEINTRESOURCE(301); ChildWindowClass.style = CS_HREDRAW | CS_VREDRAW; if( !RegisterClass(&ChildWindowClass) ) { MessageBox(NULL,"Fensterklasse konnte nicht registriert werden!","Fehler",MB_OK); return 0; } } ChildWindow = CreateWindowEx(NULL, ChildWindowClassName, "Neue Überweisung", WS_CAPTION|WS_SYSMENU|WS_DLGFRAME, CW_USEDEFAULT, CW_USEDEFAULT, HEIGHT-200, WIDTH-200, ParentWindow, NULL, ParentInstance, NULL); if( !ChildWindow ) { MessageBox(NULL,"Fenster konnte nicht erstellt werden","Fehler",MB_OK); return 0; } ShowWindow(ChildWindow,SW_SHOWNORMAL); UpdateWindow(ChildWindow); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&ChildWindowMsg, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&ChildWindowMsg); /* Send message to WindowProcedure */ DispatchMessage(&ChildWindowMsg); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return (int)ChildWindowMsg.wParam; } LRESULT CALLBACK New_Window_Procedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) /* handle the messages */ { case WM_DESTROY: { HWND temp = FindWindowEx(GetParent(hwnd),hwnd,"Kontosimulation","Kontosimulation"); //ShowWindow(hwnd,SW_HIDE); ShowWindow(temp,SW_SHOW); DestroyWindow(hwnd); PostQuitMessage(0); break; } case WM_CREATE: { } case WM_COMMAND: { switch(LOWORD(wParam)) { case IDM_SCHLIESSEN: { HWND temp = FindWindowEx(GetParent(hwnd),hwnd,"Kontosimulation","Kontosimulation"); //ShowWindow(hwnd,SW_HIDE); ShowWindow(temp,SW_SHOW); DestroyWindow(hwnd); PostQuitMessage(0); break; } case IDM_ZUREUCK: { HWND temp = FindWindowEx(GetParent(hwnd),hwnd,"Kontosimulation","Kontosimulation"); //ShowWindow(hwnd,SW_HIDE); ShowWindow(temp,SW_SHOW); DestroyWindow(hwnd); PostQuitMessage(0); break; } }//ende switch(LOWORD(wParam) }//ende WM_COMMAND default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }und hier das window für den neuen benutzer
#include "Includes.h" LRESULT CALLBACK Neuer_Nutzer_Procedure (HWND , UINT , WPARAM , LPARAM ); int neuer_benutzer(HINSTANCE ParentInstance,HWND ParentWindow) { char ChildWindowClassName[ ] = "ChildWindow"; HWND ChildWindow; /* This is the handle for our window */ MSG ChildWindowMsg; /* Here messages to the application are saved */ WNDCLASS ChildWindowClass; /* Data structure for the windowclass */ //HBRUSH background = CreateSolidBrush(RGB(255,222,173)); if( !GetClassInfo(ParentInstance,ChildWindowClassName,&ChildWindowClass) ) { ChildWindowClass.cbClsExtra = 0; ChildWindowClass.cbWndExtra = 0; ChildWindowClass.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH); ChildWindowClass.hCursor = LoadCursor(NULL,IDC_ARROW); ChildWindowClass.hIcon = LoadIcon(NULL,IDI_APPLICATION); ChildWindowClass.hInstance = ParentInstance; ChildWindowClass.lpfnWndProc = Neuer_Nutzer_Procedure; ChildWindowClass.lpszClassName = ChildWindowClassName; ChildWindowClass.lpszMenuName = 0; ChildWindowClass.style = CS_HREDRAW | CS_VREDRAW; if( !RegisterClass(&ChildWindowClass) ) { MessageBox(NULL,"Fensterklasse konnte nicht registriert werden!","Fehler",MB_OK); return 0; } } ChildWindow = CreateWindowEx(NULL, ChildWindowClassName, "Neuer Benutzer", WS_CAPTION|WS_SYSMENU|WS_DLGFRAME, CW_USEDEFAULT, CW_USEDEFAULT, HEIGHT-250, WIDTH-250, ParentWindow, NULL, ParentInstance, NULL); if( !ChildWindow ) { MessageBox(NULL,"Fenster konnte nicht erstellt werden","Fehler",MB_OK); return 0; } ShowWindow(ChildWindow,SW_SHOWNORMAL); UpdateWindow(ChildWindow); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&ChildWindowMsg, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&ChildWindowMsg); /* Send message to WindowProcedure */ DispatchMessage(&ChildWindowMsg); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return (int)ChildWindowMsg.wParam; } LRESULT CALLBACK Neuer_Nutzer_Procedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HWND ENeuerBenutzer; HWND ENeueKundennummer; HWND BErstellen; switch (message) /* handle the messages */ { case WM_DESTROY: { DestroyWindow(hwnd); PostQuitMessage(0); break; } case WM_PAINT: { PAINTSTRUCT ps; RECT ClientArea; GetClientRect(hwnd,&ClientArea); HDC hDc = BeginPaint(hwnd,&ps); { SetBkMode(hDc,TRANSPARENT); TextOut(hDc, 10, 5*VABSTAND, "Neuer Benutzername:", 19); TextOut(hDc, 8, 10*VABSTAND, "Neue Kundennummer:",18); } break; } case WM_CREATE: { ENeuerBenutzer = CreateWindow("edit", "", WS_CHILD | WS_VISIBLE | WS_BORDER, 5*HABSTAND+120, 5*VABSTAND-2, 170, 20, hwnd, (HMENU)NEUER_BENUTZER, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE), NULL); ENeueKundennummer = CreateWindow("edit", "", WS_CHILD | WS_VISIBLE | WS_BORDER|ES_READONLY, 5*HABSTAND+120, 5*VABSTAND+48, 170, 20, hwnd, (HMENU)NEUE_KUNDENNUMMER, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE), NULL); BErstellen= CreateWindow("button", "Neuen User erstellen", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, 5*HABSTAND+142, 5*VABSTAND+90, 150, 22, hwnd, (HMENU)BT_HINZUFUEGEN, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE), NULL); } case WM_COMMAND: { switch(LOWORD(wParam)) { case BT_HINZUFUEGEN: { char neuer_user[1024]; fstream datei; stringstream str,str2; ostringstream stream; string nutzer; string nutzer_nummer; string temp; int zufall; datei.open("Benutzerdaten.txt",ios::in|ios::out); srand(unsigned(time(NULL))); while(datei>>temp) { zufall = rand()%10000+99999; stream<<zufall; string nummer(stream.str()); if(!GetDlgItemText(hwnd,NEUER_BENUTZER,neuer_user,1024)) { MessageBox(hwnd,"Bitte geben sie einen Benutzernamen ein!","Fehler",MB_ICONINFORMATION); break; } str<<neuer_user; str>>nutzer; nutzer_nummer = nutzer + nummer; if(nutzer_nummer == temp) { MessageBox(hwnd,"Fehler,dieser Benutzer existiert schon","Fehler!",MB_ICONERROR); break; } else { SetDlgItemText(hwnd,NEUE_KUNDENNUMMER,nummer.c_str()); MessageBox(hwnd,"Der Benutzer wird hinzugefügt","Hinweis",MB_ICONINFORMATION); break; } } datei.close(); datei.clear(); datei.open("Benutzerdaten.txt",ios::out|ios::app); datei<<nutzer_nummer<<endl; datei.close(); break; } }//ende switch(LOWORD(wParam) }//ende WM_COMMAND default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }so bitte erstmal nix dazu sagen ob etwas komisch gecodet ist. sondern ich habe ja dazu ne frage.
wenn ich nun zum beispiel auf neuen benutzer klicke, kommt das fenster wie es soll, jedoch schließe ich das fenster und klicke auf neue überweisung dann niommt neue überweisung alles das vom neuen benutzer an, buttons, und editfelder.
andersherum isses auch so.
ich hoffe ihr könnt mir helfen
