dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 16

Thread: [RESOLVED] Edit Control and text with transparent background scroll issue

Threaded View

  1. #1
    Join Date
    Feb 2012
    Location
    Italy
    Posts
    9

    [RESOLVED] Edit Control and text with transparent background scroll issue

    Hallo Everybody,
    need some help as I can't figoure out how to solve this problem:
    I've a edit control setted as multiline, autovscroll etc, and by WM_CTLCOLOREDIT I'm able to set a black background and a text color with transparent background. The issue comes in when i fill te edit with some text out of te edit window, and exactly when i scroll with the scroll bar cursor the text draws on top of itself and creates garbage like the attache picture.
    I've solved partially the issue subclassing the edit and perform a ShowWindow(hwnd, SW_HIDE) with sequentially ShowWindow(hwnd, SW_SHOW) when the left mouse button (WM_LBUTTONDOWN) is pushed on the scroll cursor (that trough a Timer Procedure)
    But this does not solve completely the issue, the "Ghost" text is still there for some milliseconds.
    Sorry for my bad english.
    Here's my full code:

    Code:
    #include <windows.h>
    
    #define IDC_EDIT 101
    
    LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
    LRESULT APIENTRY EditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    VOID CALLBACK ProceduraTimer(HWND hwnd, UINT msg, UINT idEvent, DWORD dwTime);
    
    //Puntatore a WindowProcedure originale
    //(variabile globale);
    WNDPROC wpOrigWindowProc = 0;
    
    
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, 
        LPSTR lpCmdLine, int nCmdShow)
    {
      HWND hwnd;
      MSG  msg ;    
      WNDCLASS wc = {0};
      wc.lpszClassName = TEXT("GroupBox");
      wc.hInstance     = hInstance ;
      wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
      wc.lpfnWndProc   = WndProc ;
      wc.hCursor       = LoadCursor(0,IDC_ARROW);
    
      HINSTANCE g_hinst = hInstance;
      
      RegisterClass(&wc);
      hwnd = CreateWindow(wc.lpszClassName, TEXT("GroupBox"),
                          WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                          600, 200, 400, 450, 0, 0, hInstance, 0);  
                          
      while(GetMessage(&msg, NULL, 0, 0)) {
           TranslateMessage(&msg);
           DispatchMessage(&msg);
      }
      return (int)msg.wParam;
    }
    
    LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
    {
      HWND hwndEdit;
      DWORD CtrlEsitoID;
      HFONT hFont;
      HBRUSH hBrushCtrlBG;
      HDC hdcEdit;
      HWND hwndFocus = 0;
      HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
    
      switch(msg)  
      {
          
          case WM_CREATE:
               
                  hwndEdit = CreateWindow(TEXT("Edit"), NULL,
                                WS_TABSTOP | WS_CHILD | WS_VISIBLE | ES_WANTRETURN | WS_BORDER | 
                                WS_CLIPCHILDREN | ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL,
                                10, 10, 360, 340, hwnd, (HMENU)IDC_EDIT, 0, 0);
                                
                                
                  //Installazione del Subclassing del controllo edit (registriamo
                  //il valore della Window Procedure precedente);
                  wpOrigWindowProc = (WNDPROC)SetWindowLong(hwndEdit, GWL_WNDPROC, 
                                                           (LONG)EditSubclassProc);
                  
                  hFont = CreateFont(10, 10, 0, 0, FW_EXTRALIGHT, FALSE, FALSE, FALSE, 
                                      DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 
                                      CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
                                      DEFAULT_PITCH, "MS Sans Serif");
                                      
                  SendMessage(hwndEdit, WM_SETFONT, (WPARAM)hFont, 0); 
                  break;
    
    
          case WM_COMMAND:
                  if((HIWORD(wParam) == BN_PUSHED)) {            
                                    SetTimer(hwnd, LOWORD(wParam), 200, ProceduraTimer);
    							}
                  if(HIWORD(wParam) == BN_UNPUSHED) {
                                    KillTimer(hwnd,HIWORD(wParam));
                                    ShowWindow((HWND)lParam, SW_HIDE);
                                    UpdateWindow((HWND)lParam);
                                    ShowWindow((HWND)lParam,SW_SHOW);
    							}
                  break;
    
    
          case WM_DESTROY:
                  //Rimuovo il subclass dal controllo edit
                  SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG)wpOrigWindowProc);
                  PostQuitMessage(0);
                  break; 
                
                  
          case WM_CTLCOLOREDIT:
                  CtrlEsitoID = GetDlgCtrlID((HWND)lParam);
                  if (CtrlEsitoID == IDC_EDIT)  {
                      hBrushCtrlBG = CreateSolidBrush(RGB(0, 0, 0));
                      hdcEdit = (HDC)wParam;
                      SetTextColor(hdcEdit, RGB(71, 239, 235));
                      //SetBkColor(hdcEdit, RGB(0, 0, 0));
                      SetBkMode(hdcEdit, TRANSPARENT);
                      return (LONG)hBrushCtrlBG;  
                  }
                  break;
                  
           case WM_LBUTTONDOWN: 
                  //if(wParam == MK_LBUTTON)
                  break; 
                    
      }
      return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    
    //Procedura di Subclass
    LRESULT APIENTRY EditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        UINT code = 0;
        switch(uMsg)  {
               case WM_LBUTTONDOWN: code = BN_PUSHED; break;
               case WM_LBUTTONUP:   code = BN_UNPUSHED; break;
        }
        if(code)
               SendMessage(GetParent(hwnd), WM_COMMAND, 
                          MAKELONG(GetDlgCtrlID(hwnd), code), 
                          (LPARAM)hwnd);
        if(wpOrigWindowProc)
               return CallWindowProc(wpOrigWindowProc, hwnd, uMsg, wParam, lParam);
        return 0;
    }
    
    VOID CALLBACK ProceduraTimer(HWND hwnd, UINT msg, UINT idEvent, DWORD dwTime)
    {
       HWND hwndCtrl = GetDlgItem(hwnd, idEvent);
       ShowWindow(hwndCtrl, SW_HIDE);
       UpdateWindow(hwndCtrl);
       ShowWindow(hwndCtrl,SW_SHOW); 
    }
    Any help is very very appreciated, i'm trying to solve this frmo 3 days.
    Thank's in advance.
    Attached Images Attached Images  
    Last edited by ovidiucucu; February 15th, 2012 at 08:33 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)