Results 1 to 6 of 6

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
    Megatron
    Guest
    You need to send the WM_ERASEBKGND message. The function below is an example. It's not perfect, but you could probably fix it up.
    Code:
    // lpText = Text to draw
    // Rect = rectangle to draw in
    void DrawTxt(HWND hWnd, LPCTSTR lpText, RECT &rect)
    {
    	HDC hDC = GetDC(hWnd);
    	SendMessage(hWnd, WM_ERASEBKGND, (WPARAM)hDC,0);
    	DrawText(hDC, lpText, -1, rect, DT_CENTER);
    	ReleaseDC(hWnd, hDC);
    }
    Then just call it in the WM_MOUSEMOVE event.

  3. #3

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

  4. #4
    Megatron
    Guest
    I left all the "dirty" work for you to do (e.g: getting the handle of a window, sending the text, and creating the rectangle).

    I guess if you don't need a generic function, then you can just create "fixed values" e.g:
    Code:
    case WM_MOUSEMOVE: 
    {
    	HDC hDC = GetDC(hWnd);
    	LPCTSTR lpText = "Hello";
    	POINT pt;
    	RECT rc;
    	GetCursorPos(&pt);
    	rc.left = pt.x - 20;
    	rc.top = pt.y - 20;
    	rc.right = pt.x + 20;
    	rc.bottom = pt.y + 20;
    	SendMessage(hWnd, WM_ERASEBKGND, (WPARAM) hDC, 0);
    	DrawText(hDC, lpText, -1, &rc, DT_LEFT | DT_TOP);
    	ReleaseDC(hWnd, hDC);
    	break;
    }

  5. #5

    Thread Starter
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78
    i did all the dirty work.
    do you realize that im not using TextOut on a regular window?
    im using it on the desktop.
    when the mouse is over the desktop i want to textout.
    i use SetCapture() to capture the mouse events.
    when i get a WM_MOUSEMOVE i do exactly what your saying.

    and nothing happens.

  6. #6
    Megatron
    Guest
    What's your code so far?

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