VSCROLL und edit



  • hi leutz,
    ich habe ein kleines problem, ich bin auch neu, was mit winapi zu tun hat,..
    also ich habe zwo edit controlls, wenn das eine vertical scrolled soll das andere auch scrollen,..

    also ich verarbeite EM_SCROLL in dem einen fenster und schicke eine nachricht ans andere das auch scollen soll,.. wird das automatisch dann durch DefWindowProc() verarbeitet oder muss das denn auch manuell gemacht werden??
    hier mal der source:

    #define STRICT
    #include <windows.h>
    #include <windowsx.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string>
    using namespace std;
    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 );
    static HWND hEdit,hOffset;
    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)
    {
    
        switch(message)
        {
        case WM_CREATE:
            {            FILE *fz;
                char *buffer = NULL;
                string buffer2="1\r2\r3\r4\r5\r6\r7\r8\r\0";
    
    			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,
                                       51, 0, 400, 400,
                                       hWnd,
                                       NULL,
                                       ((LPCREATESTRUCT) lParam) -> hInstance,
                                       NULL);
                  hOffset = CreateWindowEx(WS_EX_CLIENTEDGE,
                                       "edit",
                                       "1\r2\r3\r4\r5\r6\r7\r8\r\0",    // <- das ist der Inhalt der Editfelds
                                       WS_CHILD | WS_VISIBLE | ES_MULTILINE |
                                                  ES_AUTOVSCROLL,
                                       0, 0, 50, 400,
                                       hWnd,
                                       NULL,
                                       ((LPCREATESTRUCT) lParam) -> hInstance,
                                       NULL);
                     PrevWndProcEdit = SetWindowLongPtr (hEdit, GWLP_WNDPROC, 
                                    (LONG_PTR) EditWndProc);       
                free(buffer);
    
                return 0;
            }
        case WM_SIZE:
            {MoveWindow(hEdit, 51, 0, 400,400, 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_PAINT:
             {
            //SetBkColor((HDC)wParam,RGB(0,0,0));         // Texthintergrund auf transparent setzen
            //SetTextColor((HDC)wParam,RGB(255,255,255)); // Textfarbe auf Weiss setzen
            return 0;//(long)CreateSolidBrush(RGB(0,0,0)); 
             }
    
        case WM_CTLCOLOREDIT:
             {
            SetBkColor((HDC)wParam,RGB(0,0,0));         // Texthintergrund auf transparent setzen
            SetTextColor((HDC)wParam,RGB(255,255,255)); // Textfarbe auf Weiss setzen
            return (long)CreateSolidBrush(RGB(0,0,0)); 
             }
        case WM_CTLCOLORSTATIC:
             {
            SetBkColor((HDC)wParam,RGB(0,0,0));         // 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 EM_SCROLL:
            {SendMessage(hOffset,EM_SCROLL,wParam,(LPARAM) 0);
             break;  
    		 }
       }
    
    return CallWindowProc ((WNDPROC) PrevWndProcEdit, hwnd, message, wParam, lParam);
    }
    

    danke für eure hilfe...


Anmelden zum Antworten