|
-
Oct 20th, 2002, 09:17 AM
#1
Thread Starter
Member
[RESOLVED]Using RoundRect AND DrawText
Hello,
I am using the following code to draw two red round rectangles outlined with a solid white pen in the canter of my black client window. The problem I have is that I would like to also centre my text with in the round rectangles horizontally and vertically. From what I can tell the API DrawText function would allow me to do just this using ‘DT_CENTER | DT_VCENTER’ however, this API call requires that I have a structure of type RECT how do I acquire that from my round rectangles?
Thanks in advance for any help in this matter,
Code:
case WM_PAINT:
{
PAINTSTRUCT ps;
RECT rect;
HDC hdc;
hdc = BeginPaint(hwnd, &ps);
SelectObject(hdc, GetStockObject(WHITE_PEN));
SelectObject (hdc, hBrush1);
RoundRect(hdc,10, 10, cxClient - 10, (cyClient - 10) / 2, 10, 10);
RoundRect(hdc,10, (cyClient + 10) / 2, cxClient - 10, cyClient - 10 , 10, 10);
SetBkColor(hdc, RGB(255,0,0));
SetTextAlign(hdc,TA_CENTER);
TextOut(hdc, cxClient / 2, 15, "TEXT", 4);
TextOut(hdc, cxClient / 2, 55, "MORE TEXT", 9);
//DrawText(hdc, "TEXT", 4, &rect, DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &ps);
return 0;
}
Last edited by ISquishWorms; Oct 20th, 2002 at 04:59 PM.
ISquishWorms
-
Oct 20th, 2002, 09:32 AM
#2
Monday Morning Lunatic
It's just the width and height of your round rectangle, so put in the same values you did, just ignore the radius of the corners.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 20th, 2002, 09:40 AM
#3
Thread Starter
Member
Thanks, very much for your quick reply and advice parksie it is much appreciated. I know that I need these values in the structure RECT, but what is the best way to do this and how?
-
Oct 20th, 2002, 12:55 PM
#4
Code:
RECT rect;
rect.left = 10;
rect.top = 10;
rect.right = cxClient - 10;
rect.bottom = cyClient - 10;
You could also use the SetRect API call, but why call into a dll to do a thing you can do yourself in only 3 lines more?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 20th, 2002, 01:23 PM
#5
Thread Starter
Member
Thanks, CornedBee some how I knew I could count on you for a solution. :-) Having spent a little more time investigating a solution myself since posting this thread I came up with the following code. In which I was using the SetRect API, but as your solution saves me calling this API I will be implementing your improved solution.
Code:
case WM_PAINT:
{
PAINTSTRUCT ps;
RECT rect;
HDC hdc;
hdc = BeginPaint(hwnd, &ps);
SelectObject(hdc, GetStockObject(WHITE_PEN));
SelectObject (hdc, hBrush1);
RoundRect(hdc,10, 10, cxClient - 10, (cyClient - 10) / 2, 10, 10);
RoundRect(hdc,10, (cyClient + 10) / 2, cxClient - 10, cyClient - 10, 10, 10);
SetBkMode(hdc,TRANSPARENT);
SetRect(&rect, 10, 10, cxClient - 10, (cyClient - 10) / 2);
DrawText (hdc, TEXT ("SOME TEXT"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
SetRect(&rect, 10, (cyClient + 10) / 2, cxClient - 10, cyClient - 10);
DrawText (hdc, TEXT ("MORE TEXT"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint(hwnd, &ps);
return 0;
}
Thanks, as always for helping make my code even better CornedBee.
-
Oct 20th, 2002, 01:42 PM
#6
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
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
|