[WinAPI] kleines Edit Feld? - Hilfe



  • Hallo Leute.

    Ich bin neu im Thema WinAPI und wollte nachdem Grundlagen lernen (Fenster , Buttons, Edits etc.) mal einen kleinen Scantime-Crypter schreiben.
    Er soll EXE-Dateien Crypten.

    Da ich nicht weiß , ob es in C++ auch sowas wie ein Common-Dialog gibt, wollte ich es mit einem kleinen Editfeld machen.
    Ich hab das ganze so versucht:

    hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
                                       "edit",
                                       "C:\crypten.exe",    // <- das ist der Inhalt der Editfelds
                                       WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE |
                                                  ES_AUTOVSCROLL,
                                       0, 0, 0, 0,
                                       hWnd,
                                       NULL,
                                       ((LPCREATESTRUCT) lParam) -> hInstance,
                                       NULL);
    

    Das funzt jedoch nicht , weil das Edit Feld dann , wie im Texteditor , ganz groß ist.
    Ich suche das >KLEINE< Edit Feld - ihr wisst schon.

    Wenn ich WS_VSCROLL,ES_MULTILINE und das ES_AUTOVSCROLL weglasse, bleibt trotzdem der ganze Hintergrund weiß statt grau. 😞

    Kann mir jemand helfen?

    Danke..



  • erstens gibt es eine common dlg
    kuck dich mal nach OPENFILENAME bzw. BROWSEINFO um.
    und zweitens würde ich es mal mit WS_DISABLED versuchen.



  • Für was stehen wohl diese Paranter: "0, 0, 0, 0,"?



  • Edit: war müll



  • Erstmal danke für die vielen Antworten.
    Aber:
    der einzigst passende Vorschlag war "WS_DISABLED" & der macht die Edit-Box nur aus.
    Das man nichts mehr rein schrieben kann.

    Ich will sie jedoch KLEIN.
    das habe ich nun auch geschafft (kein Multiline & Scrolling etc. mehr) aber der ganze Hintergrund bleibt weiß , wie beim Texteditor.

    Hilfe !



  • Luckie schrieb:

    Für was stehen wohl diese Paranter: "0, 0, 0, 0,"?

    Erst Probieren - Dann posten.

    Sorry aber - wenn ich diese Parameter in einen anderen Wert verändere ändert sich GARNICHTS.

    Mein Problem ist mittlerweile ausserdem nichtmehr, dass die Box so groß ist (sie ist jetzt klein) , sondern dass trotzdem der ganze Hintergrund weiß ist, als wäre sie groß.



  • zeig mal den WM_PAINT-code.



  • Editfeld in Farbe?
    http://www.c-plusplus.net/forum/viewtopic-var-t-is-39375.html

    Ich hoffe das das das Farbige ist was du vermisst.



  • Ich will dsa Edit Feld nicht färben.
    Ich will , dass es ganz weiß bleibt.
    jedoch nur so groß wie es ist.

    Kurz und Knapp :
    Hat niemand hier ein Quellcode von einem Edit-Feldchen dass normale Größe hat und nur da weiß ist, wo man auch schreiben kann & NICHT das ganze Fenster bedeckt?



  • vor dem registrieren der Fensterklasse (RegisterClassEx) musst du doch eine struktur ausfüllen (WNDCLASSEX)
    die hat ein member hbrBackground
    dem kannst du irgend ein Brush zuweisen.

    entweder mit:

    wcex.hbrBackground	= CreateSolidBrush(0x357653);
    

    oder mit einer vorgefertigten Konstanten + 1
    Wenn jemand weiß, warum man eins draufaddieren muss, immer her mit dem grund.

    wcex.hbrBackground	= (HBRUSH)(COLOR_BTNFACE+1); // BUTTON_FACE ist die Standard-Schaltflächenfarbe, die eingestellt ist.
    


  • vlad_tepesch schrieb:

    vor dem registrieren der Fensterklasse (RegisterClassEx) musst du doch eine struktur ausfüllen (WNDCLASSEX)
    die hat ein member hbrBackground
    dem kannst du irgend ein Brush zuweisen.

    entweder mit:

    wcex.hbrBackground	= CreateSolidBrush(0x357653);
    

    oder mit einer vorgefertigten Konstanten + 1
    Wenn jemand weiß, warum man eins draufaddieren muss, immer her mit dem grund.

    wcex.hbrBackground	= (HBRUSH)(COLOR_BTNFACE+1); // BUTTON_FACE ist die Standard-Schaltflächenfarbe, die eingestellt ist.
    

    Bleibt trotzdem weiß.

    Ich poste jetzt mal meinen Gesamten Quellcode , vlt. könnt ihr ja was entdecken..:

    #include <windows.h>
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                       PSTR szCmdLine, int iCmdShow)
    {
       MSG        msg;
       HWND       hWnd;
       WNDCLASS   wc;
    
       const char szAppName[]  = "urCrypt v1.0 Beta [Public Edition]";
    
       wc.cbClsExtra           = 0;
       wc.cbWndExtra           = 0;
       wc.hbrBackground    = (HBRUSH)(COLOR_BTNFACE+1);; 	
       wc.hCursor              = LoadCursor(NULL, IDC_ARROW);
       wc.hIcon                = LoadIcon(NULL, IDI_APPLICATION);
       wc.hInstance            = hInstance;
       wc.lpfnWndProc          = WndProc;
       wc.lpszClassName        = szAppName;
       wc.lpszMenuName         = NULL;
       wc.style                = CS_HREDRAW | CS_VREDRAW;
    
       RegisterClass(&wc);
    
       hWnd = CreateWindow(    szAppName,
                               szAppName,
                               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 HWND hButton;
    	 static HWND hEdit;
    
       switch (message)
       {
       case WM_CREATE:
          {
    		    hButton = CreateWindow(  "button",
                                      "Crypt !",
                                      WS_CHILD | WS_VISIBLE,
                                      0, 0, 0, 0,
                                      hWnd,
                                      NULL,
                                      ((LPCREATESTRUCT) lParam) -> hInstance,
                                      NULL);
             hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
                                       "edit",
                                       "C:\crypten.exe",    // <- das ist der Inhalt der Editfelds
                                       WS_CHILD | WS_VISIBLE ,
                                       0, 0, 0, 0,
                                       hWnd,
                                       NULL,
                                       ((LPCREATESTRUCT) lParam) -> hInstance,
                                       NULL);
    
    			return 0;
          }
    
    case WM_SIZE:
          {
    
    		   MoveWindow(hButton, LOWORD(lParam) / 2 - 80, HIWORD(lParam) - 30, 
                                                          160, 22, TRUE);
    
    		   MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
    
    		   return 0;
    	  }
    
    	  case WM_COMMAND:
          {
             if (lParam == (LPARAM)hButton)
             {
                if (HIWORD(wParam) == BN_CLICKED)
                   SendMessage(hWnd, WM_CLOSE, 0, 0);  //Hier kommt noch die Crypt-Funktion hin^^
             }
             return 0;
          }
       case WM_DESTROY:
          {
             PostQuitMessage(0);
             return 0;
          }
       }
       return DefWindowProc(hWnd, message, wParam, lParam);
    }
    


  • Ok, dein Problem ist, dass das edit-felfd maximiert ist.
    Keine Ahnung warum, aber wenn ich mein standard-miniaml-template nehme und deine zwei controlls einfüge (und ihnen position und breite gebe), werden die so angezeigt, wie man es erwartet hätte.

    // MinWInApp.cpp : Defines the entry point for the application.
    //
    #include <windows.h>
    
    // C RunTime Header Files
    #include <stdlib.h>
    #include <malloc.h>
    #include <memory.h>
    #include <tchar.h>
    
    #include "MinWInApp.h"
    
    #define MAX_LOADSTRING 100
    #define SZ_TITLE "MinWinApp"
    #define SZ_WND_CLASS "MINWINAPP"
    
    // Global Variables:
    HINSTANCE g_hInst;                // current instance
    HWND g_hWnd;
    
    TCHAR* szWndClass = TEXT(SZ_WND_CLASS);
    
    LRESULT CALLBACK  WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int APIENTRY _tWinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR    lpCmdLine,
                         int       nCmdShow)
    {
      UNREFERENCED_PARAMETER(hPrevInstance);
      UNREFERENCED_PARAMETER(lpCmdLine);
    
       // TODO: Place code here.
      MSG msg;
    
      WNDCLASSEX wcex;
    
      wcex.cbSize = sizeof(WNDCLASSEX);
    
      wcex.style      = CS_HREDRAW | CS_VREDRAW;
      wcex.lpfnWndProc  = WndProc;
      wcex.cbClsExtra    = 0;
      wcex.cbWndExtra    = 0;
      wcex.hInstance    = hInstance;
      wcex.hIcon      = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MINWINAPP));
      wcex.hCursor    = LoadCursor(NULL, IDC_ARROW);
      wcex.hbrBackground  = (HBRUSH)(COLOR_BTNFACE+1);
      wcex.lpszMenuName  = NULL;
      wcex.lpszClassName  = szWndClass;
      wcex.hIconSm    = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
      RegisterClassEx(&wcex);
    
       g_hInst = hInstance; // Store instance handle in our global variable
       g_hWnd = CreateWindow(szWndClass, TEXT(SZ_TITLE), WS_OVERLAPPEDWINDOW,
                             CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
    
       if (!g_hWnd)
       {
          return FALSE;
       }
    
       ShowWindow(g_hWnd, nCmdShow);
       UpdateWindow(g_hWnd);
    
      // Main message loop:
      while (GetMessage(&msg, NULL, 0, 0))
      {
    
          TranslateMessage(&msg);
          DispatchMessage(&msg);
      }
    
      return (int) msg.wParam;
    }
    
    //
    //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
    //
    //  PURPOSE:  Processes messages for the main window.
    //
    //  WM_COMMAND  - process the application menu
    //  WM_PAINT  - Paint the main window
    //  WM_DESTROY  - post a quit message and return
    //
    //
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
      int wmId, wmEvent;
      PAINTSTRUCT ps;
      HDC hdc;
    
      switch (message)
      {
      case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
        case 0:
        default:
          return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
      case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        // TODO: Add any drawing code here...
        EndPaint(hWnd, &ps);
        break;
      case WM_DESTROY:
        PostQuitMessage(0);
        break;
      default:
        return DefWindowProc(hWnd, message, wParam, lParam);
      }
      return 0;
    }
    


  • vlad_tepesch schrieb:

    Ok, dein Problem ist, dass das edit-felfd maximiert ist.
    Keine Ahnung warum, ...

    case WM_SIZE:
    {
    ...         
     MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); :open_mouth: 
    ...
    }
    


  • ok, das move window hab ich mir net weiter angeguckt, wer ist schon so dämlich und bewegt und maximiert controlls 😕 😕 😕



  • DANKE MAN..
    Habs endlich...

    DANKE!


Log in to reply