Click to See Complete Forum and Search --> : Textout/drawtext in desktop HDC
ExciteMouse
Jul 29th, 2001, 06:36 PM
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 (http://www.mouseindustries.com/paint.jpg)
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!
Chris
Jul 29th, 2001, 08:11 PM
try this...
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,
ExciteMouse
Jul 29th, 2001, 08:50 PM
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:
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.
Megatron
Jul 30th, 2001, 09:18 AM
Send the WM_ERASEBKGND message write before you call DrawText().
case WM_MOUSEMOVE:
SendMessage(hWnd, WM_ERASEBKGND, (WPARAM) hDC, 0);
DrawText(...);
break;
ExciteMouse
Jul 30th, 2001, 02:53 PM
hmm.. thats not working either :(
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.