CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Sep 2009
    Posts
    8

    Edit control with transparent background scrolling issue

    I'm trying to make a EULA. So I have a multi line read-only edit control that the user needs to be able to scroll down on.

    Additionally, since I'm using a custom skin for my main window background, the edit control background has to be transparent other wise it looks really ugly.

    I simply used the WS_VSCROLL style to obtain the vertical scroll bar. The problem is that when I scroll down then up, the text doesn't refresh, i.e it draws on top of itself and creates garbage.

    I've done some research, and I know that this is why:

    Code:
    case WM_CTLCOLORSTATIC: // Makes the static control backgrounds transparent
                ::SetBkMode((HDC)wParam, TRANSPARENT);
                return (LRESULT)::GetStockObject(NULL_BRUSH);   // Return NULL brush
    What I don't know is how to fix it.
    I've tried doing something like this:

    Code:
    case WM_SETTEXT:        // Ensures that text is not drawn on top of previous text
                if ( GetDlgCtrlID (hDlg) == EDIT_CONTROL_ID){ 
                    ::InvalidateRect( hDlg, NULL, TRUE);
                    DefWindowProc(hDlg, WM_SETTEXT, 0, lParam);
                }
    This exact same code worked for a similar problem I had updating static text, but doesn't seem to work on the edit control (I'm guessing cause it doesn't fire a WM_SETTEXT on a scroll). I'm sure I have to intercept the EN_VSCROLL notification, but so far nothing I've tried has worked.

    Any help is appreciated! (I'm also pretty new to win32 development)



    EDIT: Ok, so I made some progress, but not much.. still need some help.

    Code:
    case WM_COMMAND:        // COMMAND MESSAGE
    		    wmId    = LOWORD(wParam);
    		    wmEvent = HIWORD(wParam);
    		    // Parse the menu selections:
    		    switch (wmId) {
    			    case EDIT_ID:
    			        if (wmEvent == EN_VSCROLL){
    			            ::ShowWindow (GetDlgItem(hDlg, wmId), SW_HIDE);
    			            ::SetDlgItemText (hDlg, wmId, g_eulaText);
    			            ::ShowWindow (GetDlgItem(hDlg, wmId), SW_SHOW);
    			            ::SetFocus(GetDlgItem(hDlg, wmId));
    			        }
    			        return TRUE;
    then

    Code:
    case WM_SETTEXT:        // Ensures that text is not drawn on top of previous text
                if ( GetDlgCtrlID (hDlg) == EDIT_ID){     
                    ::InvalidateRect( hDlg, NULL, TRUE);
                    DefWindowProc(hDlg, WM_SETTEXT, 0, lParam);
                } 
                break;
    This has two major problems.

    1. It turns the background into non-transparent (even though it still acts as a transparent background... see 2)
    2. When I click and drag the scroll bar, it still draws on top of itself

    Actually, just found out that EN_VSCROLL doesn't get sent when the user clicks on the actual scroll bar, which means that capturing EN_VSCROLL might not work... sigh
    Last edited by ahal89; September 25th, 2009 at 02:41 PM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured