Results 1 to 5 of 5

Thread: Textout/drawtext in desktop HDC

  1. #1

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    Textout/drawtext in desktop HDC

    hello.
    what im trying to do is print text where the mouse is on the desktop. But when i use TextOut or DrawText API it just stays there, and makes a trail whereever the mouse goes. here is a picture of what i mean:

    bad painting

    How can i make this not happen, and have it clear out the text it printed out. Basically give it the effect that there is supposed to be text under the mouse.

    thanks all!

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    try this...

    PHP Code:
        PAINTSTRUCT ps;
        
    int x=0y=0;
        
    HDC ScreenDC=NULLMemoryDC=NULL;
        
    HBRUSH hBrush=NULLhOldBrush=NULL;
        
    HBITMAP hBitmap=NULLhOldBitmap=NULL;
        
    RECT rt1rt2;

            case 
    WM_PAINT:
                
    GetClientRect(hWnd, &rt1);
                
    ScreenDC BeginPaint(hWnd, &ps);

                
    MemoryDC CreateCompatibleDC(ScreenDC);
                
    hBitmap CreateCompatibleBitmap(ScreenDCrt1.right rt1.leftrt1.bottom rt1.top);
                
    hOldBitmap = (HBITMAP)SelectObject(MemoryDChBitmap);

                
    hBrush CreateSolidBrush(RGB(255,255,255));
                
    hOldBrush = (HBRUSH)SelectObject(MemoryDChBrush);
                
    FillRect(MemoryDC, &rt1hBrush);

                
    SetRect(&rt2xyy+50x+200); 
                
    DrawText(MemoryDC"Hello World"strlen("Hello World"), &rt2DT_LEFT);
                
    BitBlt(ScreenDCrt1.toprt1.leftrt1.right rt1.leftrt1.bottom rt1.topMemoryDC00SRCCOPY); 

                
    SelectObject(MemoryDChOldBrush);
                
    DeleteObject(hBrush);
                
    DeleteObject(hOldBrush);
                
    DeleteObject(hBitmap);
                
    DeleteObject(hOldBitmap);
                
    DeleteDC(MemoryDC);
                
                
    EndPaint(hWnd, &ps);
                break;
            case 
    WM_MOUSEMOVE:
                
    LOWORD(lParam);
                
    HIWORD(lParam);
                break; 
    regards,

  3. #3

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78
    thats going to create the same problem im having now.
    what your suggesting is creating a bitmap, textout to the bitmap, then transfer the bitmap to the desktop.

    why not just do this:

    Code:
    SetBkMode(hdc, TRANSPARENT);
    DrawText(hdc, "hello", 5, CRect(point.x, point.y, point.x +40, point.y + 40), DT_BOTTOM);
    what i need to know how to do is erase the text that i drew into the hdc. Invalidate, InvalidateRect API does not work to erase when working with the desktop DC.
    What you having it do is create a white brush and fill in the rectagle. all that will do is put a bunch of white blotches all over the screen instead of the text all over the screen.
    Last edited by ExciteMouse; Jul 29th, 2001 at 08:54 PM.

  4. #4
    Megatron
    Guest
    Send the WM_ERASEBKGND message write before you call DrawText().
    Code:
    case WM_MOUSEMOVE:
          SendMessage(hWnd, WM_ERASEBKGND, (WPARAM) hDC, 0);
          DrawText(...);
          break;

  5. #5

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78
    hmm.. thats not working either

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