Text im Editfeld verschmiert beim scrollen



  • mein problem ist ich weiß nicht wie ich dass ändern kann,..
    hier der source:

    #define STRICT
    #include <windows.h>
    #include <windowsx.h>
    #include <stdio.h>
    #include <stdlib.h>
    static LONG_PTR PrevWndProcEdit;
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK WndConsole(HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK EditWndProc (HWND , UINT , WPARAM , LPARAM );
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
        HWND     hWnd,hConsole;
        MSG      msg;
        WNDCLASS wcmain;
        WNDCLASS wcconsole;
    
        const char szAppName[] = "Editcontrol Tutorial";
    
        wcmain.style          = CS_HREDRAW | CS_VREDRAW;
        wcmain.lpfnWndProc    = WndProc;
        wcmain.cbClsExtra     = 0;
        wcmain.cbWndExtra     = 0;
        wcmain.hInstance      = hInstance;
        wcmain.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
        wcmain.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wcmain.hbrBackground  = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
        wcmain.lpszMenuName   = NULL;
        wcmain.lpszClassName  = szAppName;
    
        RegisterClass(&wcmain);
    
        hWnd = CreateWindow( szAppName,
                             "Editcontrol Tutorial",
                             WS_OVERLAPPEDWINDOW,
                             CW_USEDEFAULT,
                             CW_USEDEFAULT,
                             CW_USEDEFAULT,
                             CW_USEDEFAULT,
                             NULL,
                             NULL,
                             hInstance,
                             NULL );
    
        ShowWindow(hWnd, iCmdShow);
        UpdateWindow(hWnd);
        const char szConsoleName[] = "Console";
        wcconsole.style          = CS_HREDRAW | CS_VREDRAW;
        wcconsole.lpfnWndProc    = WndConsole;
        wcconsole.cbClsExtra     = 0;
        wcconsole.cbWndExtra     = 0;
        wcconsole.hInstance      = hInstance;
        wcconsole.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
        wcconsole.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wcconsole.hbrBackground  = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
        wcconsole.lpszMenuName   = NULL;
        wcconsole.lpszClassName  = szConsoleName;
        RegisterClass(&wcconsole);
        hConsole = CreateWindow( szConsoleName,
                             szConsoleName,
                             WS_OVERLAPPEDWINDOW,
                             CW_USEDEFAULT,
                             CW_USEDEFAULT,
                             CW_USEDEFAULT,
                             CW_USEDEFAULT,
                             NULL,
                             NULL,
                             hInstance,
                             NULL );
        ShowWindow(hConsole, iCmdShow);
        UpdateWindow(hConsole);
    
        while(GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    
        return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
    switch(message)
    {
     case WM_CREATE:
     {
    
          return 0;
     }
     case WM_SIZE:
     {
    
          return 0;
     }
     case WM_CLOSE:
     {
          SendMessage(FindWindow("Console","Console"),WM_CLOSE,(WPARAM)0,(LPARAM)0);
          DestroyWindow(hWnd);
          return 0;
     }
     case WM_DESTROY:
     {
          PostQuitMessage(0);
          return 0;
     }
    
     }
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    
    LRESULT CALLBACK WndConsole(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    static HWND hEdit;
    
        switch(message)
        {
        case WM_CREATE:
            {            FILE *fz;
                char *buffer = NULL;
                int iFileSize;
    
                fz = fopen("text.txt", "rb");
                if(fz != NULL)
                {
                    fseek(fz, 0, SEEK_END);
                    iFileSize = ftell(fz);
                    buffer = (char*)malloc(iFileSize);
    
                    fseek(fz, 0, SEEK_SET);
                    fread(buffer, 1, iFileSize, fz);
                    fclose(fz);
                }
    
                  hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
                                       "edit",
                                       buffer,    // <- 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);
                     PrevWndProcEdit = SetWindowLongPtr (hEdit, GWLP_WNDPROC, 
                                    (LONG_PTR) EditWndProc);       
                free(buffer);
    
                return 0;
            }
        case WM_SIZE:
            {MoveWindow(hEdit, 0, 0, 300, 300, TRUE);
            UpdateWindow(hEdit);
                return 0;
            }
        case WM_CLOSE:
            {FILE *fz;
                char *buffer = NULL;
                int iLength;
    
                iLength = GetWindowTextLength(hEdit);
    
                buffer = (char*)malloc(iLength);
    
                GetWindowText(hEdit, buffer, iLength+1);
    
                fz = fopen("text.txt", "wb");
                fwrite(buffer, 1, iLength, fz);
                fclose(fz);
    
                free(buffer);
    
                DestroyWindow(hWnd);
                return 0;
            }
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            }
        case WM_CTLCOLOREDIT:
             {
             SetBkMode((HDC)wParam,TRANSPARENT);         // Texthintergrund auf transparent setzen
            SetTextColor((HDC)wParam,RGB(255,255,255)); // Textfarbe auf Weiss setzen
            return (long)CreateSolidBrush(RGB(0,0,0)); 
             }
        }
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    LRESULT CALLBACK EditWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
       switch (message)
       {
          case WM_VSCROLL:
            {UpdateWindow(hwnd);}
             break;  
       }
    
    return CallWindowProc ((WNDPROC) PrevWndProcEdit, hwnd, message, wParam, lParam);
    }
    

    thx for help



  • ok,.. anstatt den hintergrund vom edit feld auf transparent zu stellen, sollte man direkt die bkColor auf schwarz setzen, dann passiert dass nicht,..
    gruuß



  • gibt es auch eine andere möglichkeit, das problem zu lösen??
    bei mir soll der hintergrund des editfelds nicht einfarbig werden:

    case WM_CTLCOLORSTATIC:
       SetBkMode ((HDC) wParam, TRANSPARENT);
       return (LONG) CreatePatternBrush(bitmap1);
    

    funktioniert alles, bis auf das verschmieren der schrift

    mfg ghill



  • hi,
    ich hab das problem jetzt erstmal so gelöst:

    LRESULT CALLBACK EditWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
       switch (message)
       {
          case WM_VSCROLL:
    		ShowWindow (hwnd, SW_HIDE) ;
    		ShowWindow (hwnd, SW_SHOW) ;
             break;
       }
    
    return CallWindowProc ((WNDPROC) PrevWndProcEdit, hwnd, message, wParam, lParam);
    }
    

    der text verschmiert jetzt nicht mehr, allerdings flackert das fenster beim scrollen....
    wäre über eine andere idee sehr dankbar.
    mfg ghill


Anmelden zum Antworten