Edit geht nicht ?!



  • Hallo
    Ich bin wieder mit meine Anfänger Schuhen am herumlaufen und wieder gegen eine Mauer geknallt.
    Könntet ihr mir vielleicht sagen warum ich in das Edit Feld nichts
    eintragen kann ?????

    #include <windows.h>
    
    LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
    LRESULT CALLBACK ChildProc( HWND, UINT, WPARAM, LPARAM );
    
    char szName[] = "Fensterklasse";
    char szName1[] = "Fensterklasse1";
    HINSTANCE g_hI; 
    
    int WINAPI WinMain( HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow )
    {
    
      WNDCLASS wc;
    
      wc.style = CS_HREDRAW | CS_VREDRAW ;
      wc.lpfnWndProc = WndProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 1;
      wc.hInstance = hI;
      wc.hIcon = LoadIcon( NULL, IDI_WINLOGO );
      wc.hCursor = LoadCursor( NULL, IDC_ARROW );
      wc.hbrBackground = ( HBRUSH )GetStockObject( LTGRAY_BRUSH );
      wc.lpszMenuName = NULL;
      wc.lpszClassName = szName;
    
      RegisterClass( &wc );
    
    //-----------------------------------------------------------------------------------------------------------------------------------------
      wc.style = CS_HREDRAW | CS_VREDRAW  ;
      wc.hbrBackground = ( HBRUSH )GetStockObject( LTGRAY_BRUSH );
      wc.lpfnWndProc = ChildProc;
      wc.lpszMenuName = NULL;
      wc.lpszClassName = szName1;
    
      RegisterClass( & wc );
    //-----------------------------------------------------------------------------------------------------------------------------------------
      HWND hwnd = CreateWindow // Fenster 1
           ( szName, "Hauptfenster", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
           CW_USEDEFAULT, NULL, NULL, hI, NULL );
    
      ShowWindow( hwnd, SW_SHOWMAXIMIZED );
      UpdateWindow( hwnd );
    //-----------------------------------------------------------------------------------------------------------------------------------------
      MSG msg;
      while ( GetMessage( & msg, NULL, 0, 0 ) )
      {
        TranslateMessage( & msg );
        DispatchMessage( & msg );
      }
      return msg.wParam;
    }
    //-----------------------------------------------------------------------------------------------------------------------------------------
    //-----------------------------------------------------------------------------------------------------------------------------------------
    //-----------------------------------------------------------------------------------------------------------------------------------------
    
    LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
    {
      HDC hdc;
      PAINTSTRUCT ps;
     HWND hwndButton1, hwnd2;//hier
     HWND hText;
      switch ( message )
      {
    //-----------------------------------------------------------------------------------------------------------------------------------------    
    //    case WM_PAINT:
    
    //      return 0;
    //-----------------------------------------------------------------------------------------------------------------------------------------
    
        case WM_CREATE:
                       hText = CreateWindow("STATIC", "Kein Wert",
                        WS_VISIBLE | WS_CHILD, 30, 30, 100, 16, hwnd, NULL, g_hI, NULL);
    
                       hwndButton1 = CreateWindow
               ( "button", "Knopf 1", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 150, 20, 100, 40, hwnd, NULL,
               ( HINSTANCE )GetWindowLong( hwnd, GWL_HINSTANCE ), NULL );
          return 0;
    //----------------------------------------------------------------------------------------------------------------------------------------
        case WM_COMMAND:
          hwnd2 = CreateWindow( szName1, "Eingabefenster", WS_CHILDWINDOW | WS_OVERLAPPEDWINDOW | WS_VISIBLE, 300, 500, 500, 200,
               hwnd, (HMENU)(1), (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL );
          return 0;
    //-----------------------------------------------------------------------------------------------------------------------------------------
        case WM_DESTROY:
          PostQuitMessage( 0 );
          return 0;
      }
    
      return DefWindowProc( hwnd, message, wParam, lParam );
    }
    //-----------------------------------------------------------------------------------------------------------------------------------------
    //-----------------------------------------------------------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------------------------------------
    LRESULT CALLBACK ChildProc( HWND hwnd2, UINT message, WPARAM wParam, LPARAM lParam )
    {
      HDC hdc;
      PAINTSTRUCT ps;
     static HWND hwndButton2,hwndEdit2;
    
      switch ( message )
      {
      case WM_CREATE : 
            SendMessage(hwndEdit2, EM_SETREADONLY, FALSE, 0);
          hwndButton2 = CreateWindow ( "button", "Knopf 1", 
                                       WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
                                       150, 20, 100, 40, hwnd2, NULL, 
                                       (HINSTANCE) GetWindowLong (hwnd2, GWL_HINSTANCE), NULL); 
    
      hwndEdit2   = CreateWindow ( "edit", "Edit-Feld", 
                                       WS_CHILD | WS_VISIBLE, 
                                       251, 20, 100, 40, hwnd2, NULL, 
                                       (HINSTANCE) GetWindowLong (hwnd2, GWL_HINSTANCE), NULL); 
      return 0; 
    
      case WM_COMMAND: 
    
      return 0;
    
          	case WM_CLOSE:
    		DestroyWindow(hwnd2);
    		return 0;
      }
    
      return DefWindowProc( hwnd2, message, wParam, lParam );
    }
    


  • Rabbit 007 schrieb:

    case WM_COMMAND: 
          hwnd2 = CreateWindow(
    

    CreateWindow sollte auf die Nachricht WM_CREATE reagieren



  • JA habe Ich verschoben und ausprobiert aber der gleiche effekt !!
    Aber ich möchte ja das das Fenster erst auf geht nachdem ich auf den Button
    gedrückt habe.



  • Dein Handle ist sofort ungültig, der muss statisch sein:

    HWND hwndButton1, hwnd2;//hier
    

    ➡

    static HWND hwndButton1, hwnd2;//hier
    


  • Das war aber auch nicht des Rätsels Lösung
    immer noch das gleiche wie vorher !!???



  • Rabbit 007 schrieb:

    Das war ber auch nicht des Rätzels Lösung
    immer noch das gleiche wie vorher !!???

    OMG, wie wärs mit nem Tut.? ....

    szName1 ... ➡ "EDIT" ⚠



  • CodeFinder schrieb:

    Rabbit 007 schrieb:

    Das war ber auch nicht des Rätzels Lösung
    immer noch das gleiche wie vorher !!???

    OMG, wie wärs mit nem Tut.? ....

    szName1 ... ➡ "EDIT" ⚠

    Leider hilft mir das kein Stück weiter.
    Wenn Du das bitte in einen Satz packen könntest wäre ich dir sehr verbunden.



  • Für ein Editfeld musst du die vordefinierte Speicherklasse EDIT in den 1. Parameter der Funktion CreateWindow eintragen. Das hast du nicht ⚠ getan.

    Ups das waren 2 😃 .



  • Es tut mir Leid aber ich kann das nicht umsetzen.
    Ich erhalte immer die Fehlermeldung:

    107:90 C:\Dev-Cpp\main.cpp macro "CreateWindowA" passed 12 arguments, but takes just 11
    C:\Dev-Cpp\main.cpp In function LRESULT ChildProc(HWND__*, UINT, WPARAM, LPARAM)': 104 C:\\Dev-Cpp\\main.cppCreateWindowA' undeclared (first use this function)

    hwndEdit2   = CreateWindow ( szName1, "EDIT", "4711", 
                                       WS_CHILD | WS_VISIBLE, 
                                       251, 20, 100, 40, hwnd2, NULL, 
                                       (HINSTANCE) GetWindowLong (hwnd2, GWL_HINSTANCE), NULL);
    


  • case WM_COMMAND:
          hwnd2 = CreateWindow( "EDIT", "Eingabefenster", WS_CHILDWINDOW | WS_OVERLAPPEDWINDOW | WS_VISIBLE, 300, 500, 500, 200,
               hwnd, (HMENU)(1), (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL );
          return 0;
    


  • Das bringt das System nur zum Stillstand. Schade



  • Rabbit 007 schrieb:

    Das bringt das System nur zum Stillstand. Schade

    Junge, lern WinAPI, am besten von Anfang an!

    #include <windows.h>
    
    #define BTN_CREATE_EDIT_BOX  (4001)
    #define EBX_SHOW_SOME_INFO   (4002)
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
       static TCHAR szAppName[] = TEXT ("Klassenname");
       HWND         hwnd;
       MSG          msg;
       WNDCLASSEX   wndclassex = {0};
    
       wndclassex.cbSize        = sizeof(WNDCLASSEX);
       wndclassex.style         = CS_HREDRAW | CS_VREDRAW;
       wndclassex.lpfnWndProc   = WndProc;
       wndclassex.cbClsExtra    = 0;
       wndclassex.cbWndExtra    = 0;
       wndclassex.hInstance     = hInstance;
       wndclassex.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
       wndclassex.hCursor       = LoadCursor (NULL, IDC_ARROW);
       wndclassex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
       wndclassex.lpszMenuName  = NULL;
       wndclassex.lpszClassName = szAppName;
       wndclassex.hIconSm       = wndclassex.hIcon;
    
       if (!RegisterClassEx (&wndclassex))
       {
          MessageBox (NULL, TEXT ("RegisterClassEx fehlgeschlagen!"),
                      szAppName, MB_ICONERROR);
          return (0);
       }
    
       hwnd = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW, // erweiterter Fensterstil
                      szAppName, // Name der Fensterklasse
                      TEXT ("Fenstertitel"), // Fenstertitel
                      WS_OVERLAPPEDWINDOW, // Fensterstil
                      CW_USEDEFAULT, // X-Position des Fensters                      
                      CW_USEDEFAULT, // Y-Position des Fensters       
                      400, // Fensterbreite                 
                      400, // Fensterhöhe                
                      NULL, // übergeordnetes Fenster
                      NULL, // Menü           
                      hInstance, // Programm-Kopiezähler (Programm-ID)            
                      NULL); // zusätzliche Parameter
    
       ShowWindow (hwnd, iCmdShow);
       UpdateWindow (hwnd);
    
       while (GetMessage (&msg, NULL, 0, 0))
       {
          TranslateMessage (&msg);
          DispatchMessage (&msg);
       }
       return msg.wParam;
    }
    
    // Die Hauptnachrichtenschleife
    LRESULT CALLBACK WndProc (HWND hwnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)
    {
       static HWND hebxShow,
                   hbtCreate;
    
       switch (uiMessage)
       {
       case WM_CREATE:
          hbtCreate = CreateWindowEx(0L, TEXT("BUTTON"), TEXT("Erstelle das Editfeld!"), 
             WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, (400 - 100) / 2, (400 - 20) / 2, 100, 20, hwnd, reinterpret_cast<HMENU>(BTN_CREATE_EDIT_BOX),
             reinterpret_cast<LPCREATESTRUCT>(lParam)->hInstance, NULL);
          return (0L);
    
       case WM_COMMAND:
          if(LOWORD(wParam) == BTN_CREATE_EDIT_BOX)
          {
             ShowWindow(hbtCreate, SW_HIDE);
             hebxShow = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT("Das ist wirklich nicht schwer!"), 
                  WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,                  
                  0, 0, 400, 400, hwnd, reinterpret_cast<HMENU>(EBX_SHOW_SOME_INFO), reinterpret_cast<LPCREATESTRUCT>(lParam)->hInstance,
                  NULL);
          }
          return (0L);
    
       case WM_DESTROY:
          PostQuitMessage(0);
          return (0L);
       }
    
       return (DefWindowProc(hwnd, uiMessage, wParam, lParam));
    }
    

    EDIT: Hab das NICHT getestet....Dazu kb mehr gehabt... 😃 .


Anmelden zum Antworten