PDA

Click to See Complete Forum and Search --> : DrawText RECT


JasonLpz
Jan 29th, 2003, 11:15 PM
Why do i get a error? i dont know RECT really.


RECT lbl;

lbl.left = 20;
lbl.top = 100;
lbl.right = 200;
lbl.bottom = 30;

::DrawText(NULL,"Jason",-1,lbl,DT_CENTER);

E:\Program Files\Microsoft Visual Studio\MyProjects\class2 test\main.cpp(48) : error C2664: 'DrawTextA' : cannot convert parameter 4 from 'struct tagRECT' to 'struct tagRECT *'

kedaman
Jan 29th, 2003, 11:19 PM
pass the address &lbl :p

JasonLpz
Jan 29th, 2003, 11:29 PM
thanks no error but no text maybe because
in
int DrawText(
HDC hDC, // handle to DC
LPCTSTR lpString, // text to draw
int nCount, // text length
LPRECT lpRect, // formatting dimensions
UINT uFormat // text-drawing options
);

How do i use :
HDC hDC, // handle to DC

I tried MSDN but cant understand maybe someone can help me thanks

made_of_asp
Jan 30th, 2003, 12:02 AM
HDC hdc = BeginPaint(hWnd, &ps);
//paint here
EndPaint(hWnd, &ps);

JasonLpz
Jan 30th, 2003, 12:22 AM
ok sort of helped but still nothing i got
RECT lbl;
lbl.left = 30;
lbl.top = 300;
lbl.right = 200;
lbl.bottom = 30;

PAINTSTRUCT ps;

HDC hdc = BeginPaint(hwnd, &ps);
::DrawText(hdc,"Jason",-1,&lbl,DT_CENTER);
EndPaint(hwnd, &ps);

made_of_asp
Jan 30th, 2003, 12:28 AM
Do you have your code in WM_PAINT message?

JasonLpz
Jan 30th, 2003, 12:58 AM
I got it like but no good my window bg is white

case WM_PAINT:
{
RECT lbl;
lbl.left = 30;
lbl.top = 90;
lbl.right = 200;
lbl.bottom = 30;

PAINTSTRUCT ps;

HDC hdc = BeginPaint(hwnd, &ps);
::DrawText(hdc,"Jason",-1,&lbl,DT_CENTER);
EndPaint(hwnd, &ps);
}
break;

CornedBee
Jan 30th, 2003, 07:50 AM
rect.top = 90
rect.bottom = 30


Positive y axis goes down. Your bottom is higher than your top.

JasonLpz
Jan 30th, 2003, 09:35 AM
LOL i thought that ment like how far apart from the top lol. Thankx alot it worked great.

JasonLpz
Jan 30th, 2003, 10:34 AM
ok now i go it , it works great but i can i run this from anytime i want?


case WM_PAINT:
{
RECT lbl;
lbl.left = 6;
lbl.top = 10;
lbl.right = 200;
lbl.bottom = 33;

RECT lbl2;
lbl2.left = 6;
lbl2.top = 38;
lbl2.right = 200;
lbl2.bottom = 66;

RECT lbl3;
lbl3.left = 6;
lbl3.top = 60;
lbl3.right = 200;
lbl3.bottom = 89;
PAINTSTRUCT ps;

HDC hdc = BeginPaint(hwnd, &ps);
::DrawText(hdc,"First Name",-1,&lbl,DT_LEFT);
::DrawText(hdc,"Last Name",-1,&lbl2,DT_LEFT);
::DrawText(hdc,"Enter NO. To look up.",-1,&lbl3,DT_LEFT);

EndPaint(hwnd, &ps);
}
break;

do i do a refresh? or like update or i cant?

Evil_Giraffe
Jan 30th, 2003, 11:30 AM
You need to send a WM_PAINT message to yourself.
SendMessage(hwnd, WM_PAINT, 0, 0)maybe?

CornedBee
Jan 30th, 2003, 12:14 PM
First you invalidate a region of your window (or all of it):

InvalidateRect(hwnd, &rectToInvalidate, TRUE);
// or for the whole window
InvalidateRect(hwnd, NULL, TRUE);

Then you can either wait for windows to ask your app to redraw (it will do that once your app is idle) or force immediate redrawing:

UpdateWindow(hwnd);

JasonLpz
Jan 30th, 2003, 12:49 PM
oh i c ok thanks i should be buying a couple of api books this week maybe. wheni do i wont ask such small questions anymore , cuz i know its a pain :) thankz

JasonLpz
Jan 30th, 2003, 05:33 PM
also can i drawtext to another program?

CornedBee
Jan 30th, 2003, 05:36 PM
Yes, given that you find out its hwnd. There are many ways to do that, the most common being FindWindow.
Then you call GetDC on that window and draw whatever you want into that dc. Call ReleaseDC when you're finished.


But note that everything you draw is gone once the other app repaints. Also it is considered bad manners for an app to do such a thing.

JasonLpz
Jan 30th, 2003, 07:32 PM
thx i will respect other developers programs. and also if i put that code in a timer will it work ok?

HDC hdc2 = ::GetDC(i) ? would work

ADDED

HDC hdc2 = ::GetDC(i);
::DrawText(hdc2,"Made By: Jason Lopez aka JayWare",-1,&lbl2,DT_LEFT);
ReleaseDC (i,hdc2);

CornedBee
Jan 31st, 2003, 05:33 AM
Why in a timer?

JasonLpz
Jan 31st, 2003, 07:06 AM
so it will stay on the other form. So how would i do it . That code i got above dont work.

JasonLpz
Jan 31st, 2003, 07:08 AM
ok yes it does work lol thanks

DNA7433
Jan 31st, 2003, 07:09 AM
could you subclass it? or would your winproc be called first and then the original proc overwrite the screen?

JasonLpz
Jan 31st, 2003, 02:13 PM
i got it to work great in a timer just send WM_PAINT and walla! here is a sample of what i did. if you want the source tell me. This adds some text to notepad in win98 se and winxp(tested). this is the exe ziped up at 52kb.