|
-
Jul 29th, 2001, 06:36 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 29th, 2001, 08:11 PM
#2
PowerPoster
try this...
PHP Code:
PAINTSTRUCT ps;
int x=0, y=0;
HDC ScreenDC=NULL, MemoryDC=NULL;
HBRUSH hBrush=NULL, hOldBrush=NULL;
HBITMAP hBitmap=NULL, hOldBitmap=NULL;
RECT rt1, rt2;
case WM_PAINT:
GetClientRect(hWnd, &rt1);
ScreenDC = BeginPaint(hWnd, &ps);
MemoryDC = CreateCompatibleDC(ScreenDC);
hBitmap = CreateCompatibleBitmap(ScreenDC, rt1.right - rt1.left, rt1.bottom - rt1.top);
hOldBitmap = (HBITMAP)SelectObject(MemoryDC, hBitmap);
hBrush = CreateSolidBrush(RGB(255,255,255));
hOldBrush = (HBRUSH)SelectObject(MemoryDC, hBrush);
FillRect(MemoryDC, &rt1, hBrush);
SetRect(&rt2, x, y, y+50, x+200);
DrawText(MemoryDC, "Hello World", strlen("Hello World"), &rt2, DT_LEFT);
BitBlt(ScreenDC, rt1.top, rt1.left, rt1.right - rt1.left, rt1.bottom - rt1.top, MemoryDC, 0, 0, SRCCOPY);
SelectObject(MemoryDC, hOldBrush);
DeleteObject(hBrush);
DeleteObject(hOldBrush);
DeleteObject(hBitmap);
DeleteObject(hOldBitmap);
DeleteDC(MemoryDC);
EndPaint(hWnd, &ps);
break;
case WM_MOUSEMOVE:
x = LOWORD(lParam);
y = HIWORD(lParam);
break;
regards,
-
Jul 29th, 2001, 08:50 PM
#3
Thread Starter
Lively Member
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.
-
Jul 30th, 2001, 09:18 AM
#4
Send the WM_ERASEBKGND message write before you call DrawText().
Code:
case WM_MOUSEMOVE:
SendMessage(hWnd, WM_ERASEBKGND, (WPARAM) hDC, 0);
DrawText(...);
break;
-
Jul 30th, 2001, 02:53 PM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|