|
-
Jul 29th, 2001, 06:33 PM
#1
Thread Starter
Lively Member
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!
-
Jul 30th, 2001, 09:03 AM
#2
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.
-
Jul 30th, 2001, 02:54 PM
#3
Thread Starter
Lively Member
hmm that doesnt work
-
Jul 30th, 2001, 03:13 PM
#4
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;
}
-
Jul 30th, 2001, 04:19 PM
#5
Thread Starter
Lively Member
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.
-
Jul 31st, 2001, 11:55 AM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|