Results 1 to 6 of 6

Thread: [RESOLVED]Using RoundRect AND DrawText

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    46

    [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

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    46
    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?
    ISquishWorms

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    46
    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.
    ISquishWorms

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Always glad.
    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
  •  



Click Here to Expand Forum to Full Width