CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 29

Thread: Help with mfc

Threaded View

  1. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,241

    Re: Help with mfc

    At a first look, your sample code contains not any MFC stuff. For example, TDC seems to be a Borland's OWL Library class and further are called just plain WinAPI functions (not MFC). I know, sometimes dealing with legacy code can be a real mess, but no problem, always is a place to make it better. So my advice is the following: when you are dealing with MFC, use as much as possible only MFC stuff. In this particular case, use MFC device context classes (CDC or CClientDC) instead of plain WinAPI functions calls, CString instead std::string, CRect instead of RECT structure. That can further make peogrammer's life much more reasier.

    So far, here are some remarks, based on your sample code.
    • if pass DT_CALCRECT format flag, the function DrawText just adjust the necessary rectangle and draws nothing;
    • if pass DT_SINGLELINE format flag, carriage returns ('\r') and line feeds ('\n') do not break the line;
    • do not call DeleteDC for a device context whose handle was obtained by calling the GetDC.

    See also:

    And here is a simplified example of drawing a text in an MFC application:
    Code:
    void CDemoSdiView::RenderText(CDC* pDC, int left, int top, const CString& strText)
    {
        CRect rc;
        // calculate the necessary rectangle
        pDC->DrawText(strText, rc, DT_LEFT|DT_TOP|DT_CALCRECT);
        // offset the rectangle to top-left coordinates
        rc.OffsetRect(left, top);
        // finally draw the text
        pDC->DrawText(strText, rc, DT_LEFT|DT_TOP);
    }
    
    void CDemoSdiView::OnDraw(CDC* pDC)
    {
        CString strText = _T("Ala\nBala\nPortocala");
        RenderText(pDC, 10, 10, strText);
    }
    Enjoy, and good luck!
    Last edited by ovidiucucu; January 2nd, 2023 at 07:40 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Tags for this Thread

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

Featured